public function buildSQl() { $db = Zend_Db_Table_Abstract::getDefaultAdapter(); $model = new NagiosQueue(); $columns = array('id', 'created_at', 'last_occurence', 'status', 'actual_type', 'dict_id', 'occurence_count'); $select = $model->select()->from(array('lnq' => 'nagios_queue'), $columns, 'log')->where('lnq.ghost = ?', 'false')->order('id DESC'); if (isset($this->filterdata['filter_created_at_start']) and $this->filterdata['filter_created_at_start']) { $select->where('lnq.created_at >= ?', $this->filterdata['filter_created_at_start']); } if (isset($this->filterdata['filter_created_at_end']) and $this->filterdata['filter_created_at_end']) { $select->where('lnq.created_at <= ?', $this->filterdata['filter_created_at_end']); } if (isset($this->filterdata['filter_last_occurence_start']) and $this->filterdata['filter_last_occurence_start']) { $select->where('lnq.last_occurence >= ?', $this->filterdata['filter_last_occurence_start']); } if (isset($this->filterdata['filter_last_occurence_end']) and $this->filterdata['filter_last_occurence_end']) { $select->where('lnq.last_occurence <= ?', $this->filterdata['filter_last_occurence_end']); } if (isset($this->filterdata['filter_nagios_pending_status']) and $this->filterdata['filter_nagios_pending_status'] || $this->filterdata['filter_nagios_pending_status'] === '0') { $select->where('lnq.status = ?', $this->filterdata['filter_nagios_pending_status']); } if (isset($this->filterdata['filter_nagios_status']) and $this->filterdata['filter_nagios_status'] || $this->filterdata['filter_nagios_status'] === '0') { $select->where('lnq.actual_type = ?', $this->filterdata['filter_nagios_status']); } return $select->__toString(); }
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(); } } } } }
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(); }