public function testGetService() { $service = service::get_service('local_nagios', 'scheduled_task'); $this->assertInstanceOf('local_nagios\\service', $service); $this->setExpectedException('local_nagios\\invalid_service_exception'); $service = service::get_service('local_nagios', 'non_existent'); }
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with local_nagios. If not, see <http://www.gnu.org/licenses/>. // // Author: Michael Aherne // Copyright 2014 University of Strathclyde require_once '../../config.php'; require_once $CFG->libdir . '/adminlib.php'; require_login(SITEID); require_capability('moodle/site:config', context_system::instance()); admin_externalpage_setup('local_nagios'); $PAGE->set_context(context_system::instance()); $PAGE->set_url('/local/nagios/admin.php'); $PAGE->set_pagelayout('standard'); $PAGE->set_pagetype('admin'); $PAGE->set_heading("Nagios services"); $PAGE->navbar->add("Nagios services"); $action = optional_param('action', 'servicelist', PARAM_TEXT); $out = $PAGE->get_renderer('local_nagios'); if ($action == 'servicelist') { $servicelist = \local_nagios\service::service_list(); echo $OUTPUT->header(); echo $OUTPUT->heading("Nagios services"); echo $out->render_servicelist($servicelist); echo $OUTPUT->box(markdown_to_html(get_string('servicelist_help', 'local_nagios'))); echo $OUTPUT->footer(); } else { die("Unknown action"); }
$service = $options['service']; $warning = $options['warning']; $critical = $options['critical']; $thresholds = new thresholds(); if ($options['warning']) { $thresholds->warning = threshold::from_string($options['warning']); } if ($options['critical']) { $thresholds->critical = threshold::from_string($options['critical']); } if (empty($thresholds->critical) && empty($thresholds->warning)) { echo "No valid thresholds given"; exit(service::NAGIOS_STATUS_UNKNOWN); } try { $service = service::get_service($plugin, $service); if (empty($service)) { echo "Unable to get service {$service} from {$plugin}"; exit(3); } $params = cli_get_params($service->get_param_defs()); $status = $service->check_status($thresholds, $params[0]); if (is_null($status)) { throw new Exception("Service check returned no status"); } echo $status->text; exit($status->status); } catch (Exception $e) { echo "ERROR: " . $e->getMessage(); exit(service::NAGIOS_STATUS_UNKNOWN); }