/** * 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; }
/** * Override the parent * * @return Array */ public function poll_vlanMember($vlanIndex = '') { $_ret_from_parent = parent::poll_vlanMember(); if (count($_ret_from_parent) > 0) { return $_ret_from_parent; } // TODO: cannot find another way to walk vlanMember on HP Switch // so now, assume every ports are assigned in VLAN 1 // return $_ret = []; $mVlan = \App\Vlan::where('node_id', $this->node->id)->where('vlanIndex', 1)->first(); $mVlans[] = $mVlan->id; // $mPorts = \App\Port::where('node_id', $this->node->id)->where('portIndex', '>', 0)->get(); foreach ($mPorts as $mPort) { $mPort->vlans()->sync($mVlans); } return $_ret; }
/** * display vlans in node * */ public function vlans($id) { $node = \App\Node::findOrFail($id); $vlans = \App\Vlan::where('node_id', $id)->orderBy('vlanIndex')->paginate(10); return view('nodes.vlans', compact('node', 'vlans')); }
/** * 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; }