/** * 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"; }
/** * */ 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); }