-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy paththold_notify.php
More file actions
213 lines (180 loc) · 5.86 KB
/
Copy paththold_notify.php
File metadata and controls
213 lines (180 loc) · 5.86 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
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
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 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/ |
+-------------------------------------------------------------------------+
*/
$notification_registered = false;
$pid = 0;
$thread = 1;
if (function_exists('pcntl_async_signals')) {
pcntl_async_signals(true);
} else {
declare(ticks = 100);
}
chdir(__DIR__);
chdir('../../');
require_once('./include/cli_check.php');
require_once($config['base_path'] . '/lib/rrd.php');
require($config['base_path'] . '/plugins/thold/includes/arrays.php');
require_once($config['base_path'] . '/plugins/thold/includes/functions.php');
require_once($config['library_path'] . '/snmp.php');
require_once($config['base_path'] . '/lib/time.php');
// install signal handlers for Linux/UNIX only
if (function_exists('pcntl_signal')) {
pcntl_signal(SIGTERM, 'sig_handler');
pcntl_signal(SIGINT, 'sig_handler');
}
// help with microtime(true)
// ini_set('precision', 16);
// process calling arguments
$parms = $_SERVER['argv'];
array_shift($parms);
$debug = false;
global $thread;
if (sizeof($parms)) {
foreach ($parms as $parameter) {
if (strpos($parameter, '=')) {
[$arg, $value] = explode('=', $parameter);
} else {
$arg = $parameter;
$value = '';
}
switch ($arg) {
case '-d':
case '--debug':
$debug = true;
break;
case '--thread':
if (!ctype_digit((string) $value) || (int) $value <= 0) {
print 'FATAL: The Thread ID must be numeric and greater than 0.' . PHP_EOL;
display_help();
exit(1);
}
cacti_log('WARNING: thold_notify.php --thread is deprecated and ignored; notification ownership is automatic.', false, 'THOLD');
break;
case '-v':
case '--version':
case '-V':
display_version();
exit;
case '--help':
case '-h':
case '-H':
display_help();
exit;
default:
print 'ERROR: Invalid Parameter ' . $parameter . "\n\n";
display_help();
exit(1);
}
}
}
thold_cli_debug('Thold Notification Main Collector Started');
$timeout = 3600;
if (!thold_notification_main($thread, $timeout)) {
exit(1);
}
exit(0);
/**
* sig_handler - provides a generic means to catch exceptions to the Cacti log.
*
* @param $signo - (int) the signal that was thrown by the interface.
*
* @returns - null
*/
function sig_handler($signo) {
global $thread;
switch ($signo) {
case SIGTERM:
case SIGINT:
thold_cacti_log('WARNING: Thold Daemon Notification Child Process with PID[' . getmypid() . '] terminated by user', $thread);
thold_notification_shutdown();
exit;
break;
default:
// ignore all other signals
}
}
/**
* Logs a debug message from the notification daemon to the Cacti log,
* only when global debug mode or the thold_daemon_debug setting is
* enabled.
*
* @param string $message The message to log.
* @param mixed $thread The worker thread identifier, passed through
* to thold_cacti_log() for log-line context.
*
* @return void
*
* @global bool $debug Whether debug output is enabled.
*/
function thold_daemon_debug($message, $thread) {
global $debug;
$daemon_debug = read_config_option('thold_daemon_debug');
if ($debug || $daemon_debug) {
thold_cacti_log($message, $thread);
}
}
/**
* Prints a timestamped debug message directly to stdout when global
* debug mode is enabled.
*
* @param string $string The message to print.
*
* @return void
*
* @global bool $debug Whether debug output is enabled.
*/
function thold_cli_debug($string) {
global $debug;
if ($debug) {
$output = date('Y-m-d H:i:s') . ' DEBUG: ' . trim($string);
print $output . PHP_EOL;
}
}
/**
* Prints this script's name, version, and copyright banner to stdout.
*
* @return void
*
* @global array $config Cacti global configuration array; used to
* locate setup.php when plugin_thold_version()
* isn't already loaded.
*/
function display_version() {
global $config;
if (!function_exists('plugin_thold_version')) {
include_once($config['base_path'] . '/plugins/thold/setup.php');
}
$info = plugin_thold_version();
print 'Threshold Notification Processor, Version ' . $info['version'] . ', ' . COPYRIGHT_YEARS . PHP_EOL;
}
/**
* Prints this script's version banner followed by its command-line
* usage instructions to stdout.
*
* @return void
*/
function display_help() {
display_version();
print PHP_EOL . 'usage: thold_notify.php [--thread=N] [--debug]' . PHP_EOL . PHP_EOL;
print 'The Threshold Notification Processor for the Thold Plugin.' . PHP_EOL;
}