/** * Execute the console command. * * @return mixed */ public function fire() { //$nodes = \App\Node::where('poll_enabled', 'Y')->get(); $nodes = \App\Node::all(); foreach ($nodes as $node) { unset($exec_out1); exec('/usr/sbin/fping -e ' . $node->ip_address . ' 2>/dev/null', $exec_out1, $exec_ret1); if ($exec_ret1 == 0) { // ping ok $ping_success = 100; } else { // ping fail $ping_success = 0; } print $node->ip_address . ' = ' . $ping_success . '%' . PHP_EOL; $u_node = \App\Node::find($node->id); $u_node->ping_success = $ping_success; $u_node->save(); $ping = new \App\Ping(); $ping->node_id = $node->id; $ping->success = $ping_success; $ping->timestamp = \Carbon\Carbon::now(); $ping->save(); } }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); $user = factory(App\User::class)->create(['name' => 'p', 'email' => $faker->email(), 'password' => bcrypt('test')]); //$node = factory(App\Node::class)->create(); //factory(App\Node::class, 100)->create(); //$nodestatus = factory(App\Nodestat::class, 50)->create(['node_id' => $node->id]); $task = factory(App\Task::class)->create(['user_id' => $user->id, 'node_id' => \App\Node::all()->random(1)->id]); $task = factory(App\Task::class)->create(['user_id' => $user->id, 'node_id' => \App\Node::all()->random(1)->id]); $task = factory(App\Task::class)->create(['user_id' => $user->id, 'node_id' => \App\Node::all()->random(1)->id]); Model::reguard(); }
public static function allLevelUp() { return Cache::remember(self::CACHE_KEY, self::CACHE_MINUTES, function () { $nodes = Node::all(); $result = array(); foreach ($nodes as $key => $node) { if ($node->parent_node == null) { $result['top'][] = $node; foreach ($nodes as $skey => $snode) { if ($snode->parent_node == $node->id) { $result['second'][$node->id][] = $snode; } } } } return $result; }); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $tasks = \Auth::user()->getTasks()->with('node')->get(); $nodes = \App\Node::all(); return view('tasks/index')->with('tasks', $tasks)->with('nodes', $nodes); }