Log an event for each Service Status change (#8968)

Hello

Here is a proposal for a pièce of code to log (using log_events) each service status change onto the device itself. 

Let me know if we should create the "getStatusText()" function to convert the int to "OK", "Critical" etc etc . I searched for such a function but did not find it. 

I also add to use a hack for the SQL cause it would prevent the device_id valueto be available in the resulting $service when device_attribs is empty for the device. If you have a better way to suggest, I'll be happy to use it. 

PipoCanaja

DO NOT DELETE THIS TEXT

#### Please note

> Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting.

- [X] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/)

#### Testers

If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
This commit is contained in:
PipoCanaja
2018-08-04 22:35:23 +02:00
committed by Neil Lathwood
parent 703e90fbc2
commit 2c91348c5c
2 changed files with 15 additions and 2 deletions

View File

@@ -55,7 +55,7 @@ if ($options['h']) {
}
}
$sql = 'SELECT * FROM `devices` AS D'
$sql = 'SELECT D.*,S.*,attrib_value 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;';
@@ -92,7 +92,7 @@ foreach (dbFetchRows($sql) as $service) {
log_event(
"Service check - {$service['service_desc']} ({$service['service_id']}) -
Skipping service check because device {$service['hostname']} is down due to icmp",
$device,
$service['device_id'],
'service',
4,
$service['service_id']