-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathsyslog_process.php
274 lines (235 loc) · 7.93 KB
/
syslog_process.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2024 The Cacti Group |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDTool-based Graphing Solution |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See |
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
include(dirname(__FILE__) . '/../../include/cli_check.php');
include_once(dirname(__FILE__) . '/functions.php');
include_once(dirname(__FILE__) . '/database.php');
syslog_connect();
/**
* Let it run for an hour if it has to, to clear up any big
* bursts of incoming syslog events
*/
ini_set('max_execution_time', 3600);
ini_set('memory_limit', '-1');
global $debug, $syslog_facilities, $syslog_levels;
$debug = false;
$forcer = false;
/* process calling arguments */
$parms = $_SERVER['argv'];
array_shift($parms);
if (cacti_sizeof($parms)) {
foreach($parms as $parameter) {
if (strpos($parameter, '=')) {
list($arg, $value) = explode('=', $parameter);
} else {
$arg = $parameter;
$value = '';
}
switch ($arg) {
case '--debug':
case '-d':
$debug = true;
break;
case '--force-report':
case '-F':
$forcer = true;
break;
case '--version':
case '-V':
case '-v':
display_version();
exit;
case '--help':
case '-H':
case '-h':
display_help();
exit;
default:
print "ERROR: Invalid Argument: ($arg)\n\n";
display_help();
exit(1);
}
}
}
/* record the start time */
$start_time = microtime(true);
/**
* sanity checks before starting. The first sanity check is
* to see if Syslog has been disabled entirely. If so, then
* exit right away.
*/
if (read_config_option('syslog_enabled') == '') {
$message = 'WARNING: Syslog record transferral and alerting/reporting is disabled.';
cacti_log($message, false, 'SYSLOG');
print $message . PHP_EOL;
exit(1);
}
/**
* sanity checks before starting. The second sanity check is to
* exit if you are a remote data collector and you have not enabled
* syslog to operate remotely. If you have been, then
* if the the rules replication is enabled, get the latest rules
* from the main Cacti data collector.
*/
if ($config['poller_id'] > 1) {
if (read_config_option('syslog_remote_enabled') !== 'on') {
$message = 'WARNING: Syslog is offline and Remote Data Collector Message Processing is disabled!';
cacti_log($message, false, 'SYSLOG', POLLER_VERBOSITY_MEDIUM);
print $message . PHP_EOL;
exit(1);
}
/* replicate in syslog tables sync is enabled */
syslog_replicate_in();
}
/**
* Register the start of the syslog process, or if it's found to still be
* running exit until such time as the syslog process times out.
*/
if (!register_process_start('syslog', 'master', $config['poller_id'], 1200)) {
exit(0);
}
/**
* initialize some key variables if they are not already initialized
* in the Cacti settings table.
*/
syslog_init_variables();
/**
* delete old syslog messages from the syslog table. This
* process may take some time. It's preferred that users
* always use partitioning as it will guarantee the best
* performing syslog database.
*/
syslog_debug('-------------------------------------------------------------------------------------');
if (!syslog_is_partitioned()) {
syslog_debug('Syslog Table is NOT Partitioned');
$deleted = syslog_traditional_manage();
} else {
syslog_debug('Syslog Table IS Partitioned');
$deleted = syslog_partition_manage();
}
syslog_debug('-------------------------------------------------------------------------------------');
/**
* pre-processing includes marking a uniqueID to be used
* in the processesing of alerts and stripping domains
* from hostnames in the case that the administrator
* chooses to strip them.
*/
$results = syslog_preprocess_incoming_records();
$uniqueID = $results['uniqueID'];
$incoming = $results['incoming'];
/**
* place new normalized values in various reference tables
* syslog attempts to normalize things like:
*
* - hostnames
* - facilities
* - priorities
* - programs
*
* To reduce the overall size of the syslog table over
* time and to speed up searching for these various
* columns in the database.
*/
syslog_update_reference_tables($uniqueID);
/**
* The statistics process allows the Cacti
* administrator to get some comprehension of flow
* into the syslog table and what message types are flowing
* into it.
*/
syslog_update_statistics($uniqueID);
/**
* remove records that don't need to to be transferred
*/
$results = syslog_remove_items('syslog_incoming', $uniqueID);
$removed = $results['removed'];
$xferred = $results['xferred'];
/**
* process the syslog rules and generate alerts
*/
$results = syslog_process_alerts($uniqueID);
$alerts = $results['syslog_alerts'];
$alarms = $results['syslog_alarms'];
/**
* Perform any plugin specific actions. Syslog itself does not use
* this information, but other 3rd party plugins may. This could
* be for performing certain maintenance functions that are not
* performed by syslog directly.
*/
api_plugin_hook('plugin_syslog_after_processing');
/**
* move records from incoming to syslog table and remove
* any stale records to to a poller crash
*/
$results = syslog_incoming_to_syslog($uniqueID);
$moved = $results['moved'];
$stale = $results['stale'];
/**
* process any syslog reports that are due to be
* sent.
*/
$results = syslog_process_reports();
$reports = $results['total_reports'];
$sentrpts = $results['sent_reports'];
/**
* prune and optimize any tables that are required to
* be optimized. This should be done once a day
*/
syslog_postprocess_tables();
/**
* log messages to the Cacti log and save statistics
* to the settings table
*/
syslog_process_log($start_time, $deleted, $incoming, $removed, $xferred, $alerts, $alarms, $reports);
/**
* unregister the syslog process entry so the next poller
* run can lock the process.
*/
unregister_process('syslog', 'master', $config['poller_id']);
exit(0);
/**
* display_version - displays version information
*
* @return (void)
*/
function display_version() {
global $config;
if (!function_exists('plugin_syslog_version')) {
include_once($config['base_path'] . '/plugins/syslog/setup.php');
}
$version = plugin_syslog_version();
print 'Syslog Poller, Version ' . trim($version['version']) . ', ' . COPYRIGHT_YEARS . PHP_EOL;
}
/**
* display_help - displays help information
*
* @return (void)
*/
function display_help() {
display_version();
print 'The main Syslog poller process script for Cacti Syslogging.' . PHP_EOL . PHP_EOL;
print 'usage: syslog_process.php [--debug] [--force-report]' . PHP_EOL . PHP_EOL;
print 'options:' . PHP_EOL;
print ' --force-report Send email reports now.' . PHP_EOL;
print ' --debug Provide more verbose debug output.' . PHP_EOL . PHP_EOL;
}