-
Notifications
You must be signed in to change notification settings - Fork 91
/
alerter.php
executable file
·129 lines (100 loc) · 3.54 KB
/
alerter.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env php
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage poller
* @author Adam Armstrong <[email protected]>
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
*
*/
chdir(dirname($argv[0]));
$options = getopt("h:i:m:n:dqrsV");
include("includes/sql-config.inc.php");
include("includes/polling/functions.inc.php");
include("html/includes/functions.inc.php");
$scriptname = basename($argv[0]);
$start = utime();
if (isset($options['V']))
{
print_message(OBSERVIUM_PRODUCT." ".OBSERVIUM_VERSION);
exit;
}
if (isset($options['s']))
{
// User has asked for spam. LETS MAKE THE SPAM. (sends alerts even if they have already been sent)
$spam = TRUE;
}
if (!isset($options['q']))
{
print_cli_banner();
}
if ($options['h'] == "all") { $where = " "; $doing = "all"; }
elseif ($options['h'])
{
$params = array();
if (is_numeric($options['h']))
{
$where = "AND `device_id` = ?";
$doing = $options['h'];
$params[] = $options['h'];
}
else
{
$where = "AND `hostname` LIKE ?";
$doing = $options['h'];
$params[] = str_replace('*','%', $options['h']);
}
}
if (!$where)
{
print_message("%n
USAGE:
$scriptname [-drqV] [-i instances] [-n number] [-m module] [-h device]
EXAMPLE:
-h <device id> | <device hostname wildcard> Poll single device
-h odd Poll odd numbered devices (same as -i 2 -n 0)
-h even Poll even numbered devices (same as -i 2 -n 1)
-h all Poll all devices
-h new Poll all devices that have not had a discovery run before
-i <instances> -n <number> Poll as instance <number> of <instances>
Instances start at 0. 0-3 for -n 4
OPTIONS:
-h Device hostname, id or key odd/even/all/new.
-i Poll instance.
-n Poll number.
-s Sends alerts even if they have already been sent.
-q Quiet output.
-V Show version and exit.
DEBUGGING OPTIONS:
-r Do not create or update RRDs
-d Enable debugging output.
-dd More verbose debugging output.
-m Specify module(s) (separated by commas) to be run.
%rInvalid arguments!%n", 'color');
exit;
}
print_cli_heading("%WStarting discovery run at ".date("Y-m-d H:i:s"), 0);
$polled_devices = 0;
if (!isset($query))
{
$query = "SELECT `device_id` FROM `devices` WHERE `disabled` = 0 $where ORDER BY `device_id` ASC";
}
$alert_rules = cache_alert_rules();
$alert_assoc = cache_alert_assoc();
// Allow the URL building code to build URLs with proper links.
$_SESSION['userlevel'] = 10;
foreach (dbFetch($query, $params) as $device)
{
$device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device['device_id']));
humanize_device($device);
// Overwrite the autogenerated base_url with external_url when we can't guess.
## FIXME -- Do this automatically when we know we're not running in a webserver.
$config['base_url'] = $config['external_url'];
process_alerts($device);
}
print_cli_heading("%WFinished discovery run at ".date("Y-m-d H:i:s"), 0);
// EOF