diff --git a/doc/Extensions/Services.md b/doc/Extensions/Services.md index fa7237cc9d..ea68763848 100644 --- a/doc/Extensions/Services.md +++ b/doc/Extensions/Services.md @@ -22,17 +22,24 @@ $config['nagios_plugins'] = "/usr/lib/nagios/plugins"; This will point LibreNMS at the location of the nagios plugins - please ensure that any plugins you use are set to executable. +Finally, you now need to add check-services.php to the current cron file (/etc/cron.d/librenms typically) like: +```bash +*/5 * * * * librenms /opt/librenms/check-services.php >> /dev/null 2>&1 +``` + Now you can add services via the main Services link in the navbar, or via the 'Add Service' link within the device, services page. ## Performance data -By default, the poller module will collect all performance data that the check script returns and display each datasource on a separate graph. +By default, the check-services script will collect all performance data that the Nagios script returns and display each datasource on a separate graph. However for some modules it would be better if some of this information was consolidated on a single graph. An example is the ICMP check. This check returns: Round Trip Average (rta), Round Trip Min (rtmin) and Round Trip Max (rtmax). These have been combined onto a single graph. -If you find a check script that would benefit from having some datasources graphed together, please log an issue on GitHub with the debug information from the poller, and let us know which DS's should go together. Example below: +If you find a check script that would benefit from having some datasources graphed together, please log an issue on GitHub with the debug information from the script, and let us know which DS's should go together. Example below: + ./check-services.php -d + -- snip -- Nagios Service - 26 Request: /usr/lib/nagios/plugins/check_icmp localhost Perf Data - DS: rta, Value: 0.016, UOM: ms @@ -48,3 +55,16 @@ If you find a check script that would benefit from having some datasources graph } OK u:0.00 s:0.00 r:40.67 RRD[update /opt/librenms/rrd/localhost/services-26.rrd N:0.016:0:0.044:0.009] + -- snip -- + +## Alerting + +Services uses the Nagios Alerting scheme where: + + 0 = Ok, + 1 = Warning, + 2 = Critical, + +To create an alerting rule to alert on service=critical, your alerting rule would look like: + + %services.service_status = "2" diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index e638aafe02..e57465ca46 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -219,13 +219,13 @@ if ($config['show_services']) { 0) || ($service_status[2] > 0)) { +if (($service_status[1] > 0) || ($service_status[2] > 0)) { echo ' '; - if ($service_status[2] > 0) { - echo '
  • Warning ('.$service_status[2].')
  • '; + if ($service_status[1] > 0) { + echo '
  • Warning ('.$service_status[1].')
  • '; } - if ($service_status[0] > 0) { - echo '
  • Critical ('.$service_status[0].')
  • '; + if ($service_status[2] > 0) { + echo '
  • Critical ('.$service_status[2].')
  • '; } } diff --git a/html/pages/device/services.inc.php b/html/pages/device/services.inc.php index d226001fda..7cbdb99d65 100644 --- a/html/pages/device/services.inc.php +++ b/html/pages/device/services.inc.php @@ -51,13 +51,13 @@ if (count($services) > '0') { Ok"; } - elseif ($service['service_status'] == 2) { + elseif ($service['service_status'] == 1) { $status = "Warning"; } - elseif ($service['service_status'] == 0) { + elseif ($service['service_status'] == 2) { $status = "Critical"; } else { diff --git a/html/pages/services.inc.php b/html/pages/services.inc.php index 8b8cbfca1b..a4b1ec3d39 100644 --- a/html/pages/services.inc.php +++ b/html/pages/services.inc.php @@ -74,14 +74,14 @@ print_optionbar_end(); $sql_param = array(); if (isset($vars['state'])) { if ($vars['state'] == 'ok') { - $state = '1'; - } - elseif ($vars['state'] == 'critical') { $state = '0'; } - elseif ($vars['state'] == 'warning') { + elseif ($vars['state'] == 'critical') { $state = '2'; } + elseif ($vars['state'] == 'warning') { + $state = '1'; + } } if (isset($state)) { $where .= " AND service_status= ? AND service_disabled='0' AND `service_ignore`='0'"; @@ -123,10 +123,10 @@ foreach (dbFetchRows($host_sql, $host_par) as $device) { } foreach (dbFetchRows("SELECT * FROM `services` WHERE `device_id` = ? $where", $sql_param) as $service) { - if ($service['service_status'] == '0') { + if ($service['service_status'] == '2') { $status = "".$service['service_type'].""; } - else if ($service['service_status'] == '1') { + else if ($service['service_status'] == '0') { $status = "".$service['service_type'].""; } else { diff --git a/includes/services.inc.php b/includes/services.inc.php index 97a7845961..0a3f7996f4 100644 --- a/includes/services.inc.php +++ b/includes/services.inc.php @@ -128,28 +128,9 @@ function poll_service($service) { // Some debugging d_echo("\nNagios Service - ".$service['service_id']."\n"); d_echo("Request: ".$check_cmd."\n"); - list($status, $msg, $perf) = check_service($check_cmd); + list($new_status, $msg, $perf) = check_service($check_cmd); d_echo("Response: ".$msg."\n"); - // TODO: Use proper Nagios service status. 0=Ok,1=Warning,2=Critical,Else=Unknown - // Not now because we dont want to break existing alerting rules. - if ($status == 0) { - // Nagios 0 = Libre 1 - Ok - $new_status = 1; - } - elseif ($status == 1) { - // Nagios 1 = Libre 2 - Warning - $new_status = 2; - } - elseif ($status == 2) { - // Nagios 2 = Libre 0 - Critical - $new_status = 0; - } - else { - // Unknown - $new_status = 2; - } - // If we have performance data we will store it. if (count($perf) > 0) { // Yes, We have perf data. diff --git a/sql-schema/108.sql b/sql-schema/110.sql similarity index 100% rename from sql-schema/108.sql rename to sql-schema/110.sql