public function getGraphData() { if (Sentry::getUser()) { $user_id = Sentry::getUser()->id; $period = Input::get('check_report_period'); $mongo_id = Input::get('report_mongo_id'); $check_id = Input::get('report_check_id'); $mongoAPI = new MongoAPI(); $checkAlertEmail = new CheckAlertEmail(); $data = json_decode($mongoAPI->getServerModelData($mongo_id, $period), true); $data['alert'] = $checkAlertEmail->getDataByCheckId($check_id); return Response::json($data); } else { try { $user = Sentry::findUserById(Input::get('user_id')); $emf_group = Sentry::findGroupByName('EmfUsers'); if ($user->inGroup($emf_group)) { return $this->get_exired_message(Config::get('kuu.emf_login_page')); } else { return $this->get_exired_message(URL::route('login')); } } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { return $this->get_exired_message(URL::route('login')); } catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e) { return $this->get_exired_message(URL::route('login')); } } }
function getCheckSiteListByUserId($user_id) { $kuu_config = Config::get('kuu'); $ava_good = $kuu_config['ava_good']; $ava_not_good = $kuu_config['ava_not_good']; $query = "\n\t\t\tSELECT * FROM {$this->table} \n\t\t\tWHERE user_id={$user_id} \n\t\t\tORDER BY domain, type\n\t\t"; $result = DB::select($query); $datalist = array(); $data = array(); $domain = ''; $currentTime = time(); $mongo_id_list_after_one_day = array(); $mongo_id_list_less_one_day = array(); foreach ($result as $row) { if ($currentTime - $row->create_time > 86400) { $mongo_id_list_after_one_day[] = $row->mongo_id; } else { $mongo_id_list_less_one_day[] = $row->mongo_id; } if ($domain != $row->domain) { if (is_array($data) && count($data) > 0 && $domain != '') { $datalist[$domain] = $data; $data = array(); } $domain = $row->domain; } $option = json_decode($row->options); $data[] = array('passday' => intval(($currentTime - $row->create_time) / (24 * 3600)), 'check_id' => $row->check_id, 'mongo_id' => $row->mongo_id, 'type' => $row->type, 'host' => $row->host, 'is_paused' => $row->paused, 'url' => isset($row->url) ? $row->url : '', 'path' => isset($option->url_path) ? strlen($option->url_path) > 20 ? substr($option->url_path, 0, 20) . '[...]' : $option->url_path : $row->domain); } if (is_array($data) && count($data) > 0 && $domain != '') { $datalist[$domain] = $data; } if (is_array($datalist) && count($datalist) > 0) { $mongoAPI = new MongoAPI(); $lastDayCheckStates = $mongoAPI->getMultiCheckLastDayStatus($mongo_id_list_after_one_day, $mongo_id_list_less_one_day); // Log::info(print_r($lastDayCheckStates, true)); foreach ($datalist as &$domain) { foreach ($domain as &$data) { if (isset($lastDayCheckStates[$data['mongo_id']])) { $check_value = array(); $check_value['uptime'] = round($lastDayCheckStates[$data['mongo_id']]->availability * 100) / 100; if ($check_value['uptime'] > 99) { $check_value['uptime'] = round($check_value['uptime'] * 10) / 10; } else { $check_value['uptime'] = floor($check_value['uptime']); } if ($check_value['uptime'] < $ava_not_good) { $check_value['uptime_warning'] = true; $check_value['uptime_progress_class'] = 'progress-danger'; $check_value['uptime_progress_val'] = '20'; } else { if ($check_value['uptime'] < $ava_good) { $check_value['uptime_warning'] = false; $check_value['uptime_progress_class'] = 'progress-warning'; $check_value['uptime_progress_val'] = '50'; } else { $check_value['uptime_warning'] = false; $check_value['uptime_progress_class'] = 'progress-success'; $check_value['uptime_progress_val'] = '100'; } } $check_value['response_speed'] = $lastDayCheckStates[$data['mongo_id']]->response_time; $temp_speed = (3000 - $check_value['response_speed']) / 3000 * 100; if ($check_value['response_speed'] < 1000) { $check_value['response_speed_text'] = 'Fast'; $check_value['response_speed_warning'] = false; $check_value['response_speed_progress_class'] = 'progress-success'; } else { if ($check_value['response_speed'] < 2000) { $check_value['response_speed_text'] = 'Average'; $check_value['response_speed_warning'] = false; $check_value['response_speed_progress_class'] = 'progress-warning'; } else { if ($check_value['response_speed'] < 3000) { $check_value['response_speed_text'] = 'Too Slow'; $check_value['response_speed_warning'] = true; $check_value['response_speed_progress_class'] = 'progress-danger'; } else { $temp_speed = 0; $check_value['response_speed_text'] = 'Too Slow'; $check_value['response_speed_warning'] = true; $check_value['response_speed_progress_class'] = 'progress-danger'; } } } $check_value['response_speed'] = round($temp_speed * 100) / 100; $data['check_value'] = $check_value; } } } } return $datalist; }
public function delete_check() { $MongoAPI = new MongoAPI(); $mongo_request = $MongoAPI->deleteCheckInMongo($this->mongo_id); Log::info($mongo_request); $mongo_result = json_decode($mongo_request); if (isset($mongo_result->Result) && $mongo_result->Result == 'OK') { try { DB::beginTransaction(); foreach ($this->checkalertemail as $alert) { $alert->delete(); } $this->delete(); DB::commit(); } catch (\PDOException $e) { DB::rollback(); return false; } return true; } return false; }