Exemple #1
0
 public function doMonitorAsJobs()
 {
     $canCheckTime = time() - 60;
     $ids = $this->getCheckServiceIds($canCheckTime);
     $cmd = '';
     if ($ids) {
         Ym_Logger::info('Start monitor check:-----------------------------------------------------');
         foreach ($ids as $id) {
             $status = isset($id['status']) ? $id['status'] : 3;
             //3默认为unknown
             $theTime = $id['next_check_time'] ? $id['next_check_time'] : time();
             $lastTime = $id['last_check_time'] ? $id['last_check_time'] : $theTime - 60;
             $lastNotifyTime = $id['last_notify_time'] ? $id['last_notify_time'] : 0;
             $monitorApi = $id['monitor_api'] ? $id['monitor_api'] : '';
             if (!$monitorApi) {
                 Ym_Logger::error('Unknow monitor api on service_id : ' . $id["service_id"] . '!');
                 continue;
             }
             $cmd = '/alarm/monitorscript/' . $monitorApi . '/id/';
             $cmd .= $id['service_id'] . '/lastStatus/' . $status;
             $cmd .= '/lastTime/' . $lastTime . '/currentTime/' . $theTime . '/lastNotifyTime/' . $lastNotifyTime;
             Ym_CommonTool::phpCli($cmd, TRUE, FALSE);
         }
         Ym_Logger::info("End monitor check:-----------------------------------------------------");
     }
     return FALSE;
 }
Exemple #2
0
 public function getAccessLog($tables, $stepTime)
 {
     $returns = array();
     $nodes = count($tables);
     $slave = false;
     $recordTime = $this->logPersistentService->getRecordTime($this->logType, $stepTime);
     $from = intval($recordTime);
     $to = intval($from + $stepTime);
     foreach ($tables as $n => $table) {
         if ($nodes > 2 and $n == $nodes - 1) {
             $slave = true;
         }
         $after = $this->dataModel->getAfter($table, $to, $slave);
         if (!$after) {
             Ym_Logger::error('Access after false endTime: ' . date('Y-m-d H:i:s', $to));
             break;
             //                return false;
         }
     }
     $this->logPersistentService->updateRecordTime($this->logType, $to);
     foreach ($tables as $table) {
         $result = $this->dataModel->getData($table, $from, $to);
         $returns = array_merge($returns, $result);
     }
     return $returns;
 }
Exemple #3
0
 public static function output($flag = true, $msg = '', $data = array())
 {
     if ($flag) {
         $out = array('flag' => 'success', 'msg' => $msg, 'data' => $data);
     } else {
         $out = array('flag' => 'error', 'msg' => $msg, 'data' => $data);
         Ym_Logger::error($msg);
     }
     Ym_CommonTool::output(NULL, $out, 'json');
 }
Exemple #4
0
 private function output($flag = TRUE, $msg = '', $data = array())
 {
     if ($flag) {
         $out = array('flag' => 'success', 'msg' => $msg, 'data' => $data);
     } else {
         $out = array('flag' => 'error', 'msg' => $msg, 'data' => $data);
         Ym_Logger::error($msg);
     }
     Ym_CommonTool::output($this, $out, 'json');
 }
Exemple #5
0
 public static function outputJsonp($flag = TRUE, $msg = '', $data = array(), $obj = NULL)
 {
     // output json {"flag":"error","msg":"","data":[]}
     if ($flag) {
         $out = array('flag' => 'success', 'msg' => $msg, 'data' => $data);
     } else {
         $out = array('flag' => 'error', 'msg' => $msg, 'data' => $data);
         Ym_Logger::error($msg);
     }
     Ym_CommonTool::output($obj, $out, 'jsonp');
     exit;
 }
Exemple #6
0
 public function getAfter($table, $time, $slave = false)
 {
     $returns = false;
     $timeout = 30;
     $slaveLimit = 10;
     if ($slave) {
         $d = $this->getData($table, $time, $time);
         if (count($d) < $slaveLimit) {
             return TRUE;
         }
     }
     for ($i = 0; $i < $timeout; $i++) {
         // 获取范围外数据
         $this->mongoDao = new Dao_Mongo($this->logType);
         $this->mongoDao->orderBy(array("time" => -1));
         $this->mongoDao->limit(1);
         $data = $this->mongoDao->get($table);
         if (count($data) < 1) {
             $returns = true;
         } else {
             $lastData = current($data);
             $lastTime = isset($lastData['time']) ? $lastData['time']->sec : 0;
             if ((int) abs($lastTime - $time) >= $timeout) {
                 $returns = true;
                 break;
             }
             if ($lastTime < $time) {
                 Ym_Logger::error(date('Y-m-d H:i:s', $time) . ' need wait for ' . $table . ' ' . date('Y-m-d H:i:s', $lastTime));
             }
             if ($lastTime > $time) {
                 $returns = true;
                 break;
             } else {
                 sleep(1);
                 continue;
             }
         }
     }
     return $returns;
 }
Exemple #7
0
 /**
  * 
  * 过滤用户报警配置
  * 
  * @param array $checkResult
  * @param int $lastStatus
  * @param str $smethod
  * @param str $userid
  */
 public function filterUser($checkResult, $lastStatus, $smethod, $userid = '')
 {
     $currentMethod = '';
     $code = isset($checkResult['code']) ? $checkResult['code'] : 0;
     $uidarr = $this->getUsers($userid);
     if ($uidarr) {
         foreach ($uidarr as $u) {
             if (!$u['notify_status']) {
                 Ym_Logger::error('UID: ' . $userid . ' DisableNotify');
                 continue;
             }
             if (!$this->getNotifyType(explode(',', $u['notify_type']), $code, $lastStatus)) {
                 continue;
             }
             $umethod = $this->getnotifyMethod(explode(',', $u['notify_method']));
             if (!$umethod) {
                 continue;
             }
             if ($smethod == 3) {
                 $currentMethod = $umethod;
             } else {
                 if ($umethod < 3 and $umethod != $smethod) {
                     continue;
                 }
                 $currentMethod = $smethod;
             }
             if (!$this->getNotifyPeriod($u['notify_period'])) {
                 continue;
             }
             $filter = 0;
             if ($u['host_id'] and in_array(long2ip($checkResult['ip']), explode(',', $u['host_id']))) {
                 $filter = 1;
             }
             if ($filter == 0 and $u['apps'] and in_array($checkResult['app'], explode(',', $u['apps']))) {
                 $filter = 1;
             }
             if ($filter == 0 and $u['keyword']) {
                 $keywords = explode("\n", $u['keyword']);
                 foreach ($keywords as $k) {
                     if (strpos($checkResult['msg'], $k) !== FALSE) {
                         $filter = 1;
                     }
                 }
             }
             if (!$filter) {
                 continue;
             }
             switch ($currentMethod) {
                 case 3:
                     $this->_C['email'][] = $u['id'];
                     $this->_C['sms'][] = $u['id'];
                     break;
                 case 2:
                     $this->_C['sms'][] = $u['id'];
                     break;
                 case 1:
                     $this->_C['email'][] = $u['id'];
                     break;
             }
         }
     }
 }
Exemple #8
0
 public function myoutput($flag = TRUE, $msg = '', $data = array())
 {
     if ($flag) {
         $out = array('flag' => 'success', 'msg' => $msg, 'data' => $data);
     } else {
         $out = array('flag' => 'error', 'msg' => $msg, 'data' => $data);
         Ym_Logger::error($msg);
     }
     self::output($this, $out, 'json');
 }