forked from Cacti/plugin_syslog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
syslog_batch_transfer.php
156 lines (129 loc) · 4.78 KB
/
syslog_batch_transfer.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
<?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/ |
+-------------------------------------------------------------------------+
*/
chdir('../../');
include('./include/cli_check.php');
include_once('./lib/poller.php');
include_once('./plugins/syslog/functions.php');
include_once('./plugins/syslog/database.php');
syslog_determine_config();
include(SYSLOG_CONFIG);
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;
$debug = true;
/* 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 '--version':
case '-V':
case '-v':
display_version();
exit;
case '--help':
case '-H':
case '-h':
display_help();
exit(0);
default:
echo "ERROR: Invalid Argument: ($arg)\n\n";
display_help();
exit(1);
}
}
}
/* record the start time */
$start_time = microtime(true);
/* Connect to the Syslog Database */
global $syslog_cnn, $cnn_id, $database_default;
if (empty($syslog_cnn)) {
if ((strtolower($database_hostname) == strtolower($syslogdb_hostname)) &&
($database_default == $syslogdb_default)) {
/* move on, using Cacti */
$syslog_cnn = $cnn_id;
}else{
if (!isset($syslogdb_port)) {
$syslogdb_port = '3306';
}
if (!isset($syslogdb_retries)) {
$syslogdb_retries = '5';
}
if (!isset($syslogdb_ssl)) {
$syslogdb_ssl = false;
}
if (!isset($syslogdb_ssl_key)) {
$syslogdb_ssl_key = '';
}
if (!isset($syslogdb_ssl_cert)) {
$syslogdb_ssl_cert = '';
}
if (!isset($syslogdb_ssl_ca)) {
$syslogdb_ssl_ca = '';
}
$syslog_cnn = syslog_db_connect_real($syslogdb_hostname, $syslogdb_username, $syslogdb_password, $syslogdb_default, $syslogdb_type, $syslogdb_port, $syslogdb_retries, $syslogdb_ssl, $syslogdb_ssl_key, $syslogdb_ssl_cert, $syslogdb_ssl_ca);
}
}
/* If Syslog Collection is Disabled, Exit Here */
if (read_config_option('syslog_enabled') == '') {
print "NOTE: Syslog record transferral and alerting/reporting is disabled. Exiting\n";
exit -1;
}
/* remove records that don't need to to be transferred */
syslog_debug('Syslog Batch Transfer / Remove Process started ...... ');
$syslog_items = syslog_manage_items('syslog', 'syslog_removed');
$syslog_removed = $syslog_items['removed'];
$syslog_xferred = $syslog_items['xferred'];
syslog_debug("Removed " . $syslog_removed . ", Message(s) from the 'syslog' table");
syslog_debug("Xferred " . $syslog_xferred . ", Message(s) to the 'syslog_removed' table");
syslog_debug('Finished processing...');
function display_version() {
global $config;
if (!function_exists('plugin_syslog_version')) {
include_once($config['base_path'] . '/plugins/syslog/setup.php');
}
$info = plugin_syslog_version();
echo "Syslog Batch Process, Version " . $info['version'] . ", " . COPYRIGHT_YEARS . "\n";
}
function display_help() {
display_version();
echo "\nusage: syslog_batch_transfer.php [--debug|-d]\n\n";
echo "The Syslog batch process script for Cacti Syslogging.\n";
echo "This script removes old messages from main view.\n";
}