_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("FilePath", CS::translate('CSALIVE_MONITOR_FILE', 'csalive'), '', '', FALSE, array( 'PaneTitle' => CS::translate('REST_GUI_EDIT_SETTINGS'), 'onlyFolder' => true )); $editor->addField("SelectedContent", CS::translate('CSALIVE_MONITOR_SERVICE_CONTENT', 'csalive'), $this->getContentNames(), 'Content1', FALSE, array( 'PaneTitle' => CS::translate('REST_GUI_EDIT_SETTINGS'), 'noEmptyOption' => true )); } ///// PROTECTED METHODS ////////////////////////////////////////////////////// /** * Starts the observation. * * Checks if the file in the given path exists * * 1: TRUE | 2: FALSE * * Saves the text content of the file if possible in the "Unit" column */ protected function _processObservation() { $observation = CSMonitor::createObservation($this->_observer->getID(), 'CS.FileContent.' . $this->getSelectedContent()); $observation->setTimestamp(CS::getDate()); $state = CSMonitor::MONITOR_GUI_NOTIFICATION_NONE_ID; $observation->setState($state); $observation->setWarningValue(1); $observation->setCriticalValue(2); $intMeasuredValue = 2; if (!empty($this->getSelectedContent())) { if (file_exists($this->getSelectedFile())) { if (!empty($this->getSelectedFile())) { $intMeasuredValue = 1; } } } $observation->setMeasuredValue($intMeasuredValue); if (file_get_contents($this->getSelectedFile()) == FALSE) { $strUnit = 'Status (File could not been read.)'; } else { $strUnit = file_get_contents($this->getSelectedFile()); } $observation->setUnit($strUnit); $observation->store(); } ///// PRIVATE METHODS ////////////////////////////////////////////////////// /** * Gets the entered value from the editor * * @return String Path */ private function getSelectedFile() { $strPath = $this->_observer->getValue('FilePath'); return $strPath; } /** * Gets the entered value from the editor * * @return String Content name */ private function getSelectedContent() { $strContent = $this->_observer->getValue('SelectedContent'); return $strContent; } /** * Gets the adjustable names for the services to prevent them from * overwriting each other accidentally * * @return array Strings which can be selected in the interface */ private function getContentNames() { $arrSelectableContent = array(); for ($intI = 1; $intI <= 10; $intI++) { $arrSelectableContent['Content' . $intI] = 'Content' . $intI; } return $arrSelectableContent; } }