Пример #1
0
 protected function checkservicesAction()
 {
     $dictionary = new Base_Dictionary();
     //        $distStatuses = $dictionary->setSource('nagios_status',array("entry in ('WARNING', 'CRITICAL')", 'ghost = false'))->getDictionary();
     $distStatuses = $dictionary->setSource('nagios_status', array('ghost = false'))->getDictionary();
     $statusKeys = array_flip($distStatuses);
     $model = new NagiosQueue();
     $select = $model->select()->setIntegrityCheck(false)->from(array('lnq' => 'nagios_queue'), array('id'), 'log')->where('lnq.ghost = ?', 'false')->where('lnq.actual_type in (?)', $statusKeys);
     $rowSet = $model->fetchAll($select)->toArray();
     $config = Zend_Registry::get('config');
     $lastStep = array_pop(array_keys($config['nagios']['step']));
     foreach ($rowSet as $row) {
         $checkerVal = array();
         $currentVal = array();
         $current = $model->findOne($row['id']);
         $services = $current->getDependentServices();
         if (!empty($services)) {
             foreach ($services as $serviceRow) {
                 $sc = new ServiceChecker();
                 $scRow = $sc->getRow($serviceRow->id, $current->actual_type);
                 try {
                     $service = new Logic_Service($serviceRow);
                     $sms = new Logic_Sms($service->getServiceRow(), $config['nagios']['ip']);
                     $sms->text($this->opts->phone, 'test sms');
                     $error = false;
                 } catch (Exception $exc) {
                     $error = true;
                 }
                 if ($current->actual_type == $statusKeys['WARNING']) {
                     if ($error) {
                         $currentVal['last_occurence'] = date('c');
                         $currentVal['occurence_count'] = $current->occurence_count + 1;
                         $checkerVal['actual_type'] = $statusKeys['WARNING'];
                         if ($scRow->step >= 3) {
                             $currentVal['actual_type'] = $statusKeys['CRITICAL'];
                             $checkerVal['actual_type'] = $statusKeys['CRITICAL'];
                         }
                         if (time() >= strtotime($current->last_occurence) + $config['nagios']['step'][$scRow->step]) {
                             $checkerVal['step'] = $scRow->step < $lastStep ? $scRow->step + 1 : $scRow->step;
                         }
                     } else {
                         if ($current->actual_type == $scRow->actual_type || empty($scRow->actual_type)) {
                             $checkerVal['actual_type'] = $statusKeys['OK'];
                             $checkerVal['step'] = 1;
                         }
                         if (time() >= strtotime($current->last_occurence) + $config['nagios']['step'][$scRow->step]) {
                             $checkerVal['step'] = $scRow->step + 1;
                             if ($values['step'] == $lastStep) {
                                 $currentVal['actual_type'] = $statusKeys['OK'];
                                 $checkerVal['ghost'] = 'true';
                             }
                         }
                     }
                 } elseif ($current->actual_type == $statusKeys['CRITICAL']) {
                     if (strtotime($current->last_occurence) + $config['nagios']['step'][$scRow->step] >= time()) {
                         if ($error) {
                             $currentVal['last_occurence'] = date('c');
                             $currentVal['occurence_count'] = $current->occurence_count + 1;
                             $checkerVal['step'] = $scRow->step > $lastStep ? $scRow->step + 1 : $scRow->step;
                         } else {
                             $checkerVal['actual_type'] = $statusKeys['WARNING'];
                             $checkerVal['step'] = 1;
                             $currentVal['actual_type'] = $statusKeys['WARNING'];
                         }
                     }
                 }
                 if (!empty($currentVal)) {
                     $current->setFromArray($currentVal);
                     $current->save();
                 }
                 if (!empty($checkerVal)) {
                     $scRow->setFromArray($checkerVal);
                     $scRow->save();
                 }
             }
         }
     }
 }
Пример #2
0
 /**
  * 
  * @param Logic_Service $service
  * @param type $reason
  * @param type $lvl
  */
 protected function _logRejected(Logic_Service &$service, $reason, $lvl = Zend_Log::INFO)
 {
     if (false === self::_checkDebugPriority($lvl)) {
         return;
     }
     $logger = Zend_Registry::get('LoadBalancerRejectedLog');
     $messages = $service->getValidatorMessages();
     foreach ($messages as $validatorName => $message) {
         $logger->log($reason, $lvl, array('ws_service_id' => $service->getItemId(), 'ws_service_sms_group_id' => $this->_serviceGroupId, 'messages' => Zend_Json::encode($message), 'validator_name' => $validatorName));
     }
 }