Exemplo n.º 1
0
 public function checkLatency($id)
 {
     $check = Check::findOrFail($id);
     $data = DB::table('checks_results')->select(array(DB::raw('UNIX_TIMESTAMP(`created_at`) * 1000 AS `x`'), DB::raw('`latency` AS `y`')))->where('check_id', '=', $check->id)->where('created_at', '>', DB::raw('NOW() - INTERVAL 1 WEEK'))->orderBy('created_at', 'asc')->get();
     $data = array_map(function ($result) use($check) {
         return array('x' => (int) $result->x, 'y' => (int) $result->y, 'color' => $result->y / 1000 < $check->latency_tolerating ? $result->y / 1000 < $check->latency_satisfied ? '#A1CF64' : '#F05940' : '#D95C5C');
     }, $data);
     return array(array('name' => trans('check.latency'), 'data' => $data));
 }
Exemplo n.º 2
0
 public function fire(Illuminate\Queue\Jobs\Job $job, $data)
 {
     $check = Check::findOrFail($data);
     $headers = array();
     $options = array();
     if (!empty($check->username)) {
         $options['auth'] = array($check->username, $check->password);
     }
     try {
         $latencyStart = microtime(true);
         $response = Requests::get($check->url, $headers, $options);
         $latency = round((microtime(true) - $latencyStart) * 1000);
     } catch (Requests_Exception $e) {
         $latency = round((microtime(true) - $latencyStart) * 1000);
         if (CheckResult::create(array('check_id' => $check->id, 'status_code' => 0, 'success' => false, 'latency' => $latency, 'content' => trans('check.errors.resolve-host', array('host' => $check->url))))) {
             $job->delete();
         } else {
             $job->release();
         }
         return true;
     }
     $lastCheck = CheckResult::where('check_id', '=', $check->id)->orderBy('created_at', 'desc')->first();
     if ($response->success) {
         if (isset($lastCheck) && !$lastCheck->success) {
             Mail::queue('email.check.online', array('id' => $check->id, 'title' => $check->title), function ($message) use($check) {
                 $message->to($check->theUser->email)->subject(trans('check.job.email.online.subject', array('title' => $check->title)));
             });
         }
         if (CheckResult::create(array('check_id' => $check->id, 'status_code' => $response->status_code, 'success' => true, 'latency' => $latency))) {
             $job->delete();
         } else {
             $job->release();
         }
     } else {
         if (isset($lastCheck) && $lastCheck->success) {
             Mail::queue('email.check.offline', array('id' => $check->id, 'title' => $check->title, 'statusCode' => $response->status_code), function ($message) use($check) {
                 $message->to($check->theUser->email)->subject(trans('check.job.email.offline.subject', array('title' => $check->title)));
             });
         }
         if (CheckResult::create(array('check_id' => $check->id, 'status_code' => $response->status_code, 'success' => false, 'content' => $response->body, 'headers' => json_encode($response->headers), 'latency' => $latency))) {
             $job->delete();
         } else {
             $job->release();
         }
     }
 }
Exemplo n.º 3
0
 public function unpause($id)
 {
     $check = Check::findOrFail($id);
     $check->paused = false;
     $check->save();
     Session::flash('success', trans('check.unpause.success'));
     return Redirect::route('check.index');
 }