/** * poller ipAddress * * @return Array */ public function poll_ipAddress() { // return $_ret = []; $snmp = new \App\Lnms\Snmp($this->node->ip_address, $this->node->snmp_comm_ro); // walk OID_ipAdEntIfIndex $walk_ipAdEntIfIndex = $snmp->walk(OID_ipAdEntIfIndex); if (count($walk_ipAdEntIfIndex) == 0 || $walk_ipAdEntIfIndex === false) { // not found ipAddress return $_ret; } // walk netmask $walk_ipAdEntNetMask = $snmp->walk(OID_ipAdEntNetMask); // oid.ipAddress(4) = ifIndex foreach ($walk_ipAdEntIfIndex as $key1 => $ifIndex) { $ipAddress = str_replace(OID_ipAdEntIfIndex . '.', '', $key1); $netmask = explode('.', $walk_ipAdEntNetMask[OID_ipAdEntNetMask . '.' . $ipAddress]); if (count($netmask) == 4) { $masks = substr_count(decbin($netmask[0]), 1) + substr_count(decbin($netmask[1]), 1) + substr_count(decbin($netmask[2]), 1) + substr_count(decbin($netmask[3]), 1); } else { $masks = 0; } $port = \App\Port::where('node_id', $this->node->id)->where('ifIndex', $ifIndex)->first(); if ($port) { // found port and vlan $_ret[] = ['table' => 'ips', 'action' => 'sync', 'key' => ['node_id' => $this->node->id, 'port_id' => $port->id], 'data' => ['ipAddress' => $ipAddress, 'masks' => $masks]]; } } return $_ret; }
/** * poller macAddress * * @return Array */ public function poll_macAddress() { // return $_ret = []; $snmp = new \App\Lnms\Snmp($this->node->ip_address, $this->node->snmp_comm_ro); // walk OID_dot1qTpFdbPort $walk_dot1qTpFdbPort = $snmp->walk(OID_dot1qTpFdbPort); if (count($walk_dot1qTpFdbPort) == 0) { // not found macAddress return $_ret; } // dot1qTpFdbPort.vlanIndex.macDec = portIndex foreach ($walk_dot1qTpFdbPort as $key1 => $portIndex) { $tmp1 = explode('.', str_replace(OID_dot1qTpFdbPort . '.', '', $key1)); $vlanIndex = $tmp1[0]; $macAddress = sprintf("%02s", dechex($tmp1[1])) . ':' . sprintf("%02s", dechex($tmp1[2])) . ':' . sprintf("%02s", dechex($tmp1[3])) . ':' . sprintf("%02s", dechex($tmp1[4])) . ':' . sprintf("%02s", dechex($tmp1[5])) . ':' . sprintf("%02s", dechex($tmp1[6])); //print "$vlanIndex $macAddress = $portIndex<br>"; $port = \App\Port::where('node_id', $this->node->id)->where('portIndex', $portIndex)->first(); $vlan = \App\Vlan::where('node_id', $this->node->id)->where('vlanIndex', $vlanIndex)->first(); if ($port && $vlan) { // found port and vlan $_ret[] = ['table' => 'macs', 'action' => 'sync', 'key' => ['node_id' => $this->node->id, 'port_id' => $port->id, 'vlan_id' => $vlan->id], 'data' => ['macAddress' => $macAddress]]; } } return $_ret; }
/** * Override the parent * * @return Array */ public function poll_macAddress() { $_ret_from_parent = parent::poll_macAddress(); if (count($_ret_from_parent) > 0) { return $_ret_from_parent; } // return $_ret = []; $snmp = new \App\Lnms\Snmp($this->node->ip_address, $this->node->snmp_comm_ro); // walk OID_dot1dTpFdbPort $walk_dot1dTpFdbPort = $snmp->walk(OID_dot1dTpFdbPort); if (count($walk_dot1dTpFdbPort) == 0) { // not found macAddress return $_ret; } // oid.macDec(6) = portIndex // - portIndex = 0 // management port // - no vlanIndex in this mib, so assume VLAN 1 foreach ($walk_dot1dTpFdbPort as $key1 => $portIndex) { $tmp1 = explode('.', str_replace(OID_dot1dTpFdbPort . '.', '', $key1)); $macAddress = sprintf("%02s", dechex($tmp1[0])) . ':' . sprintf("%02s", dechex($tmp1[1])) . ':' . sprintf("%02s", dechex($tmp1[2])) . ':' . sprintf("%02s", dechex($tmp1[3])) . ':' . sprintf("%02s", dechex($tmp1[4])) . ':' . sprintf("%02s", dechex($tmp1[5])); $port = \App\Port::where('node_id', $this->node->id)->where('portIndex', $portIndex)->first(); $vlan = \App\Vlan::where('node_id', $this->node->id)->where('vlanIndex', 1)->first(); if ($port && $vlan) { // found port and vlan $_ret[] = ['table' => 'macs', 'action' => 'sync', 'key' => ['node_id' => $this->node->id, 'port_id' => $port->id, 'vlan_id' => $vlan->id], 'data' => ['macAddress' => $macAddress]]; } } return $_ret; }
/** * Execute the console command. * * @return mixed */ public function fire() { // delay to prevent run the same time with another job sleep($this->argument('endIfIndex') % 2 * 30 + 5); //print \Carbon\Carbon::now() . ' Start '; //print $this->name . '(' . $this->argument('endIfIndex') . ') '; //print "\n"; $start_timestamp = time(); // now test poll only ethernet(6) Up $ports = \App\Port::where('ifType', '6')->where('ifOperStatus', '1')->where('ifIndex', 'LIKE', '%' . $this->argument('endIfIndex'))->where('poll_enabled', 'Y')->orderBy('ifIndex')->get(); $counter = 0; foreach ($ports as $port) { if ($port->node->ping_success == 100 && $port->node->snmp_success == 100 && $port->node->snmp_version > 0) { $snmp = new \App\Lnms\Snmp($port->node->ip_address, $port->node->snmp_comm_ro, $port->node->snmp_version); if ($port->node->snmp_version == 2) { $oid_input = OID_ifHCInOctets; $oid_output = OID_ifHCOutOctets; } else { $oid_input = OID_ifInOctets; $oid_output = OID_ifOutOctets; } $get_result = $snmp->get([$oid_input . '.' . $port->ifIndex, $oid_output . '.' . $port->ifIndex]); $current_timestamp = time(); $diff_timestamp = $current_timestamp - $start_timestamp; //print \Carbon\Carbon::now() . ' '; //print $this->name . '(' . $this->argument('endIfIndex') . ') '; //print $counter . ' (' . $diff_timestamp . ' s.) - '; //print $port->node->ip_address . ' ' . $port->ifIndex . ' = '; if ($get_result) { // get ok //print $get_result[$oid_input . '.' . $port->ifIndex] . ' / '; //print $get_result[$oid_output . '.' . $port->ifIndex] . ' '; if ((int) $get_result[$oid_input . '.' . $port->ifIndex] > 0 || (int) $get_result[$oid_output . '.' . $port->ifIndex] > 0) { $octet = \App\Octet::Create(['port_id' => $port->id, 'timestamp' => \Carbon\Carbon::now(), 'input' => $get_result[$oid_input . '.' . $port->ifIndex], 'output' => $get_result[$oid_output . '.' . $port->ifIndex]]); } else { //print ' *** get error *** '; // disable polling $port->poll_enabled = 'N'; $port->save(); } } else { // get errors //print ' *** cannot get the value *** '; // disable polling $port->poll_enabled = 'N'; $port->save(); } //print "\n"; } $counter++; } $current_timestamp = time(); $total_runtime = $current_timestamp - $start_timestamp; //print \Carbon\Carbon::now() . ' Stop '; print \Carbon\Carbon::now() . ' '; print $this->name . '(' . $this->argument('endIfIndex') . ') '; print $counter . ' records, '; print 'runtime = ' . $total_runtime . " s.\n"; }
/** * 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; }
public function poll_if($ifOIDs, $ifIndex = '') { // return $_ret = []; $snmp = new \App\Lnms\Snmp($this->node->ip_address, $this->node->snmp_comm_ro); $oids = []; if ($ifIndex == '') { foreach ($this->node->ports as $port) { if (is_array($ifOIDs)) { foreach ($ifOIDs as $ifOID) { $oids[] = constant('OID_' . $ifOID) . '.' . $port->ifIndex; } } else { $oids[] = constant('OID_' . $ifOIDs) . '.' . $port->ifIndex; } } } else { if (is_array($ifOIDs)) { foreach ($ifOIDs as $ifOID) { $oids[] = constant('OID_' . $ifOID) . '.' . $ifIndex; } } else { $oids[] = constant('OID_' . $ifOIDs) . '.' . $ifIndex; } } if (count($oids) > 0) { $get_result = $snmp->get($oids); if ($get_result > 0) { if (is_array($ifOIDs)) { $ifData = []; foreach ($get_result as $key1 => $value1) { $ifKey = preg_replace('/\\.[0-9]+$/', '', $key1); $ifIndex = str_replace($ifKey . '.', '', $key1); foreach ($ifOIDs as $ifOID) { if (constant('OID_' . $ifOID) == $ifKey) { $ifData[$ifIndex][$ifOID] = $value1; } } } foreach ($ifData as $ifIndex => $ifValues) { $_ret[] = ['table' => 'ports', 'action' => 'update', 'key' => ['node_id' => $this->node->id, 'ifIndex' => $ifIndex], 'data' => $ifValues]; } } else { foreach ($get_result as $key1 => $value1) { $ifIndex = str_replace(constant('OID_' . $ifOIDs) . '.', '', $key1); $ifValue = $value1; $_ret[] = ['table' => 'ports', 'action' => 'update', 'key' => ['node_id' => $this->node->id, 'ifIndex' => $ifIndex], 'data' => [$ifOIDs => $ifValue]]; } } } } return $_ret; }
/** * 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"; }
/** * poller name * * @return Array */ public function poll_portIndex($ifIndex = '') { // return $_ret = []; $snmp = new \App\Lnms\Snmp($this->node->ip_address, $this->node->snmp_comm_ro); // walk portIndex $walk_portIndex = $snmp->walk(OID_dot1dBasePortIfIndex); if (count($walk_portIndex) > 0) { // found ports foreach ($walk_portIndex as $key1 => $value1) { $portIndex = str_replace(OID_dot1dBasePortIfIndex . '.', '', $key1); $ifIndex = $value1; $_ret[] = ['table' => 'ports', 'action' => 'update', 'key' => ['node_id' => $this->node->id, 'ifIndex' => $ifIndex], 'data' => ['portIndex' => $portIndex]]; } } return $_ret; }
/** * poller clientMacAddress * * @return Array */ public function poll_clientMacAddress() { // return $_ret = []; $snmp = new \App\Lnms\Snmp($this->node->ip_address, $this->node->snmp_comm_ro); // walk coDot11StationMACAddress $walk_coDot11StationMACAddress = $snmp->walk(OID_Colubris_coDot11StationMACAddress); if (count($walk_coDot11StationMACAddress) == 0 || $walk_coDot11StationMACAddress === false) { // not found coDot11StationMACAddress return $_ret; } // oid.ifIndex.clientIndex foreach ($walk_coDot11StationMACAddress as $key1 => $clientMacHex) { $clientMacAddress = str_replace(' ', ':', $clientMacHex); $clientSuffix = str_replace(OID_Colubris_coDot11StationMACAddress . '.', '', $key1); $tmp1 = explode('.', $clientSuffix); $ifIndex = $tmp1[0]; $clientIndex = $tmp1[1]; // find port_id $port = \App\Port::where('node_id', $this->node->id)->where('ifIndex', $ifIndex)->first(); if ($port) { // find bssid $bssid = \App\Bssid::where('node_id', $this->node->id)->where('port_id', $port->id)->first(); // $clientDetails = $snmp->get([OID_Colubris_coDot11StationIPAddress . '.' . $clientSuffix, OID_Colubris_coDot11SignalLevel . '.' . $clientSuffix]); if (isset($clientDetails[OID_Colubris_coDot11StationIPAddress . '.' . $clientSuffix])) { $clientIpAddress = $clientDetails[OID_Colubris_coDot11StationIPAddress . '.' . $clientSuffix]; } else { $clientIpAddress = null; } if (isset($clientDetails[OID_Colubris_coDot11SignalLevel . '.' . $clientSuffix])) { $clientSignalStrength = $clientDetails[OID_Colubris_coDot11SignalLevel . '.' . $clientSuffix]; } else { $clientSignalStrength = null; } if ($bssid) { // found bssid $_ret[] = ['table' => 'bds', 'action' => 'insert', 'key' => ['node_id' => $this->node->id, 'bssid_id' => $bssid->id, 'clientMacAddress' => $clientMacAddress, 'timestamp' => \Carbon\Carbon::now()], 'data' => ['clientIpAddress' => $clientIpAddress, 'clientSignalStrength' => $clientSignalStrength, 'clientBytesReceived' => 0, 'clientBytesSent' => 0]]; } } } return $_ret; }
/** * poller system * * @return Array */ public function poll_system() { // return $_ret = []; $snmp = new \App\Lnms\Snmp($this->node->ip_address, $this->node->snmp_comm_ro); // get system $get_system = $snmp->get([OID_sysDescr, OID_sysObjectID, OID_sysContact, OID_sysName, OID_sysLocation]); if (count($get_system) == 0) { // not found system return $_ret; } $sysDescr = $get_system[OID_sysDescr]; $sysObjectID = $get_system[OID_sysObjectID]; $sysContact = $get_system[OID_sysContact]; $sysName = $get_system[OID_sysName]; $sysLocation = $get_system[OID_sysLocation]; // update data $_ret[] = ['table' => 'nodes', 'action' => 'update', 'key' => ['id' => $this->node->id], 'data' => ['sysDescr' => $sysDescr, 'sysObjectID' => $sysObjectID, 'sysContact' => $sysContact, 'sysName' => $sysName, 'sysLocation' => $sysLocation]]; return $_ret; }
/** * poller routeDest * * @return Array */ public function poll_routeDest() { // return $_ret = []; $snmp = new \App\Lnms\Snmp($this->node->ip_address, $this->node->snmp_comm_ro); // walk ipRouteIfIndex $walk_ipRouteIfIndex = $snmp->walk(OID_ipRouteIfIndex); if (count($walk_ipRouteIfIndex) == 0) { // not found route return $_ret; } // $walk_ipRouteNextHop = $snmp->walk(OID_ipRouteNextHop); $walk_ipRouteType = $snmp->walk(OID_ipRouteType); $walk_ipRouteProto = $snmp->walk(OID_ipRouteProto); $walk_ipRouteMask = $snmp->walk(OID_ipRouteMask); // oid.routeDest = ifIndex foreach ($walk_ipRouteIfIndex as $key1 => $ifIndex) { $routeDest = str_replace(OID_ipRouteIfIndex . '.', '', $key1); $routeNextHop = $walk_ipRouteNextHop[OID_ipRouteNextHop . '.' . $routeDest]; $routeType = $walk_ipRouteType[OID_ipRouteType . '.' . $routeDest]; $routeProto = $walk_ipRouteProto[OID_ipRouteProto . '.' . $routeDest]; $netmask = explode('.', $walk_ipRouteMask[OID_ipRouteMask . '.' . $routeDest]); $routeMasks = substr_count(decbin($netmask[0]), 1) + substr_count(decbin($netmask[1]), 1) + substr_count(decbin($netmask[2]), 1) + substr_count(decbin($netmask[3]), 1); $port = \App\Port::where('node_id', $this->node->id)->where('ifIndex', $ifIndex)->first(); if ($port) { // found port $_ret[] = ['table' => 'routes', 'action' => 'sync', 'key' => ['node_id' => $this->node->id, 'port_id' => $port->id, 'routeDest' => $routeDest, 'routeMasks' => $routeMasks], 'data' => ['routeNextHop' => $routeNextHop, 'routeType' => $routeType, 'routeProto' => $routeProto]]; } } return $_ret; }
/** * poller arpAddress * * @return Array */ public function poll_arpAddress() { // return $_ret = []; $snmp = new \App\Lnms\Snmp($this->node->ip_address, $this->node->snmp_comm_ro); // walk ipNetToMediaPhysAddress $walk_ipNetToMediaPhysAddress = $snmp->walk(OID_ipNetToMediaPhysAddress); if (count($walk_ipNetToMediaPhysAddress) == 0) { // not found arpAddress return $_ret; } // oid.ifIndex.ipAddress(4) = macAddress foreach ($walk_ipNetToMediaPhysAddress as $key1 => $macAddress) { $tmp1 = explode('.', str_replace(OID_ipNetToMediaPhysAddress . '.', '', $key1)); $ifIndex = $tmp1[0]; $ipAddress = $tmp1[1] . '.' . $tmp1[2] . '.' . $tmp1[3] . '.' . $tmp1[4]; $port = \App\Port::where('node_id', $this->node->id)->where('ifIndex', $ifIndex)->first(); if ($port) { // found port $_ret[] = ['table' => 'arps', 'action' => 'sync', 'key' => ['node_id' => $this->node->id, 'port_id' => $port->id, 'ipAddress' => $ipAddress], 'data' => ['macAddress' => $macAddress]]; } } return $_ret; }
/** * poller ap client * * @return Array */ public function poll_apClient() { // return $_ret = []; $snmp = new \App\Lnms\Snmp($this->node->ip_address, $this->node->snmp_comm_ro); $walk_nUserApBSSID = $snmp->walk(OID_Aruba_nUserApBSSID); if (count($walk_nUserApBSSID) == 0) { return $_ret; } // oid.clientMacDec(6).clientIpAddress(4) = bssidMacHex foreach ($walk_nUserApBSSID as $key1 => $bssidMacHex) { $bssidMacAddress = str_replace(' ', ':', trim($bssidMacHex)); $clientSuffix = str_replace(OID_Aruba_nUserApBSSID . '.', '', $key1); $tmp1 = explode('.', $clientSuffix); $clientMacAddress = sprintf("%02s", dechex($tmp1[0])) . ':' . sprintf("%02s", dechex($tmp1[1])) . ':' . sprintf("%02s", dechex($tmp1[2])) . ':' . sprintf("%02s", dechex($tmp1[3])) . ':' . sprintf("%02s", dechex($tmp1[4])) . ':' . sprintf("%02s", dechex($tmp1[5])); $clientIpAddress = $tmp1[6] . '.' . $tmp1[7] . '.' . $tmp1[8] . '.' . $tmp1[9]; // find bssid $bssid = \App\Bssid::where('bssidMacAddress', $bssidMacAddress)->first(); $clientSignalStrength = 0; $clientBytesReceived = 0; $clientBytesSent = 0; // get more details about client $clientDetails = $snmp->get([OID_Aruba_staUserAgent . '.' . $clientSuffix, OID_Aruba_staUserType . '.' . $clientSuffix]); if (isset($clientDetails[OID_Aruba_staUserAgent . '.' . $clientSuffix])) { $clientUserAgent = $clientDetails[OID_Aruba_staUserAgent . '.' . $clientSuffix]; } else { $clientUserAgent = ''; } if (isset($clientDetails[OID_Aruba_staUserType . '.' . $clientSuffix])) { $clientUserType = $clientDetails[OID_Aruba_staUserType . '.' . $clientSuffix]; } else { $clientUserType = ''; } if ($bssid) { // found bssid $_ret[] = ['table' => 'bds', 'action' => 'insert', 'key' => ['node_id' => $bssid->node->id, 'bssid_id' => $bssid->id, 'clientMacAddress' => $clientMacAddress, 'timestamp' => \Carbon\Carbon::now()], 'data' => ['clientIpAddress' => $clientIpAddress, 'clientSignalStrength' => $clientSignalStrength, 'clientBytesReceived' => $clientBytesReceived, 'clientBytesSent' => $clientBytesSent, 'clientUserAgent' => $clientUserAgent, 'clientUserType' => $clientUserType]]; } } return $_ret; }
/** * poller clientMacAddress * * @return Array */ public function poll_clientMacAddress() { // return $_ret = []; $snmp = new \App\Lnms\Snmp($this->node->ip_address, $this->node->snmp_comm_ro); // walk cDot11ClientIpAddress $walk_cDot11ClientIpAddress = $snmp->walk(OID_cDot11ClientIpAddress); if (count($walk_cDot11ClientIpAddress) == 0) { // not found cDot11ClientIpAddress return $_ret; } $walk1 = $snmp->walk(OID_cDot11ClientSignalStrength); // oid.?.??.bssidNameDec.clientMacAddressDec = clientIpAddressHex foreach ($walk_cDot11ClientIpAddress as $key1 => $clientIpAddressHex) { $clientSuffix = str_replace(OID_cDot11ClientIpAddress . '.', '', $key1); $tmp1 = explode('.', $clientSuffix); // find which bssidName each client connected // TODO : for now ignore the first 2-bytes // find bssidName $bssidName = ''; for ($i = 2; $i < count($tmp1) - 6; $i++) { $bssidName .= chr($tmp1[$i]); } // find clientMacAddress $clientMacAddress = ''; for ($i = count($tmp1) - 6; $i < count($tmp1); $i++) { $clientMacAddress .= sprintf("%02s", dechex($tmp1[$i])) . ':'; } $clientMacAddress = trim($clientMacAddress, ':'); // find clientIpAddress $tmp2 = explode(' ', trim($clientIpAddressHex)); $clientIpAddress = ''; for ($i = 0; $i < count($tmp2); $i++) { $clientIpAddress .= hexdec($tmp2[$i]) . '.'; } $clientIpAddress = trim($clientIpAddress, '.'); // get cDot11ClientStatisticEntry $walk_clientStatistics = $snmp->get([OID_cDot11ClientSignalStrength . '.' . $clientSuffix, OID_cDot11ClientBytesReceived . '.' . $clientSuffix, OID_cDot11ClientBytesSent . '.' . $clientSuffix]); if (isset($walk_clientStatistics[OID_cDot11ClientSignalStrength . '.' . $clientSuffix])) { $clientSignalStrength = $walk_clientStatistics[OID_cDot11ClientSignalStrength . '.' . $clientSuffix]; } else { $clientSignalStrength = null; } if (isset($walk_clientStatistics[OID_cDot11ClientBytesReceived . '.' . $clientSuffix])) { $clientBytesReceived = $walk_clientStatistics[OID_cDot11ClientBytesReceived . '.' . $clientSuffix]; } else { $clientBytesReceived = null; } if (isset($walk_clientStatistics[OID_cDot11ClientBytesSent . '.' . $clientSuffix])) { $clientBytesSent = $walk_clientStatistics[OID_cDot11ClientBytesSent . '.' . $clientSuffix]; } else { $clientBytesSent = null; } // find bssid $bssid = \App\Bssid::where('node_id', $this->node->id)->where('bssidName', $bssidName)->first(); if ($bssid) { // found bssid $_ret[] = ['table' => 'bds', 'action' => 'insert', 'key' => ['node_id' => $this->node->id, 'bssid_id' => $bssid->id, 'clientMacAddress' => $clientMacAddress, 'timestamp' => \Carbon\Carbon::now()], 'data' => ['clientIpAddress' => $clientIpAddress, 'clientSignalStrength' => $clientSignalStrength, 'clientBytesReceived' => $clientBytesReceived, 'clientBytesSent' => $clientBytesSent]]; } } return $_ret; }
/** * snmp get system mibs * * @return Array * */ public static function snmpget_system($ip_address, $snmp_comm_ro) { $snmp = new \App\Lnms\Snmp($ip_address, $snmp_comm_ro); // get system //$systemOids = array( 'sysDescr', 'sysObjectID', // 'sysUpTime', 'sysContact', // 'sysName', 'sysLocation', ); $systemOids = array('sysDescr', 'sysObjectID'); $get_oids = array(); foreach ($systemOids as $oid_name) { $get_oids[] = constant('OID_' . $oid_name); } $get_result = $snmp->get($get_oids); // get system error if ($snmp->getErrno() != 0) { return false; } // return array $snmp_system = []; foreach ($systemOids as $oid_name) { $snmp_system[$oid_name] = $get_result[constant('OID_' . $oid_name)]; } return $snmp_system; }