2010-09-03 18:26:59 +00:00
|
|
|
#!/usr/bin/env php
|
2007-04-03 14:10:23 +00:00
|
|
|
<?php
|
2012-04-06 15:19:43 +00:00
|
|
|
|
2012-05-09 10:01:42 +00:00
|
|
|
/**
|
2013-10-28 12:01:36 -07:00
|
|
|
* Observium
|
2012-05-09 10:01:42 +00:00
|
|
|
*
|
2013-10-28 12:01:36 -07:00
|
|
|
* This file is part of Observium.
|
2012-05-09 10:01:42 +00:00
|
|
|
*
|
2013-10-28 12:01:36 -07:00
|
|
|
* @package observium
|
|
|
|
* @subpackage services
|
|
|
|
* @author Adam Armstrong <adama@memetic.org>
|
|
|
|
* @copyright (C) 2006 - 2012 Adam Armstrong
|
2012-05-09 10:01:42 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-04-08 10:44:41 +00:00
|
|
|
chdir(dirname($argv[0]));
|
|
|
|
|
2010-02-27 14:44:38 +00:00
|
|
|
include("includes/defaults.inc.php");
|
2007-04-03 14:10:23 +00:00
|
|
|
include("config.php");
|
2012-05-09 10:01:42 +00:00
|
|
|
include("includes/definitions.inc.php");
|
2007-04-03 14:10:23 +00:00
|
|
|
include("includes/functions.php");
|
2011-03-12 08:50:47 +00:00
|
|
|
|
2011-05-13 11:42:26 +00:00
|
|
|
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)
|
2011-03-12 08:50:47 +00:00
|
|
|
{
|
2011-03-23 09:54:56 +00:00
|
|
|
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";
|
2007-04-03 14:10:23 +00:00
|
|
|
|
2011-03-23 09:54:56 +00:00
|
|
|
if (is_file($checker_script))
|
|
|
|
{
|
|
|
|
include($checker_script);
|
2011-03-22 20:27:39 +00:00
|
|
|
}
|
2011-03-23 09:54:56 +00:00
|
|
|
else
|
2011-03-22 20:27:39 +00:00
|
|
|
{
|
2011-03-23 09:54:56 +00:00
|
|
|
$status = "2";
|
|
|
|
$check = "Error : Script not found ($checker_script)";
|
2011-03-22 20:27:39 +00:00
|
|
|
}
|
|
|
|
|
2011-05-13 11:42:26 +00:00
|
|
|
$update = array();
|
|
|
|
|
2011-03-23 09:54:56 +00:00
|
|
|
if ($service_status != $status)
|
2011-03-22 20:27:39 +00:00
|
|
|
{
|
2011-05-13 11:42:26 +00:00
|
|
|
$update['service_changed'] = time();
|
2011-09-20 09:55:11 +00:00
|
|
|
|
2011-03-23 09:54:56 +00:00
|
|
|
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); }
|
|
|
|
|
2011-05-13 11:42:26 +00:00
|
|
|
$update = array_merge(array('service_status' => $status, 'service_message' => $check, 'service_checked' => time()), $update);
|
|
|
|
dbUpdate($update, 'services', '`service_id` = ?', array($service['service_id']));
|
2011-09-20 09:55:11 +00:00
|
|
|
unset($update);
|
2011-05-13 11:42:26 +00:00
|
|
|
|
2011-03-23 09:54:56 +00:00
|
|
|
} else {
|
|
|
|
$status = "0";
|
|
|
|
}
|
|
|
|
|
|
|
|
$rrd = $config['rrd_dir'] . "/" . $service['hostname'] . "/" . safename("service-" . $service['service_type'] . "-" . $service['service_id'] . ".rrd");
|
|
|
|
|
|
|
|
if (!is_file($rrd))
|
|
|
|
{
|
2012-04-26 13:05:52 +00:00
|
|
|
rrdtool_create ($rrd, "DS:status:GAUGE:600:0:1 ".$config['rrd_rra']);
|
2011-03-23 09:54:56 +00:00
|
|
|
}
|
|
|
|
if ($status == "1" || $status == "0")
|
|
|
|
{
|
|
|
|
rrdtool_update($rrd,"N:".$status);
|
2012-04-26 13:05:52 +00:00
|
|
|
} else {
|
|
|
|
rrdtool_update($rrd,"N:U");
|
2011-03-23 09:54:56 +00:00
|
|
|
}
|
2012-04-26 13:05:52 +00:00
|
|
|
|
2011-03-12 08:50:47 +00:00
|
|
|
} # while
|
2011-03-23 09:54:56 +00:00
|
|
|
|
2011-05-13 11:42:26 +00:00
|
|
|
?>
|