Ejemplo n.º 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();
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 public function checkInNagiosQueue($id = null)
 {
     $dict = new Base_Dictionary();
     $de = $dict->setSource('nagios_pending_status', array("entry NOT ILIKE 'SOLVED'"))->getDictionary();
     $id = !is_null($id) ? $id : $this->getItemId();
     $model = new NagiosQueue();
     $select = $model->select()->setIntegrityCheck(false)->from(array('lnq' => 'nagios_queue'), '*', 'log')->joinLeft(array('ssmed' => 'multiinfo_error_dict'), 'ssmed.id = lnq.dict_id', array(), 'sms')->joinLeft(array('ssmec' => 'multiinfo_error_config'), 'ssmed.id = ssmec.dict_id', array(), 'sms')->where('lnq.ghost = ?', 'false')->where('ssmec.service_id = ?', $id)->where('lnq.status in (?)', array_keys($de))->order('id DESC');
     return $model->fetchAll($select)->toArray();
 }