_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', 'csalive'), '', '', FALSE, array( 'PaneTitle' => CS::translate('REST_GUI_EDIT_SETTINGS') )); $editor->addField("Password", CS::translate('CSALIVE_MONITOR_OPTIONAL_PASSWORD', 'csalive'), '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 { $strPreparedURL = Curl::prepareUrl('http://' . CS::getOption('activemqUrlHost', 'exportstaging') . ':8161/admin/xml/subscribers.jsp'); $strCurlReturn = Curl::GET($strPreparedURL, $this->strUserName, $this->strPassword); $objSimpleXML = new SimpleXMLElement($strCurlReturn); $intMasterValue = get_object_vars(get_object_vars(get_object_vars($objSimpleXML)['subscriber'][1])['stats'])['@attributes']['pendingQueueSize']; $arrReturnValues['MasterSubscriber'] = ['Value' => $intMasterValue, 'Unit' => 'Items']; $intElasticValue = get_object_vars(get_object_vars(get_object_vars($objSimpleXML)['subscriber'][0])['stats'])['@attributes']['pendingQueueSize']; $arrReturnValues['ElasticSubscriber'] = ['Value' => $intElasticValue, '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 //////////////////////////////////////////////////////////////////////////////////////////////// /** * Quality of life method for faster debugging. * * @param mixed $mixMessage */ private function quickAlert($mixMessage) { alert($mixMessage, 1); die(); } /** * 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(); } }