Poll service check only if the associated device is available (#8757)

* Update check-services.php

Poll service check only if the associated device is available.

* Update check-services.php

Updating line 68 based on laf suggestion.

* Update check-services.php

Also check the following before polling the service:
* "Disable ICMP Test" is enabled
* Service hostname/IP is different from associated device.

* Update check-services.php

Remove whitespaces.

* Update check-services.php

* Make check-services.php perform more similarly to services.wrapper.py - loop service checks per device and execute RunRules() function after polling all services for one device (like in poller.php).
* Add more debugging information, similar to poller.php

* Update check-services.php

Implement logging to eventlog when service is skipped due to icmp down event. Event is logged only once during device down event, which is achieved by checking value in service_disabled column in services table.

* Update check-services.php

Fix Travis errors.

* Update check-services.php

Revert back to one query and one foreach loop code.
Added inet6_ntop() for reading $service['ip'] value.
Removed RunRules() function.

* Update check-services.php

Formatting fixes.

* Update check-services.php

More formatting fixes. :)

* Update check-services.php

Removed 'alerts' from init_module.

* Update Services.md

Update Services documentation with info about changes to service checks polling logic.

* Update check-services.php

Fix spelling check on `previosly`.

* Update check-services.php

Replace phrase "Nagios Service" with "Service check".

* Update Services.md

Reword first two sentences of `Service checks polling logic` section.
This commit is contained in:
dsgagi
2018-07-25 09:38:52 +02:00
committed by Neil Lathwood
parent 4abf27b28e
commit 24d84aec9d
2 changed files with 66 additions and 4 deletions

View File

@ -35,8 +35,13 @@ if ($config['noinfluxdb'] !== true && $config['influxdb']['enable'] === true) {
$influxdb = false;
}
$poller_start = microtime(true);
rrdtool_initialize();
echo "Starting service polling run:\n\n";
$polled_services = 0;
$where = '';
if ($options['h']) {
if (is_numeric($options['h'])) {
@ -50,10 +55,59 @@ if ($options['h']) {
}
}
$sql = 'SELECT * FROM `devices` AS D, `services` AS S WHERE S.device_id = D.device_id ' . $where . ' ORDER by D.device_id DESC';
$sql = 'SELECT * FROM `devices` AS D'
.' INNER JOIN `services` AS S ON S.device_id = D.device_id AND D.disabled = 0 '.$where
.' LEFT JOIN `devices_attribs` as A ON D.device_id = A.device_id AND A.attrib_type = "override_icmp_disable"'
.' ORDER by D.device_id DESC;';
foreach (dbFetchRows($sql) as $service) {
// Run the polling function
poll_service($service);
} //end foreach
// Run the polling function if the associated device is up, "Disable ICMP Test" option is not enabled,
// or service hostname/ip is different from associated device
if ($service['status'] === "1" || ($service['status'] === '0' && $service['status_reason'] === 'snmp') ||
$service['attrib_value'] === 'true' || ($service['service_ip'] !== $service['hostname'] &&
$service['service_ip'] !== inet6_ntop($service['ip']) )) {
// Mark service check as enabled if it was disabled previously because device was down
if ($service['service_disabled'] === "1") {
dbUpdate(
array('service_disabled' => '0'),
'services',
'`service_id` = ?',
array($service['service_id'])
);
}
poll_service($service);
$polled_services++;
} else {
d_echo("\nService check - ".$service['service_id']."\nSkipping service check because device "
.$service['hostname']." is down due to icmp.\n");
// Mark service check as disabled while device is down and log to eventlog that service check is skipped,
// but only if it's not already marked as disabled
if ($service['service_disabled'] === "0") {
dbUpdate(
array('service_disabled' => '1'),
'services',
'`service_id` = ?',
array($service['service_id'])
);
log_event(
"Service check - {$service['service_desc']} ({$service['service_id']}) -
Skipping service check because device {$service['hostname']} is down due to icmp",
$device,
'service',
4,
$service['service_id']
);
}
}
} //end service foreach
$poller_end = microtime(true);
$poller_run = ($poller_end - $poller_start);
$poller_time = substr($poller_run, 0, 5);
$string = $argv[0]." ".date($config['dateformat']['compact'])
." - $polled_services services polled in $poller_time secs";
d_echo("$string\n");
rrdtool_close();

View File

@ -91,3 +91,11 @@ then you can run the following command to help troubleshoot services.
```
./check-services.php -d
```
## Service checks polling logic
Service check is skipped when the associated device is not pingable, and an appropriate entry is populated in the event log.
Service check is polled if it's `IP address` parameter is not equal to associated device's IP address, even when the associated device is not pingable.
To override the default logic and always poll service checks, you can disable ICMP testing for any device by switching `Disable ICMP Test` setting (Edit -> Misc) to ON.
Service checks will never be polled on disabled devices.