-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathalerter.php
More file actions
executable file
·152 lines (119 loc) · 4.36 KB
/
Copy pathalerter.php
File metadata and controls
executable file
·152 lines (119 loc) · 4.36 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env php
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage cli
* @copyright (C) Adam Armstrong
*
*/
chdir(dirname($argv[0]));
$options = getopt("h:p:dqrsV");
include("includes/observium.inc.php");
include("includes/polling/functions.inc.php");
include("html/includes/functions.inc.php");
$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'] === "pollers") {
// Distributed pollers only (just placeholder as in poller)
if (OBS_DISTRIBUTED) {
//poll_pollers_distributed();
print_debug("Distribution pollers not require alerter.");
} elseif (OBSERVIUM_EDITION === 'community') {
print_debug("Distribution pollers not available in CE.");
} else {
print_debug("Distribution pollers not exist on install.");
}
exit(); // Silent exit
}
if (isset($options['h'])) {
$params = [];
switch ($options['h']) {
case 'odd':
case 'even':
case 'new':
case 'none':
// placeholder for hostname as in discovery
$doing = $options['h'];
break;
case 'all':
$where = ' ';
$doing = 'all';
break;
default:
if (is_numeric($options['h'])) {
$doing_single = TRUE; // Alert single device! (from wrapper)
$where = "AND `device_id` = ?";
$params[] = $options['h'];
$doing = $options['h'];
} elseif ($doing_single = (is_valid_hostname($options['h']) || get_ip_version($options['h']))) {
// Alert single device as hostname
$where = "AND `hostname` = ?";
$params[] = $options['h'];
$doing = $options['h'];
} else {
$where = "AND `hostname` LIKE ?";
$doing = $options['h'];
$params[] = str_replace('*', '%', $options['h']);
}
}
}
if (isset($options['p'])) {
print_cli_heading("%WConstrained to poller partition id " . $options['p']);
$where .= ' AND `poller_id` = ?';
$params[] = $options['p'];
}
if (!$where) {
print_message("%n
USAGE:
$scriptname [-drqV] [-p poller_id] [-h device]
EXAMPLE:
-h <device id> | <device hostname wildcard> Poll single device
-h all Poll all devices
-p <poller_id> Poll for specific poller_id
OPTIONS:
-h Device hostname, id or hostname or keys all.
-p Poller ID.
-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.
%rInvalid arguments!%n", 'color');
exit;
}
print_cli_heading("%WStarting alerter run at " . date("Y-m-d H:i:s"), 0);
$polled_devices = 0;
$alert_rules = cache_alert_rules();
$alert_assoc = cache_alert_assoc();
// Allow the URL building code to build URLs with proper links.
$_SESSION['userlevel'] = 10;
// FIXME. Not sure, should notifications will send on every node or on main node only?
//$where .= ' AND `poller_id` = ?';
//$params[] = $config['poller_id'];
$query = "SELECT * FROM `devices` WHERE `disabled` = 0 $where ORDER BY `device_id` ASC";
foreach (dbFetchRows($query, $params) as $device) {
humanize_device($device);
process_alerts($device);
if ($config['poller-wrapper']['notifications'] || $spam) {
process_notifications(['device_id' => $device['device_id']]); // Send all notifications (also for syslog from queue)
}
dbUpdate(['last_alerter' => ['NOW()']], 'devices', '`device_id` = ?', [$device['device_id']]);
}
print_cli_heading("%WFinished alerter run at " . date("Y-m-d H:i:s"), 0);
// EOF