示例#1
0
文件: Mac.php 项目: afdalwahyu/lnms
 /**
  * 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;
 }
示例#2
0
文件: Ip.php 项目: afdalwahyu/lnms
 /**
  * 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;
 }
示例#3
0
文件: Route.php 项目: afdalwahyu/lnms
 /**
  * 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;
 }
示例#4
0
文件: Mac.php 项目: afdalwahyu/lnms
 /**
  * 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;
 }
示例#5
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     //
     $option_interval = $this->option('interval');
     $option_status = $this->option('status');
     if ($option_status == 'A') {
         // poll all
         $pollings = \App\Polling::where('table_name', 'ports')->where('interval', $option_interval)->get();
     } else {
         // poll only status = 'Y'
         $pollings = \App\Polling::where('table_name', 'ports')->where('status', 'Y')->where('interval', $option_interval)->get();
     }
     foreach ($pollings as $polling) {
         $port = \App\Port::findOrFail($polling->table_id);
         if ($port->poll_enabled == 'Y' || $option_status == 'A') {
             $poll_class = '\\App\\Lnms\\' . $port->node->poll_class . '\\' . $polling->poll_class;
             $poll_object = new $poll_class($port->node);
             $poll_method = $polling->poll_method;
             $poller_result = $poll_object->{$poll_method}($port->ifIndex);
             for ($i = 0; $i < count($poller_result); $i++) {
                 if ($poller_result[$i]['table'] == 'pds') {
                     unset($poller_result[$i]['key']);
                     $poller_result[$i]['key'] = ['polling_id' => $polling->id, 'timestamp' => \Carbon\Carbon::now()];
                 }
                 switch ($poller_result[$i]['action']) {
                     case 'insert':
                         // insert new
                         if (isset($poller_result[$i]['key'])) {
                             \DB::table($poller_result[$i]['table'])->insert(array_merge($poller_result[$i]['key'], $poller_result[$i]['data']));
                         } else {
                             \DB::table($poller_result[$i]['table'])->insert($poller_result[$i]['data']);
                         }
                         break;
                     case 'sync':
                     case 'update':
                         // query existing data by key
                         $poll_db = \DB::table($poller_result[$i]['table']);
                         foreach ($poller_result[$i]['key'] as $poll_key => $poll_value) {
                             $poll_db = $poll_db->where($poll_key, $poll_value);
                         }
                         if ($poll_db->count() > 0) {
                             // update
                             \DB::table($poller_result[$i]['table'])->where('id', $poll_db->first()->id)->update($poller_result[$i]['data']);
                         } else {
                             if ($poller_result[$i]['action'] == 'sync') {
                                 // just insert for 'sync'
                                 if (isset($poller_result[$i]['key'])) {
                                     \DB::table($poller_result[$i]['table'])->insert(array_merge($poller_result[$i]['key'], $poller_result[$i]['data']));
                                 } else {
                                     \DB::table($poller_result[$i]['table'])->insert($poller_result[$i]['data']);
                                 }
                             }
                         }
                         // TODO : detect and delete removed Port from DB
                         break;
                 }
             }
         }
     }
 }
示例#6
0
 /**
  * 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";
 }
示例#7
0
 public function search_result()
 {
     $searchterm = Input::get('searchterm');
     $cruises = Cruise::where('name', 'LIKE', '%' . $searchterm . '%')->get();
     //$cruises = Cruise::first();
     $port = Port::all();
     return view('partial.partial_search', ['cruises' => $cruises, 'port' => $port]);
 }
示例#8
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $cruise = Cruise::find($id);
     $cabins = Cabin::where('ship_id', $cruise->ship_id)->get();
     $port = Port::all();
     $cabin_type = Cruise_Cabin_Type::where('cruise_id', $cruise->id)->get();
     return view("pages.cruises_show", compact('cruise', 'cabins', 'port', 'cabin_type'));
 }
 public function create_helper_confirmation()
 {
     $cruiseid = Input::get('cruiseid');
     $cabinid = Input::get('cabinid');
     $cruise = Cruise::findOrFail($cruiseid);
     $ship = Ship::findOrFail($cruise->ship_id);
     $cabin = Cabin::where('id', $cabinid)->first();
     $port = Port::all();
     $cabin_type = Cruise_Cabin_Type::where('cruise_id', $cruise->id)->get();
     return view('partial.partial_confirmation', compact('cruise', 'ship', 'cabin', 'port', 'cabin_type'));
 }
 public function multipleUpdate(Request $request)
 {
     for ($i = 0; $i < count($request->all()); $i++) {
         $this->validate($request, [$i . '.description' => 'string', $i . '.data' => 'numeric', $i . '.vlan' => 'numeric']);
         $port = Port::where('id', $request->input($i . '.id'))->first();
         $port->data = $request->input($i . '.data') ? $request->input($i . '.data') : null;
         $port->vlan = $request->input($i . '.vlan') ? $request->input($i . '.vlan') : null;
         $port->description = $request->input($i . '.description') ? $request->input($i . '.description') : null;
         $port->save();
     }
 }
示例#11
0
文件: Bssid.php 项目: afdalwahyu/lnms
 /**
  * poller bssidName
  *
  * @return Array
  */
 public function poll_bssidName()
 {
     // return
     $_ret = [];
     $snmp = new \App\Lnms\Snmp($this->node->ip_address, $this->node->snmp_comm_ro);
     // walk cd11IfAuxSsid
     $walk_cd11IfAuxSsid = $snmp->walk(OID_cd11IfAuxSsid);
     if (count($walk_cd11IfAuxSsid) == 0) {
         // not found cd11IfAuxSsid
         return $_ret;
     }
     //
     $walk_cd11IfPhyMacSpecification = $snmp->walk(OID_cd11IfPhyMacSpecification);
     $walk_cd11IfPhyDsssMaxCompatibleRate = $snmp->walk(OID_cd11IfPhyDsssMaxCompatibleRate);
     $walk_cd11IfPhyDsssCurrentChannel = $snmp->walk(OID_cd11IfPhyDsssCurrentChannel);
     // oid.ifIndex.bssidIndex = bssidName
     foreach ($walk_cd11IfAuxSsid as $key1 => $bssidName) {
         $tmp1 = explode('.', str_replace(OID_cd11IfAuxSsid . '.', '', $key1));
         $ifIndex = $tmp1[0];
         $bssidIndex = $tmp1[1];
         // TODO: find out which index to use, whether ifIndex or bssidIndex
         if (isset($walk_cd11IfPhyMacSpecification[OID_cd11IfPhyMacSpecification . '.' . $ifIndex])) {
             $bssidSpec = $walk_cd11IfPhyMacSpecification[OID_cd11IfPhyMacSpecification . '.' . $ifIndex];
         } else {
             $bssidSpec = 0;
         }
         if (isset($walk_cd11IfPhyDsssMaxCompatibleRate[OID_cd11IfPhyDsssMaxCompatibleRate . '.' . $ifIndex])) {
             // units : 500 Kb per second
             // cast to int Mbps
             $bssidMaxRate = (int) (0.5 * $walk_cd11IfPhyDsssMaxCompatibleRate[OID_cd11IfPhyDsssMaxCompatibleRate . '.' . $ifIndex]);
         } else {
             $bssidMaxRate = 0;
         }
         if (isset($walk_cd11IfPhyDsssCurrentChannel[OID_cd11IfPhyDsssCurrentChannel . '.' . $ifIndex])) {
             $bssidCurrentChannel = $walk_cd11IfPhyDsssCurrentChannel[OID_cd11IfPhyDsssCurrentChannel . '.' . $ifIndex];
         } else {
             $bssidCurrentChannel = 0;
         }
         $port = \App\Port::where('node_id', $this->node->id)->where('ifIndex', $ifIndex)->first();
         if ($port) {
             // found port
             // 'port_id' => $port->id,
             $_ret[] = ['table' => 'bssids', 'action' => 'sync', 'key' => ['node_id' => $this->node->id, 'bssidIndex' => $bssidIndex], 'data' => ['bssidMacAddress' => $port->ifPhysAddress, 'bssidName' => $bssidName, 'bssidSpec' => $bssidSpec, 'bssidMaxRate' => $bssidMaxRate, 'bssidCurrentChannel' => $bssidCurrentChannel]];
         }
     }
     return $_ret;
 }
