_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("url", CS::translate('URL', 'csalive'), '', '', FALSE, array( 'PaneTitle' => CS::translate('REST_GUI_EDIT_SETTINGS'), )); $editor->addField("timeOut", CS::translate('timeOut', 'csalive'), '', '', FALSE, array( 'PaneTitle' => CS::translate('REST_GUI_EDIT_SETTINGS'), 'noEmptyOption' => true )); $editor->addField("searchText", CS::translate('SEARCH_TEXT', 'csalive'), '', '', FALSE, array( 'PaneTitle' => CS::translate('REST_GUI_EDIT_SETTINGS'), 'noEmptyOption' => true )); $editor->addField("SelectedInDesignServer", CS::translate('CSALIVE_MONITOR_HTML_CONTENT', 'csalive'), $this->getServerNames(), 'HTML1', FALSE, array( 'PaneTitle' => CS::translate('REST_GUI_EDIT_SETTINGS'), 'noEmptyOption' => true )); } ///// PROTECTED METHODS ////////////////////////////////////////////////////// /** * Checks wether a HTTP content exists and saves the corresponding value * 1: TRUE | 2: FALSE */ protected function _processObservation() { $observation = CSMonitor::createObservation($this->_observer->getID(), 'HTML.' . $this->getSelectedInDesignServer()); $observation->setTimestamp(CS::getDate()); $observation->setUnit('Status'); $state = CSMonitor::MONITOR_GUI_NOTIFICATION_NONE_ID; $observation->setState($state); $observation->setWarningValue(1); $observation->setCriticalValue(2); $intMeasuredValue = 2; if ($this->getContentStatus() === true) { $intMeasuredValue = 1; } $observation->setMeasuredValue($intMeasuredValue); $observation->store(); } ///// PRIVATE METHODS ////////////////////////////////////////////////////// /** * Gets Status if the value from searchText exist in value from URL Response * * @return boolean */ private function getContentStatus() { $objCurl = curl_init(); $arrCurlOpt = array( CURLOPT_URL => $this->getURL(), CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => $this->getTimeOut() ); curl_setopt_array($objCurl, $arrCurlOpt); $strResult = curl_exec($objCurl); curl_close($objCurl); if (strstr($strResult, $this->getSearchText())) { return true; } else { return false; } } /** * Gets the entered value from the editor * * @return the entered Values */ private function getURL() { $strURL = $this->_observer->getValue('url'); return $strURL; } private function getTimeOut() { $intTimeOut = $this->_observer->getValue('timeOut'); return $intTimeOut; } private function getSearchText() { $strSearchText = $this->_observer->getValue('searchText'); return $strSearchText; } /** * Gets the entered value from the editor * * @return String Share name */ private function getSelectedInDesignServer() { $strServer = $this->_observer->getValue('SelectedInDesignServer'); return $strServer; } /** * Creates an array of 10 share names to choose from. * So that they don't overwrite each other accidentally * * @return array List of all selectable shares */ private function getServerNames() { $arrSelectableServers = array(); for ($intI = 1; $intI <= 10; $intI++) { $arrSelectableServers['HTML' . $intI] = 'HTML' . $intI; } return $arrSelectableServers; } }