Exemplo n.º 1
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;
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  *
  */
 public function pollings_update($id)
 {
     $input = \Request::all();
     $port = \App\Port::findOrFail($id);
     // new node_poll_class object
     $node_class_name = '\\App\\Lnms\\' . $port->node->poll_class . '\\Node';
     $node_object = new $node_class_name();
     $node_pollers = $node_object->pollers();
     foreach ($node_pollers['ports'] as $poller_name => $poller_params) {
         $polling = \App\Polling::where('poll_class', $poller_params['class'])->where('poll_method', $poller_params['method'])->where('table_name', 'ports')->where('table_id', $id)->first();
         if (isset($input['status'][$polling->id])) {
             $polling->status = 'Y';
         } else {
             $polling->status = 'N';
         }
         $polling->save();
     }
     \Session::flash('flash_message', 'polling status updated.');
     return redirect('/ports/' . $id . '/pollings');
 }
Exemplo n.º 3
0
 /**
  *
  * @return view
  */
 public function ds($id)
 {
     $polling = \App\Polling::findOrFail($id);
     $pds = \App\Pd::where('polling_id', $id)->orderBy('timestamp', 'desc')->paginate(10);
     return view('pollings.ds', compact('polling', 'pds'));
 }