示例#12
0
文件: Vlan.php 项目: afdalwahyu/lnms
 /**
  * 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;
 }
示例#13
0
文件: Bssid.php 项目: afdalwahyu/lnms
 /**
  * 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;
 }
示例#14
0
 /**
  *
  */
 public function octets_data($id)
 {
     if (\Request::has('date')) {
         $q_date = \Request::get('date');
     } else {
         $q_date = strftime("%Y-%m-%d");
     }
     $port = \App\Port::findOrFail($id);
     $octets = \App\Octet::where('port_id', $id)->where('timestamp', '>', $q_date)->orderBy('timestamp')->limit(288)->get();
     //
     $prev_timestamp = 0;
     $prev_input = 0;
     $prev_output = 0;
     $avg_input = [];
     $avg_output = [];
     foreach ($octets as $data) {
         $diff_timestamp = strtotime($data->timestamp) - $prev_timestamp;
         $diff_input = $data->input - $prev_input;
         $diff_output = $data->output - $prev_output;
         if ($diff_input < 0) {
             $diff_input = $diff_input + 4294967296;
         }
         if ($diff_output < 0) {
             $diff_output = $diff_output + 4294967296;
         }
         if ($prev_input != 0 && $diff_timestamp > 0 && $diff_input >= 0 && $diff_output >= 0) {
             // convert byte to bit
             $in_avg5 = (int) (8 * ($diff_input / $diff_timestamp));
             $out_avg5 = (int) (8 * ($diff_output / $diff_timestamp));
             $avg_input[] = array(strtotime($data->timestamp) * 1000, $in_avg5);
             $avg_output[] = array(strtotime($data->timestamp) * 1000, $out_avg5);
         }
         // next
         $prev_timestamp = strtotime($data->timestamp);
         $prev_input = $data->input;
         $prev_output = $data->output;
     }
     $response[] = array('data' => $avg_input, 'label' => 'Inbound', 'color' => 'lightgreen', 'lines' => array('show' => 'true', 'fill' => 'true', 'fillColor' => 'lightgreen'));
     $response[] = array('data' => $avg_output, 'label' => 'Outbound', 'color' => 'darkblue');
     // Response::json($response, $statusCode)->setCallback(Input::get('callback'));i
     return response()->json($response);
 }
