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(); }
/** * Obsługa błedów dla usług SMS * @param Logic_Service_Exception $exception * @throws Logic_WebService_Sms_Exception */ protected function _errorHandler($code, $message, $sid) { $errorStorage = new SmsMultiinfoErrorConfig(); $errorConf = $errorStorage->getErrorConfig($code, $message, $sid); $errorDict = $errorStorage->getErrorDict($errorConf); $nagiosStorage = new NagiosQueue(); try { $nagiosStorage->insert(array('dict_id' => $errorDict->id)); } catch (Exception $exc) { throw new Logic_WebService_Sms_Exception('Cannot save data to Nagios Queue', null, $exc); } throw new Logic_WebService_Sms_Exception('Blad bramki SMS: ' . $errorDict->code . ' ' . $errorDict->description, 512); }
/** * dodawanie nowej reklamacji * @return */ public function addAction() { $request = $this->getRequest(); $nqId = $request->getParam('id'); $disable = isset($nqId) ? true : false; $form = new Logic_Ws_Complaint_Form_Generic($disable); if ($request->isPost()) { $post = $request->getPost(); if (key_exists('cancel', $post)) { foreach ($post as $key => $value) { $post[$key] = ''; } $request->setPost($post); } else { if ($form->isValid($post)) { try { $id = $this->_model->createComplaint($form); //$this->_model->showComplaint($id); $this->_helper->messenger->success(); $this->_helper->redirector('send', null, null, array('id' => $this->_helper->IdConvert->strToHex($id))); return; } catch (Logic_Ws_Exception $e) { $this->_helper->messenger->error($e->getMessage()); } } } } if (!empty($nqId)) { $nqId = $this->_helper->IdConvert->hexToStr($nqId); $nqModel = new NagiosQueue(); $nqRow = $nqModel->getRowWithDependencies($nqId); $repetable = $nqRow->occurence_count > 1 ? 'Tak, wystąpień: ' . $nqRow->occurence_count : 'Nie'; $user = Zend_Auth::getInstance()->getIdentity(); $defaults = array('surname' => $user->surname, 'name' => $user->first_name, 'phone_number' => $user->phone, 'email' => $user->email, 'special_id' => $nqRow->special_id, 'description' => $nqRow->error_code . ':: ' . $nqRow->error_message, 'login' => $nqRow->service_login, 'problem_phone_number' => $nqRow->phone_number, 'start_problem_date' => date('Y-m-d h:i:s', strtotime($nqRow->created_at)), 'problem_info' => $repetable, 'last_problem_date' => date('Y-m-d h:i:s', strtotime($nqRow->last_occurence)), 'nagios_queue_id' => $nqId); $form->setDefaults($defaults); } $this->view->form = $form; }
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(); }