forked from librenms/librenms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-services.php
executable file
·63 lines (54 loc) · 1.95 KB
/
check-services.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env php
<?php
/*
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage services
* @author Adam Armstrong <adama@memetic.org>
* @copyright (C) 2006 - 2012 Adam Armstrong
*/
chdir(dirname($argv[0]));
require 'includes/defaults.inc.php';
require 'config.php';
require 'includes/definitions.inc.php';
require 'includes/functions.php';
foreach (dbFetchRows('SELECT * FROM `devices` AS D, `services` AS S WHERE S.device_id = D.device_id ORDER by D.device_id DESC') as $service) {
if ($service['status'] = '1') {
unset($check, $service_status, $time, $status);
$service_status = $service['service_status'];
$service_type = strtolower($service['service_type']);
$service_param = $service['service_param'];
$checker_script = $config['install_dir'].'/includes/services/'.$service_type.'/check.inc';
if (is_file($checker_script)) {
include $checker_script;
}
else {
$cmd = $config['nagios_plugins'] . "/check_" . $service['service_type'] . " -H " . ($service['service_ip'] ? $service['service_ip'] : $service['hostname']);
$cmd .= " ".$service['service_param'];
$check = shell_exec($cmd);
list($check, $time) = split("\|", $check);
if(stristr($check, "ok -")) {
$status = 1;
}
else {
$status = 0;
}
}
$update = array();
if ($service_status != $status) {
$update['service_changed'] = time();
}
else {
unset($updated);
}
$update = array_merge(array('service_status' => $status, 'service_message' => $check, 'service_checked' => time()), $update);
dbUpdate($update, 'services', '`service_id` = ?', array($service['service_id']));
unset($update);
}
else {
$status = '0';
}//end if
} //end foreach