Beispiel #1
0
 /**
  * poller vlanMember
  *
  * @return Array
  */
 public function poll_vlanMember($vlanIndex = '')
 {
     // return
     $_ret = [];
     $snmp = new \App\Lnms\Snmp($this->node->ip_address, $this->node->snmp_comm_ro);
     // disable line breaks in output
     $snmp->setOptions('--hexOutputLength=0');
     if ($this->node->vlans->count() == 0) {
         // no vlan
         return $_ret;
     }
     foreach ($this->node->vlans as $vlan) {
         // why has .0.
         $oids[] = OID_dot1qVlanCurrentEgressPorts . '.0.' . $vlan->vlanIndex;
     }
     if (count($oids) == 0) {
         // no oid to poll
         return $_ret;
     }
     $get_result = $snmp->get($oids);
     if (count($get_result) == 0) {
         // cannot get anything
         return $_ret;
     }
     $members = [];
     foreach ($get_result as $key1 => $value1) {
         $vlanIndex = str_replace(OID_dot1qVlanCurrentEgressPorts . '.0.', '', $key1);
         $vlanValue = $value1;
         $tmp_hex = explode(' ', $value1);
         for ($i = 0; $i < count($tmp_hex); $i++) {
             if ($tmp_hex[$i] != '00') {
                 $tmp_bin = sprintf("%08s", decbin(hexdec($tmp_hex[$i])));
                 for ($j = 0; $j < strlen($tmp_bin); $j++) {
                     if ($tmp_bin[$j] == 1) {
                         $portIndex = $i * 8 + $j + 1;
                         $members[$portIndex][] = $vlanIndex;
                     }
                 }
             }
         }
     }
     //
     if (count($members) == 0) {
         // cannot get any members
         return $_ret;
     }
     foreach ($members as $memberPortIndex => $memberVlans) {
         // TODO: check query error
         $mVlans = [];
         foreach ($memberVlans as $memberVlan) {
             $mVlan = \App\Vlan::where('node_id', $this->node->id)->where('vlanIndex', $memberVlan)->first();
             $mVlans[] = $mVlan->id;
         }
         //
         $mPort = \App\Port::where('node_id', $this->node->id)->where('portIndex', $memberPortIndex)->first();
         $mPort->vlans()->sync($mVlans);
     }
     return $_ret;
 }
Beispiel #2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     //
     print \Carbon\Carbon::now() . ' Start snmpPoller...' . "\n";
     $nodes = \App\Node::where('ping_method', 'ping')->where('ping_params', '')->where('ping_success', 100)->get();
     $start_timestamp = time();
     $counter = 0;
     foreach ($nodes as $node) {
         // try v2c
         $snmp = new \App\Lnms\Snmp($node->ip_address, $node->snmp_comm_ro, '2c');
         $snmp->setOptions('-r 1 -t 1');
         $get_result = $snmp->get(OID_sysUpTime);
         if ($get_result) {
             $snmp_version = 2;
         } else {
             // try v1
             $snmp = new \App\Lnms\Snmp($node->ip_address, $node->snmp_comm_ro);
             $snmp->setOptions('-r 1 -t 1');
             $get_result = $snmp->get(OID_sysUpTime);
             $snmp_version = 1;
         }
         if ($get_result) {
             // snmp ok
             $snmp_success = 100;
             $get_sysUpTime = $get_result[OID_sysUpTime];
             // get sysObjectID
             $get_result2 = $snmp->get([OID_sysObjectID, OID_sysName]);
             $get_sysObjectID = $get_result2[OID_sysObjectID];
             $get_sysName = $get_result2[OID_sysName];
         } else {
             // snmp fail
             $snmp_version = 0;
             $snmp_success = 0;
             $get_sysUpTime = 0;
             $get_sysObjectID = '';
             $get_sysName = '';
         }
         $current_timestamp = time();
         $diff_timestamp = $current_timestamp - $start_timestamp;
         print \Carbon\Carbon::now() . " {$counter} ({$diff_timestamp} s.) - {$node->ip_address} {$node->snmp_comm_ro} = (v{$snmp_version}) {$snmp_success} {$get_sysUpTime} = {$get_sysObjectID} {$get_sysName}\n";
         $u_node = \App\Node::find($node->id);
         $u_node->snmp_version = $snmp_version;
         $u_node->snmp_success = $snmp_success;
         $u_node->snmp_updated = \Carbon\Carbon::now();
         $u_node->sysObjectID = $get_sysObjectID;
         $u_node->sysName = $get_sysName;
         $u_node->sysUpTime = $get_sysUpTime;
         $u_node->save();
         $counter++;
     }
     print \Carbon\Carbon::now() . ' Stop snmpPoller...' . "\n";
 }