|
@@ -0,0 +1,211 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace CmtsBundle\Command;
|
|
|
+
|
|
|
+use BaseStatsBundle\Command\BaseCmtsCommand;
|
|
|
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
|
|
+use Symfony\Component\Console\Input\InputOption;
|
|
|
+use Symfony\Component\Console\Input\InputInterface;
|
|
|
+use Symfony\Component\Console\Output\OutputInterface;
|
|
|
+use CmtsBundle\SNMP\SNMP as SNMP;
|
|
|
+use Symfony\Component\Yaml\Parser;
|
|
|
+
|
|
|
+class CmtsInterfaceDescriptionCommand extends BaseCmtsCommand
|
|
|
+{
|
|
|
+
|
|
|
+ protected function configure()
|
|
|
+ {
|
|
|
+ $this
|
|
|
+ ->setName('cmts:interface:description')
|
|
|
+ ->setDescription('Obtener Detalles de las Interfaces')
|
|
|
+ ->setHelp('Se requieren parámetros para poder realizar la correcta consulta. El comando requiere Redis.')
|
|
|
+ ->setDefinition(array(
|
|
|
+ new InputOption('cmts-device-id', null, InputOption::VALUE_OPTIONAL, "DeviceId del CMTS",1),
|
|
|
+ new InputOption('cmts-server-id', null, InputOption::VALUE_OPTIONAL, "ServerDevice del CMTS",1),
|
|
|
+ new InputOption('cmts-ip', false, InputOption::VALUE_OPTIONAL, "IP del CMTS"),
|
|
|
+ new InputOption('cmts-community', false, InputOption::VALUE_OPTIONAL, "Community del CMTS"),
|
|
|
+ new InputOption('cmts-snmp-library', false, InputOption::VALUE_OPTIONAL, "Versión de librería SNMP"),
|
|
|
+ new InputOption('save-historic', null, InputOption::VALUE_OPTIONAL, "Send data to StatsD",1)
|
|
|
+ ))
|
|
|
+ ;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param InputInterface $input
|
|
|
+ * @param OutputInterface $output
|
|
|
+ */
|
|
|
+ protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
+ {
|
|
|
+ parent::execute($input, $output);
|
|
|
+
|
|
|
+ $saveHistoric = (int) $input->getOption('save-historic');
|
|
|
+ $inicio = microtime(true);
|
|
|
+
|
|
|
+ $SNMP = new SNMP($this->cmtsIp, $this->cmtsCommunity);
|
|
|
+ $library = "use".$this->cmtsSnmpLibrary;
|
|
|
+ $this->apiSNMP = $SNMP->$library();
|
|
|
+
|
|
|
+ /*
|
|
|
+ ----------------------------------
|
|
|
+ Columns cmts_interface_description
|
|
|
+ ----------------------------------
|
|
|
+ id
|
|
|
+ server_id
|
|
|
+ cmts_device_id
|
|
|
+ updated
|
|
|
+ index
|
|
|
+ name
|
|
|
+ if_type
|
|
|
+ if_mtu
|
|
|
+ if_speed
|
|
|
+ if_phys_address
|
|
|
+ if_admin_status
|
|
|
+ if_oper_status
|
|
|
+ if_last_change
|
|
|
+ if_in_octets
|
|
|
+ if_in_ucast_pkts
|
|
|
+ if_in_nucast_pkts
|
|
|
+ if_in_discards
|
|
|
+ if_in_errors
|
|
|
+ if_in_unknown_protos
|
|
|
+ if_out_octets
|
|
|
+ if_out_ucast_pkts
|
|
|
+ if_out_nucast_pkts
|
|
|
+ if_out_discards
|
|
|
+ if_out_errors
|
|
|
+ if_out_qlen
|
|
|
+ if_specific
|
|
|
+
|
|
|
+ docs_if_sig_qincludes_contention
|
|
|
+ docs_if_sig_qunerroreds
|
|
|
+ docs_if_sig_qcorrecteds
|
|
|
+ docs_if_sig_quncorrectables
|
|
|
+ docs_if_sig_qext_unerroreds
|
|
|
+ docs_if_sig_qext_correcteds
|
|
|
+ docs_if_sig_qext_uncorrectables
|
|
|
+ cer
|
|
|
+ extra_data
|
|
|
+ */
|
|
|
+
|
|
|
+ $sigOids = array(1 => 'includes_contention', 2 => 'unerroreds', 3 => 'correcteds', 4 => 'uncorrectables', 8 => 'ext_unerroreds', 9 => 'ext_correcteds', 10 => 'ext_uncorrectables');
|
|
|
+ $ifEntry = $this->getSNMP("ifEntry","cmtsIfEntry");
|
|
|
+ /* http://cric.grenoble.cnrs.fr/Administrateurs/Outils/MIBS/?oid=1.3.6.1.2.1.2.2.1 */
|
|
|
+
|
|
|
+ $dataIfEntry = array();
|
|
|
+ foreach($ifEntry as $index => $value) {
|
|
|
+
|
|
|
+ list($oid, $ifIndex) = explode(".",$index);
|
|
|
+
|
|
|
+ if(!isset($dataIfEntry[$ifIndex])) $dataIfEntry[$ifIndex] = array();
|
|
|
+
|
|
|
+ $dataIfEntry[$ifIndex][$oid] = $value;
|
|
|
+ }
|
|
|
+
|
|
|
+ $docsIfSignalQualityTable = $this->getSNMP("docsIfSignalQualityTable","cmtsDocsIfSignalQualityTable");
|
|
|
+ /* http://oidref.com/1.3.6.1.2.1.10.127.1.1.4.1 */
|
|
|
+
|
|
|
+ $dataIfSignal = array();
|
|
|
+ foreach($docsIfSignalQualityTable as $index => $value) {
|
|
|
+
|
|
|
+ list($oid, $ifIndex) = explode(".",$index);
|
|
|
+
|
|
|
+ if(!isset($dataIfSignal[$ifIndex])) $dataIfSignal[$ifIndex] = array();
|
|
|
+
|
|
|
+ $dataIfSignal[$ifIndex][$oid] = $value;
|
|
|
+ }
|
|
|
+
|
|
|
+ $sendData = $rows = array();
|
|
|
+ $countIfs = 0;
|
|
|
+ foreach($dataIfEntry as $ifIndex => $values) {
|
|
|
+ $countIfs++;
|
|
|
+ $row = array();
|
|
|
+
|
|
|
+ $row[] = "NULL";
|
|
|
+ $row[] = $this->cmtsServerId;
|
|
|
+ $row[] = $this->cmtsDeviceId;
|
|
|
+ $row[] = "'".date("Y-m-d H:i:s")."'";
|
|
|
+ $row[] = $ifIndex;
|
|
|
+
|
|
|
+ (isset($values[2]) && !empty($values[2]))? $row[] = "'{$values[2]}'" : $row[] = "NULL";
|
|
|
+
|
|
|
+ for($i = 3; $i <= 22; $i++) {
|
|
|
+ if($i == 6) {
|
|
|
+ (isset($values[$i]) && !empty($values[$i]))? $row[] = "'{$values[$i]}'" : $row[] = "NULL";
|
|
|
+ } else {
|
|
|
+ (isset($values[$i]) && !empty($values[$i]))? $row[] = $values[$i] : $row[] = "NULL";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for($i = 1; $i <= 4; $i++) {
|
|
|
+ if(isset($dataIfSignal[$ifIndex][$i]) && !empty($dataIfSignal[$ifIndex][$i])) {
|
|
|
+ $v = $row[] = $dataIfSignal[$ifIndex][$i];
|
|
|
+ $name = $sigOids[$i];
|
|
|
+ $sendData["{$this->d_s}_if_{$name}_{$ifIndex}"] = "{$v}|g";
|
|
|
+ } else {
|
|
|
+ $row[] = "NULL";
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ $aux = array();
|
|
|
+ for($i = 8; $i <= 10; $i++) {
|
|
|
+ if(isset($dataIfSignal[$ifIndex][$i]) && !empty($dataIfSignal[$ifIndex][$i])) {
|
|
|
+ $v = $aux[$i] = $row[] = $dataIfSignal[$ifIndex][$i];
|
|
|
+ $name = $sigOids[$i];
|
|
|
+ $sendData["{$this->d_s}_if_{$name}_{$ifIndex}"] = "{$v}|g";
|
|
|
+ } else {
|
|
|
+ $row[] = "NULL";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(isset($aux[8]) && isset($aux[9]) && isset($aux[10])) {
|
|
|
+ $sum = $aux[8] + $aux[9];
|
|
|
+ $prom = $aux[10] / $sum;
|
|
|
+ $v = $row[] = round($prom,6);
|
|
|
+ $sendData["{$this->d_s}_if_cer_{$ifIndex}"] = "{$v}|g";
|
|
|
+ } else {
|
|
|
+ $row[] = "NULL";
|
|
|
+ }
|
|
|
+
|
|
|
+ $row[] = "NULL";
|
|
|
+
|
|
|
+ $rows[] = "(".implode(",",$row).")";
|
|
|
+ }
|
|
|
+
|
|
|
+ if($rows) {
|
|
|
+
|
|
|
+ $doctrine = $this->getContainer()->get('doctrine.orm.entity_manager');
|
|
|
+ $conn = $doctrine->getConnection();
|
|
|
+ $sql = "DELETE FROM `cmts_interface_description` WHERE server_id = {$this->cmtsServerId} AND cmts_device_id = {$this->cmtsDeviceId};";
|
|
|
+ $conn->query($sql);
|
|
|
+ $conn->close();
|
|
|
+
|
|
|
+ $conn = $doctrine->getConnection();
|
|
|
+ $sql = "INSERT LOW_PRIORITY IGNORE INTO `cmts_interface_description` () VALUES ". implode(",", $rows).";";
|
|
|
+
|
|
|
+ $conn->query($sql);
|
|
|
+ $conn->close();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if($sendData && $saveHistoric) {
|
|
|
+ $t_start_script = microtime(true);
|
|
|
+ $statsdService = $this->getContainer()->get('statsd');
|
|
|
+ $statsdService->send($sendData);
|
|
|
+ $t_end_script = microtime(true);
|
|
|
+ $time = $t_end_script - $t_start_script;
|
|
|
+ print_r("Tiempo de envío al StatsD: {$time} ms / Cantidad: ".count($sendData).PHP_EOL);
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->removeLock($this->flag);
|
|
|
+
|
|
|
+ $fin = microtime(true);
|
|
|
+ $time = $fin - $inicio;
|
|
|
+ $this->output->writeln("Tiempo: $time segundos / Cantidad Interfaces: {$countIfs}");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|