-
Notifications
You must be signed in to change notification settings - Fork 1
/
check-services.php
executable file
·85 lines (71 loc) · 2.44 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env php
<?php
/**
* PanoptixNMS
*
* This file is part of PanoptixNMS.
*
* @package panoptixnms
* @subpackage services
* @author Adam Armstrong <adama@memetic.org>
* @copyright (C) 2006 - 2012 Adam Armstrong
*
*/
chdir(dirname($argv[0]));
include("includes/defaults.inc.php");
include("config.php");
include("includes/definitions.inc.php");
include("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
{
$status = "2";
$check = "Error : Script not found ($checker_script)";
}
$update = array();
if ($service_status != $status)
{
$update['service_changed'] = time();
if ($service['sysContact']) { $email = $service['sysContact']; } else { $email = $config['email_default']; }
if ($status == "1")
{
$msg = "Service Up: " . $service['service_type'] . " on " . $service['hostname'];
notify($device, "Service Up: " . $service['service_type'] . " on " . $service['hostname'], $msg);
}
elseif ($status == "0")
{
$msg = "Service Down: " . $service['service_type'] . " on " . $service['hostname'];
notify($device, "Service Down: " . $service['service_type'] . " on " . $service['hostname'], $msg);
}
} 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";
}
$rrd = $config['rrd_dir'] . "/" . $service['hostname'] . "/" . safename("service-" . $service['service_type'] . "-" . $service['service_id'] . ".rrd");
if (!is_file($rrd))
{
rrdtool_create ($rrd, "DS:status:GAUGE:600:0:1 ".$config['rrd_rra']);
}
if ($status == "1" || $status == "0")
{
rrdtool_update($rrd,"N:".$status);
} else {
rrdtool_update($rrd,"N:U");
}
} # while
?>