Переглянути джерело

Se crea comando para obtner descripción de interfaces, codewords y calcular el CER. Se almacena en DB y se envía al mongo los datos históricos.

Maxi Schvindt 7 роки тому
батько
коміт
fcdbde0a5c

+ 211 - 0
Command/CmtsInterfaceDescriptionCommand.php

@@ -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}");
+        
+    }
+
+    
+
+}

+ 19 - 19
Command/CmtsOctetsCommand.php

@@ -27,7 +27,7 @@ class CmtsOctetsCommand extends BaseCmtsCommand
                 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('cmts-docs', false, InputOption::VALUE_OPTIONAL, "Versión DOCS-QOS del CMTS.", 1),
+                new InputOption('cmts-docs', false, InputOption::VALUE_OPTIONAL, "Versión DOCS-QOS del CMTS.", 2),
                 new InputOption('save-historic', null, InputOption::VALUE_OPTIONAL, "Send data to StatsD",1)
             ))
         ;
@@ -42,7 +42,6 @@ class CmtsOctetsCommand extends BaseCmtsCommand
         parent::execute($input, $output);
         
         $key_cm_octets = "cm_octets_{$this->d_s}";
-        //$key_cmts_octets = "cmts_octets_{$this->d_s}";
         $saveHistoric = (int) $input->getOption('save-historic');
         $cmtsDocs = (int) $input->getOption('cmts-docs');
         $inicio = microtime(true);
@@ -54,7 +53,6 @@ class CmtsOctetsCommand extends BaseCmtsCommand
         $this->apiSNMP = $SNMP->$library();
         
         $cmOctetsCached = $this->getData($key_cm_octets, true);
-        //$cmtsOctetsCached = $this->getData($key_cmts_octets, true);
 
         $inBandTotal = $outBandTotal = $inAccTotal = $outAccTotal = 0;
         
@@ -63,11 +61,6 @@ class CmtsOctetsCommand extends BaseCmtsCommand
             $cmOctetsCached = array();
         }
         
-        /* if(empty($cmtsOctetsCached)) {
-            $this->output->writeln("Se inicializa {$key_cmts_octets}.");
-            $cmtsOctetsCached = array();
-        } */
-
         switch($cmtsDocs) {
 
             case 1:
@@ -93,7 +86,7 @@ class CmtsOctetsCommand extends BaseCmtsCommand
 
         $data = array();
         $totalConsOut = $totalConsIn = $totalIn = $totalOut = 0;
-        
+
         foreach($index as $mac => $_flows) {
 
             $new = array('flows' => array());
@@ -137,27 +130,32 @@ class CmtsOctetsCommand extends BaseCmtsCommand
                 $new['flows'][$flow] = array('d' => $d, 'oct' => $o1);
             }
 
-            $new['inBand'] = $inBand;
-            $new['outBand'] = $outBand;
-            $new['inAcc'] = $inAcc;
-            $new['outAcc'] = $outAcc;
-            $new['t'] = $time;
-            
-            $data[$mac] = $new;
             $sendData["inbandwidth_cm_{$mac}"] = "{$inBand}|g";
             $sendData["outbandwidth_cm_{$mac}"] = "{$outBand}|g";
-
+            
             $div = 1073741824; //bytes => giga
             $consIn = number_format(($inAcc / $div),3);
             $consOut = number_format(($outAcc / $div),3);
             
             $sendData["inconsumption_cm_{$mac}"] = "{$consIn}|g";
             $sendData["outconsumption_cm_{$mac}"] = "{$consOut}|g";
-
+            
             $inBandTotal += $inBand;
             $outBandTotal += $outBand;
             $inAccTotal += $inAcc;
             $outAccTotal += $outAcc;
+            
+            if(date("n",$t0) != date("n",$time)) {
+                $inAcc = $outAcc = 0;
+            }
+
+            $new['inBand'] = $inBand;
+            $new['outBand'] = $outBand;
+            $new['inAcc'] = $inAcc;
+            $new['outAcc'] = $outAcc;
+            $new['t'] = $time;
+
+            $data[$mac] = $new;
 
         }
 
@@ -191,6 +189,7 @@ class CmtsOctetsCommand extends BaseCmtsCommand
         $this->output->writeln("Tiempo: $time segundos");
     }
 
+    /*
     private function octets(&$ifStatsCached, $dataCached, $saveHistoric) {
 
         $inOctets = $this->getSNMP("inOctets","cmtsIfInOctets");
@@ -241,7 +240,7 @@ class CmtsOctetsCommand extends BaseCmtsCommand
                 $sendData["{$subId}_inbandwidth_if_{$index}"] = "{$inBandwidth}|g";
                 $sendData["{$subId}_outbandwidth_if_{$index}"] = "{$outBandwidth}|g";
 
-                if(date("d",$t0) != date("d",$t1)) {
+                if(date("n",$t0) != date("n",$t1)) {
                     $inAcc = $outAcc = 0;
                 }
 
@@ -285,5 +284,6 @@ class CmtsOctetsCommand extends BaseCmtsCommand
         }
         
     }
+    */
 
 }

+ 10 - 0
SNMP/MIBS/OIDSBase.php

@@ -77,6 +77,8 @@ class OIDSBase extends \CmtsBundle\SNMP\MIB {
     const OID_docsIfUpChannelFrequency		= "1.3.6.1.2.1.10.127.1.1.2.1.2";
     const OID_docsIfUpChannelWidth 		= "1.3.6.1.2.1.10.127.1.1.2.1.3";
     
+    const OID_docsIfSignalQualityTable = "1.3.6.1.2.1.10.127.1.1.4.1";
+    const OID_ifEntry = "1.3.6.1.2.1.2.2.1";
     
     
     public function docsIfCmtsCmStatusMacAddress() {
@@ -310,5 +312,13 @@ class OIDSBase extends \CmtsBundle\SNMP\MIB {
         return $return;
     }
 
+    public function docsIfSignalQualityTable() {
+        return $this->getSNMP()->lastOidWalk(self::OID_docsIfSignalQualityTable,13);
+    }
+    
+    public function ifEntry() {
+        return $this->getSNMP()->lastOidWalk(self::OID_ifEntry,10);
+    }
+
     
 }