_processObservation(); } /** * Adds additional editor fields to the Contentserv interface * * @param CSGuiEditor $editor Editor object that can add fields * @param CSMonitorObserver $observer */ public function prepareEditor(CSGuiEditor $editor, CSMonitorObserver $observer) { $this->_observer = $observer; $editor->addField("UserName", CS::translate('CSALIVE_MONITOR_OPTIONAL_USER_NAME', 'sawsalive'), '', '', FALSE, array( 'PaneTitle' => CS::translate('REST_GUI_EDIT_SETTINGS') )); $editor->addField("Password", CS::translate('CSALIVE_MONITOR_OPTIONAL_PASSWORD', 'sawsalive'), 'password', '', FALSE, array( 'PaneTitle' => CS::translate('REST_GUI_EDIT_SETTINGS') )); } ///// PROTECTED FUNCTIONS ////////////////////////////////////////////////////////////////////////////////////////////// /** * Function is automatically called when the observation runs. */ protected function _processObservation() { $intObserverID = $this->_observer->getID(); $this->strUserName = $this->_observer->getValue('UserName'); $arrReturnValues = []; if (empty($this->strUserName)) { $this->strUserName = CSUser::getUserName(); if (empty($this->strUserName)) { $this->strUserName = 'admin'; } } $this->strPassword = $this->_observer->getValue('Password'); if (empty($this->strPassword)) { $this->strPassword = 'admin'; } try { $oActiveMQRestConnector = new ActiveMQRestConnector(); $aSubscriberPendingMessages = $oActiveMQRestConnector->getPendingMessages(); foreach ($aSubscriberPendingMessages as $sSubscriberName => $iSubscriberVal) { $arrReturnValues[str_replace(' ', '', $sSubscriberName)] = ['Value' => $iSubscriberVal, 'Unit' => 'Items']; } foreach ($arrReturnValues as $strKey => $arrValue) { if (isset($arrValue['Value'])) { $this->storeResultsInDatabase($intObserverID, $arrValue['Value'], $arrValue['Unit'], 'ActiveMQ.' . $strKey); } else { $this->storeResultsInDatabase($intObserverID, 99999, 'No cURL-Results received.', 'ActiveMQ.Error'); } } } catch (Exception $ex) { $this->storeResultsInDatabase($intObserverID, 99999, $ex->getMessage(), 'ActiveMQ'); } } ///// PRIVATE FUNCTIONS //////////////////////////////////////////////////////////////////////////////////////////////// /** * Stores a value with the given parameter in the monitor observation database * * @param integer $intObserverID ID which the observation ID shall have * @param mixed $mixedMeasuredValue Result that shall be stored in the value column * @param string $strUnit Unit of the value (ca. 150 character text field) * @param string $strServiceName Name of the result */ private function storeResultsInDatabase(int $intObserverID, $mixedMeasuredValue, string $strUnit, string $strServiceName) { $observation = CSMonitor::createObservation($intObserverID, $strServiceName); $observation->setMeasuredValue($mixedMeasuredValue); $observation->setTimestamp(CS::getDate()); $observation->setUnit($strUnit); $state = CSMonitor::MONITOR_GUI_NOTIFICATION_NONE_ID; $observation->setState($state); $observation->setWarningValue(1); $observation->setCriticalValue(2); $observation->store(); } }