_processObservation(); } /** * Adds additional editor fields to the Contentserv interface * * @param CSGuiEditor $editor * @param CSMonitorObserver $observer */ public function prepareEditor(CSGuiEditor $editor, CSMonitorObserver $observer) { $this->_observer = $observer; $editor->addField("ElasticSearch", CS::translate('CSALIVE_ELASTIC_SEARCH', 'csalive'), 'checkbox', 0, FALSE, array( 'PaneTitle' => CS::translate('REST_GUI_EDIT_SETTINGS') )); $editor->addField("Cassandra", CS::translate('CSALIVE_CASSANDRA_SEARCH', 'csalive'), 'checkbox', 0, FALSE, array( 'PaneTitle' => CS::translate('REST_GUI_EDIT_SETTINGS') )); } ///// PROTECTED METHODS ////////////////////////////////////////////////////// protected function _processObservation() { $arrExecs = $this->getInspectProcesses(); foreach ((array) $arrExecs as $strFunctionName => $strName) { if (!method_exists($this, $strFunctionName)) { continue; } $strService = 'Core.' . substr($strFunctionName, 4); $mixedReturnValue = $this->$strFunctionName(); if ($mixedReturnValue !== NULL) { $this->saveReturnValue($mixedReturnValue['value'], $strService . 'Value', $mixedReturnValue['unit'], $mixedReturnValue['warn'], $mixedReturnValue['crit']); } } } ///// PRIVATE METHODS ////////////////////////////////////////////////////// /** * Is called when a function has a return value. * Saves the return value in the database with the Unit * * @param mixed $mixedReturnValue * @param String $strService */ private function saveReturnValue($mixedReturnValue, $strService, $strUnit = 's', $intWarn = 1, $intCrit = 2) { $observation = CSMonitor::createObservation($this->_observer->getID(), $strService); $observation->setMeasuredValue($mixedReturnValue); $observation->setTimestamp(CS::getDate()); $observation->setUnit($strUnit); $state = CSMonitor::MONITOR_GUI_NOTIFICATION_NONE_ID; $observation->setState($state); $observation->setWarningValue($intWarn); $observation->setCriticalValue($intCrit); $observation->store(); } /** * Returns an array of Strings of all processes the plugin can monitor * * @return array all processes possible to be inspect */ private function getInspectProcesses() { $arrClassMethods = get_class_methods($this); $strSearchWord = 'exec'; $arrMatches = array_filter((array) $arrClassMethods, function($var) use ($strSearchWord) { return preg_match("/$strSearchWord/i", $var); }); foreach ((array) $arrMatches as $value) { $arrTranslatedMatches[$value] = CS::translate($value, 'csalive'); } return (array) $arrTranslatedMatches; } /** * Checks If the Elastic Search is available * * * @return int value of the count */ private function execElasticSearch() { if (!$this->_observer->getValue('ElasticSearch')) return NULL; CS::requireFile(CS_ADMIN. 'core/extensions/exportstaging/api/CSExportStagingUtils.php'); $arrVal = CSExportStagingUtils::isServiceRunning(CSExportStagingUtils::ES_PROPERTY_ELASTICSEARCH); return array('value' => (($arrVal[0] == CSExportStagingUtils::STATUS_RUNNING) ? 2 : 1), 'unit' => 'Pos', 'warn' => 0, 'crit' => 1); } /** * Checks If the Cassandra Database is available * * * @return int value of the count */ private function execCassandraDatabase() { if (!$this->_observer->getValue('Cassandra')) return NULL; CS::requireFile(CS_ADMIN. 'core/extensions/exportstaging/api/CSExportStagingUtils.php'); $aResult = ServiceProviderUtils::getServiceStatus('cassandra'); $iStatus = 1; if (is_array($aResult)) { $aResult = reset($aResult); if (array_key_exists('RUNNING', $aResult)) $iStatus = 2; } return array('value' => $iStatus, 'unit' => 'Pos', 'warn' => 0, 'crit' => 1); } /** * Checks If the Active MQ for Cassandra Database is available * * * @return int value of the count */ private function execActiveMQ() { if (!$this->_observer->getValue('Cassandra')) return NULL; CS::requireFile(CS_ADMIN. 'core/extensions/exportstaging/api/CSExportStagingUtils.php'); $arrVal = CSExportStagingUtils::isServiceRunning(CSExportStagingUtils::ES_PROPERTY_ACTIVEMQ); return array('value' => (($arrVal[0] == CSExportStagingUtils::STATUS_RUNNING) ? 2 : 1), 'unit' => 'Pos', 'warn' => 0, 'crit' => 1); } /** * Checks If the Active MQ for Cassandra Database is available * * * @return int value of the count */ private function execExportExecuter() { if (!$this->_observer->getValue('Cassandra')) return NULL; CS::requireFile(CS_ADMIN. 'core/extensions/exportstaging/api/services/ExportExecutorAPI.php'); return array('value' => ((ExportExecutorAPI::isExportExecutorStarted()) ? 2 : 1), 'unit' => 'Pos', 'warn' => 0, 'crit' => 1); } /** * Checks If the Active MQ for Cassandra Database is available * * * @return int value of the count */ private function execSqlDatabase() { if (!$this->_observer->getValue('Cassandra')) return NULL; CS::requireFile(CS_ADMIN. 'core/extensions/exportstaging/api/services/ExportExecutorAPI.php'); return array('value' => ((ExportExecutorAPI::isExportExecutorStarted()) ? 2 : 1), 'unit' => 'Pos', 'warn' => 0, 'crit' => 1); } }