示例#15
0
文件: Arp.php 项目: afdalwahyu/lnms
 /**
  * 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;
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     // deletes the network switch records.
     NetworkSwitch::where('id', $id)->delete();
     // and its ports
     Port::where('network_switch_id')->delete();
 }
示例#17
0
 /**
  * display ports in node
  *
  */
 public function ports($id)
 {
     $node = \App\Node::findOrFail($id);
     $ports = \App\Port::where('node_id', $id)->orderBy('ifIndex')->paginate(100);
     return view('nodes.ports', compact('node', 'ports'));
 }
示例#18
0
文件: Port.php 项目: afdalwahyu/lnms
 /**
  * poller octets
  *
  * @return Array
  */
 public function poll_ifOctets($ifIndex = '')
 {
     if ($ifIndex == '') {
         // poll only one port, specified by ifIndex
         return [];
     }
     $port = \App\Port::where('node_id', $this->node->id)->where('ifIndex', $ifIndex)->first();
     if ($port->ifOperStatus != 1) {
         return [];
     }
     // poll only Port Up
     $poll_results = $this->poll_if(['ifInOctets', 'ifOutOctets'], $ifIndex);
     // mapping data
     for ($i = 0; $i < count($poll_results); $i++) {
         $_ret[] = ['table' => 'pds', 'action' => 'insert', 'key' => $poll_results[$i]['key'], 'data' => ['input' => $poll_results[$i]['data']['ifInOctets'], 'output' => $poll_results[$i]['data']['ifOutOctets']]];
     }
     return $_ret;
 }
示例#19
0
文件: Vlan.php 项目: afdalwahyu/lnms
 /**
  * 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;
 }