Пример #1
0
 /**
  *  Get ports information by SNMP
  * @param array $keys
  * @return array 
  * @throws Exception
  */
 public function loadPortsInfo($keys)
 {
     try {
         foreach ($keys as $key) {
             $resSNMPPorts = PNMSnmp::walk($this, PNMSnmp::getOid($key), 2);
             foreach ($resSNMPPorts as $oid => $res) {
                 preg_match('/(.+[.][0-9]+)[.]([0-9]+)/', $oid, $match);
                 $portIndex = (int) $match[2];
                 //if( ! isset($this->ports[$portIndex]) ) {
                 $this->ports[$portIndex]['ifIndex'] = $portIndex;
                 //}
                 preg_match('/([^:]+): "?([^"]+)"?/', $res, $values_match);
                 switch ($values_match[1]) {
                     case "INTEGER":
                     case "Gauge32":
                     case "Counter32":
                         $this->ports[$portIndex][$key] = (int) $values_match[2];
                         break;
                     default:
                         $this->ports[$portIndex][$key] = $values_match[2];
                 }
                 $hostConn = $this->getConnectionOnPort($portIndex);
                 if ($hostConn instanceof Connection) {
                     $this->ports[$portIndex]['hasConnection'] = $hostConn->hostDst;
                 }
             }
         }
     } catch (Exception $exc) {
         throw new Exception($exc->getMessage());
     }
     foreach ($this->ports as $k => $port) {
         if (preg_match($this->ifNameExceptionsRegex, $port['ifDescr'])) {
             unset($this->ports[$k]);
         }
     }
     return $this->ports;
 }
Пример #2
0
 /**
  * change SNMP value of Host
  */
 public function actionSetSNMP()
 {
     try {
         $name = $_POST['name'];
         switch ($_POST['key']) {
             case "ifAlias":
                 $type = 's';
                 break;
             default:
                 $type = 'i';
         }
         $model = $this->loadModelByName($name);
         if ($model) {
             $key = PNMSnmp::getOid($_POST['key']);
             $index = (int) $_POST['index'];
             $value = $_POST['value'];
             $oid = $key . '.' . $index;
             $result = $model->setSNMPValue($oid, $type, $value);
         }
         $this->layout = '//layouts/json';
         $this->render('jsonSetStatus', array('result' => $result));
     } catch (Exception $exc) {
         $this->render('jsonError', array('error' => "actionSetSNMP error:" . $exc->getMessage()));
     }
 }