_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("RecordType", CS::translate('CSALIVE_MONITOR_RECORD_TYPE', 'csalive'), $this->getRecordTypes(), 'Pdmarticle', FALSE, array( 'PaneTitle' => CS::translate('REST_GUI_EDIT_SETTINGS'), 'noEmptyOption' => true, 'onlyFolder' => true )); $editor->addField("InspectRequests", CS::translate('CSALIVE_MONITOR_REQUEST_VALUES', 'csalive'), $this->getInspectProcesses(), '', FALSE, array( 'PaneTitle' => CS::translate('REST_GUI_EDIT_SETTINGS'), 'noEmptyOption' => true, 'multiple' => true )); $editor->addField('TimeLag', CS::translate('CSALIVE_MONITOR_TIME_LAG', 'csalive'), 'number', 2, FALSE, array( 'PaneTitle' => CS::translate('REST_GUI_EDIT_SETTINGS') )); $editor->addField('TimeCushion', CS::translate('CSALIVE_MONITOR_TIME_CUSHION', 'csalive'), 'number', 60, false, [ '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->strObjectType = $this->_observer->getValue('RecordType'); $this->arrChosenRequests = explode(',', $this->_observer->getValue('InspectRequests')); $this->intTimeLag = $this->_observer->getValue('TimeLag'); $this->intTimeCushion = $this->_observer->getValue('TimeCushion'); if (!empty($this->arrChosenRequests) && !empty($this->strObjectType)) { try { if (!CassandraAPI::isCassandraStarted()) { //throw new Exception('Cassandra is not started.'); } foreach ((array) $this->arrChosenRequests as $strFunctionName) { if (!method_exists($this, $strFunctionName)) { continue; } $arrReturnValues = $this->$strFunctionName(); if (!empty($arrReturnValues)) { $this->storeResultsInDatabase($intObserverID, $arrReturnValues['Value'], $arrReturnValues['Unit'], 'Cassandra.' . substr($strFunctionName, 7)); } } } catch (Exception $ex) { $this->storeResultsInDatabase($intObserverID, 99999, $ex->getMessage(), 'Cassandra.Error'); //$this->quickAlert($ex->getMessage()); } } } ///// PRIVATE FUNCTIONS //////////////////////////////////////////////////////////////////////////////////////////////// private function getCassandraPrefix() { return 'export_'; } /** * Returns an array of Strings of all processes the plugin can monitor. * * @return array Returns all processes possible to be inspect */ private function getInspectProcesses() { $arrClassMethods = get_class_methods($this); $strSearchWord = 'request'; $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; } /** * Returns an array of Strings of all available filetypes * * @return array Possible datatypes that can be chosen to be monitored */ private function getRecordTypes() { return (array) array( 'Pdmarticle' => CS::translate('Pdmarticle'), 'Mamfile' => CS::translate('Mamfile'), 'Pdmarticlestructure' => CS::translate('Pdmarticlestructure'), 'User' => CS::translate('User') ); } /** * Quality of life method for faster debugging. * * @param mixed $mixMessage */ private function quickAlert($mixMessage) { alert($mixMessage, 1); die(); } /** * Measures the difference in the object count between the contentserv and cassandra database. * * @return array Returns an array containing the values for the database export */ private function requestCassandraDataQuality() { $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); } /** * 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(); } }