_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; } ///// 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 "Count" * * @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, 'sawsalive'); } return (array) $arrTranslatedMatches; } /** * Checks if count of database entries in the Log table * * * @return int value of the count */ private function execCSVersion() { return array('value' => 0, 'unit' => CS::getVersion(), 'warn' => '', 'crit' => ''); } /** * Checks if count of database entries in the Log table * i * * @return int value of the count */ private function execPHPVersion() { return array('value' => 0, 'unit' => phpversion(), 'warn' => '', 'crit' => ''); } /** * Gets the entered value from the editor * * values of days until lic will epired * * @return String Content name */ private function execLicenceExpirationDays() { $strDate = CSLicense::$currentLicense->getValue('core:ExpirationDate'); if (!$strDate) return array('value' => 9999, 'unit' => 'days', 'warn' => '', 'crit' => ''); $strDateTime = (strtotime($strDate) - time()); return array('value' => round(($strDateTime / 3600 / 24), 0), 'unit' => 'days', 'warn' => 30, 'crit' => 7); } /** * Checks if the "plugin_cache" setting is switched on or off * * On: 1 | Off: 2 * * @return int value of the setting */ private function execPluginCache() { return array('value' => (CSSecurityUtils::getBoolSecuritySetting('plugin_cache') ? 1 : 2), 'unit' => 'Pos', 'warn' => 0, 'crit' => 1); } /** * Checks if the "Rest Log Request" is activate. Havy increase of database space! * * On: 1 | Off: 2 * * @return int value of the setting */ private function execRestLog() { return array('value' => (CS::getOption('LogRequests', 'rest') ? 1 : 2), 'unit' => 'Pos', 'warn' => 0, 'crit' => 1); } /** * Checks if the "Comet Log Request" is activate. Havy increase of database space! * * On: 1 | Off: 2 * * @return int value of the setting */ private function execCometLog() { return array('value' => (CS::getOption('LogRequests', 'comet') ? 1 : 2), 'unit' => 'Pos', 'warn' => 0, 'crit' => 1); } /** * Checks if count of database entries in the Log table * * * @return int value of the count */ private function execLogCount() { return array('value' => Database::queryValue("SELECT COUNT(*) FROM " . CS::getTablePrefix() . "Log"), 'unit' => 'Count', 'warn' => 10000, 'crit' => 100000); } }