forked from librenms/librenms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-errors.php
executable file
·59 lines (47 loc) · 1.55 KB
/
check-errors.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
#!/usr/bin/env php
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage alerts
* @author Adam Armstrong <[email protected]>
* @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';
require 'html/includes/functions.inc.php';
// Check all of our interface RRD files for errors
if ($argv[1]) {
$where = 'AND `port_id` = ?';
$params = array($argv[1]);
}
$i = 0;
$errored = 0;
foreach (dbFetchRows("SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id $where", $params) as $interface) {
$errors = ($interface['ifInErrors_delta'] + $interface['ifOutErrors_delta']);
if ($errors > '1') {
$errored[] = generate_device_link($interface, $interface['hostname'].' - '.$interface['ifDescr'].' - '.$interface['ifAlias'].' - '.$interface['ifInErrors_delta'].' - '.$interface['ifOutErrors_delta']);
$errored++;
}
$i++;
}
echo "Checked $i interfaces\n";
if (is_array($errored)) {
// If there are errored ports
$i = 0;
$msg = "Interfaces with errors : \n\n";
foreach ($errored as $int) {
$msg .= "$int\n";
// Add a line to the report email warning about them
$i++;
}
// Send the alert email
notify($device, $config['project_name']." detected errors on $i interface".($i != 1 ? 's' : ''), $msg);
}
echo "$errored interfaces with errors over the past 5 minutes.\n";