Example #1
0
 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');
 }
Example #2
0
$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);
}