2010-09-03 18:26:59 +00:00
|
|
|
#!/usr/bin/env php
|
2007-06-24 16:07:03 +00:00
|
|
|
<?php
|
|
|
|
|
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 alerts
|
|
|
|
* @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-06-24 16:07:03 +00:00
|
|
|
include("config.php");
|
2012-05-09 10:01:42 +00:00
|
|
|
include("includes/definitions.inc.php");
|
2007-06-24 16:07:03 +00:00
|
|
|
include("includes/functions.php");
|
2012-02-03 18:37:00 +00:00
|
|
|
include("html/includes/functions.inc.php");
|
2007-06-24 16:07:03 +00:00
|
|
|
|
2012-05-25 12:24:34 +00:00
|
|
|
// Check all of our interface RRD files for errors
|
2008-03-17 22:31:05 +00:00
|
|
|
|
2012-05-16 13:25:50 +00:00
|
|
|
if ($argv[1]) { $where = "AND `port_id` = ?"; $params = array($argv[1]); }
|
2007-06-24 16:07:03 +00:00
|
|
|
|
2012-02-03 18:37:00 +00:00
|
|
|
$i = 0;
|
|
|
|
$errored = 0;
|
2009-10-12 09:48:40 +00:00
|
|
|
|
2011-05-13 11:42:26 +00:00
|
|
|
foreach (dbFetchRows("SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id $where", $params) as $interface)
|
2011-03-15 15:10:23 +00:00
|
|
|
{
|
2011-03-23 09:54:56 +00:00
|
|
|
$errors = $interface['ifInErrors_delta'] + $interface['ifOutErrors_delta'];
|
|
|
|
if ($errors > '1')
|
|
|
|
{
|
2012-02-03 18:37:00 +00:00
|
|
|
$errored[] = generate_device_link($interface, $interface['hostname'] . " - " . $interface['ifDescr'] . " - " . $interface['ifAlias'] . " - " . $interface['ifInErrors_delta'] . " - " . $interface['ifOutErrors_delta']);
|
|
|
|
$errored++;
|
2011-03-23 09:54:56 +00:00
|
|
|
}
|
|
|
|
$i++;
|
2008-03-12 16:21:13 +00:00
|
|
|
}
|
|
|
|
|
2012-02-03 18:37:00 +00:00
|
|
|
echo("Checked $i interfaces\n");
|
2008-03-17 22:31:05 +00:00
|
|
|
|
2012-02-03 18:37:00 +00:00
|
|
|
if (is_array($errored))
|
2012-05-25 12:24:34 +00:00
|
|
|
{ // If there are errored ports
|
2011-03-23 09:54:56 +00:00
|
|
|
$i = 0;
|
|
|
|
$msg = "Interfaces with errors : \n\n";
|
|
|
|
|
|
|
|
foreach ($errored as $int)
|
|
|
|
{
|
2012-05-25 12:24:34 +00:00
|
|
|
$msg .= "$int\n"; // Add a line to the report email warning about them
|
2011-03-23 09:54:56 +00:00
|
|
|
$i++;
|
|
|
|
}
|
2012-05-25 12:24:34 +00:00
|
|
|
// Send the alert email
|
2013-11-05 09:33:32 +10:00
|
|
|
notify($device, $config['project_name'] . " detected errors on $i interface" . ($i != 1 ? 's' : ''), $msg);
|
2007-06-24 16:07:03 +00:00
|
|
|
}
|
|
|
|
|
2012-02-03 18:37:00 +00:00
|
|
|
echo("$errored interfaces with errors over the past 5 minutes.\n");
|
|
|
|
|
2011-03-22 20:27:39 +00:00
|
|
|
?>
|