|
44 | 44 |
|
45 | 45 | $debug = false; |
46 | 46 | $force = false; |
47 | | -$test_id = ''; |
| 47 | +$test_id = 0; |
48 | 48 |
|
49 | 49 | $poller_interval = read_config_option('poller_interval'); |
50 | 50 | $cert_expiry_days = read_config_option('servcheck_certificate_expiry_days'); |
|
62 | 62 |
|
63 | 63 | switch ($arg) { |
64 | 64 | case '--id': |
65 | | - $test_id = $value; |
| 65 | + $test_id = intval($value); |
66 | 66 | break; |
67 | 67 | case '-d': |
68 | 68 | case '--debug': |
|
84 | 84 | $force = true; |
85 | 85 | break; |
86 | 86 | default: |
87 | | - print 'ERROR: Invalid Parameter ' . $parameter . "\n\n"; |
| 87 | + print 'ERROR: Invalid Parameter ' . $parameter . PHP_EOL . PHP_EOL; |
88 | 88 | display_help(); |
89 | 89 | exit; |
90 | 90 | } |
91 | 91 | } |
92 | 92 | } |
93 | 93 |
|
94 | 94 | if (!function_exists('curl_init')) { |
95 | | - print "FATAL: You must install php-curl to use this Plugin" . PHP_EOL; |
| 95 | + print 'FATAL: You must install php-curl to use this Plugin' . PHP_EOL; |
96 | 96 | } |
97 | 97 |
|
98 | | -if (empty($test_id)) { |
99 | | - print "ERROR: You must specify a test id\n"; |
| 98 | +if (empty($test_id) || !is_int($test_id)) { |
| 99 | + print 'ERROR: You must specify a test id' . PHP_EOL; |
100 | 100 | exit(1); |
101 | 101 | } |
102 | 102 |
|
|
113 | 113 | WHERE id = ? ' . $enabled, |
114 | 114 | array(($poller_interval-10), $test_id)); |
115 | 115 |
|
116 | | - |
117 | 116 | if (!cacti_sizeof($test)) { |
118 | | - print "ERROR: Test not Found\n"; |
| 117 | + print 'ERROR: Test not Found' . PHP_EOL; |
119 | 118 | exit(1); |
120 | 119 | } |
121 | 120 |
|
122 | 121 | $poller = db_fetch_cell_prepared('SELECT * FROM poller WHERE id = ?', |
123 | 122 | array($test['poller_id'])); |
124 | 123 |
|
125 | 124 | if ($poller == false) { |
126 | | - print "Selected poller not found, changing to poller 1.\n"; |
| 125 | + print 'Selected poller not found, changing to poller 1' . PHP_EOL; |
127 | 126 | db_execute_prepared('UPDATE plugin_servcheck_test |
128 | 127 | SET poller_id = 1 |
129 | 128 | WHERE id = ?', |
|
186 | 185 |
|
187 | 186 | if (cacti_sizeof($results) == 0) { |
188 | 187 | plugin_servcheck_debug('Unknown error for test ' . $test['id'], $test); |
189 | | - exit('Unknown errof for test ' . $test['id']); |
| 188 | + exit('Unknown error for test ' . $test['id']); |
190 | 189 | } |
191 | 190 |
|
192 | 191 | plugin_servcheck_debug('failures:'. $test['stats_bad'] . ', triggered:' . $test['triggered'], $test); |
|
196 | 195 | if (isset($results['options']['certinfo'][0])) { |
197 | 196 | plugin_servcheck_debug('Returned certificate info: ' . clean_up_lines(var_export($results['options']['certinfo'], true)) , $test); |
198 | 197 |
|
199 | | - $parsed = date_parse_from_format("M j H:i:s Y e", $results['options']['certinfo'][0]['Expire date']); |
| 198 | + $parsed = date_parse_from_format('M j H:i:s Y e', $results['options']['certinfo'][0]['Expire date']); |
200 | 199 | $exp = mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $parsed['month'], $parsed['day'], $parsed['year']); |
201 | 200 | $test['days'] = round(($exp - time()) / 86400); |
202 | 201 | $test['expiry_date'] = $parsed['day'] . '. ' . $parsed['month'] . '. ' . $parsed['year']; |
|
205 | 204 |
|
206 | 205 | $test['status_change'] = false; |
207 | 206 |
|
208 | | -$last_log = db_fetch_row_prepared("SELECT * |
| 207 | +$last_log = db_fetch_row_prepared('SELECT * |
209 | 208 | FROM plugin_servcheck_log |
210 | | - WHERE test_id = ? ORDER BY id DESC LIMIT 1", |
| 209 | + WHERE test_id = ? ORDER BY id DESC LIMIT 1', |
211 | 210 | array ($test['id'])); |
212 | 211 |
|
213 | 212 | if (!$last_log) { |
|
221 | 220 | $test['stats_bad'] += 1; |
222 | 221 | } |
223 | 222 |
|
224 | | - |
225 | 223 | if ($last_log['result'] != $results['result'] || $last_log['result_search'] != $results['result_search'] || |
226 | 224 | ($test['certexpirenotify'] && $test_expiry_days > 0 && $test['days'] < $cert_expiry_days)) { |
227 | 225 |
|
228 | 226 | plugin_servcheck_debug('Checking for trigger', $test); |
229 | 227 |
|
230 | | - |
231 | 228 | $sendemail = false; |
232 | 229 |
|
233 | 230 | if ($results['result'] != 'ok') { |
|
241 | 238 | } |
242 | 239 |
|
243 | 240 | if ($results['result'] == 'ok') { |
244 | | - if ($test['failures'] == 0 && $test['triggered'] == 1) { |
| 241 | + if ($test['triggered'] == 1) { |
245 | 242 | $sendemail = true; |
246 | | - $test['triggered'] = 0; |
247 | 243 | $test['status_change'] = true; |
248 | | - $test['failures'] = 0; |
249 | 244 | } |
250 | | - } |
| 245 | + $test['triggered'] = 0; |
| 246 | + $test['failures'] = 0; |
| 247 | + |
251 | 248 |
|
| 249 | + } |
252 | 250 |
|
253 | 251 | if ($last_log['result_search'] != $results['result_search']) { |
254 | 252 | $sendemail = true; |
255 | 253 | } |
256 | 254 |
|
257 | | - |
258 | | - |
259 | 255 | if ($test['certexpirenotify'] && $cert_expiry_days > 0 && $test['days'] < $cert_expiry_days) { |
260 | 256 |
|
261 | 257 | // notify once per day |
|
272 | 268 | } |
273 | 269 | } |
274 | 270 |
|
275 | | - |
276 | | - |
277 | 271 | if ($sendemail) { |
278 | 272 | plugin_servcheck_debug('Time to send email', $test); |
279 | 273 |
|
|
311 | 305 | } |
312 | 306 | } else { |
313 | 307 | plugin_servcheck_debug('Not checking for trigger', $test); |
| 308 | + |
| 309 | + if ($results['result'] != 'ok') { |
| 310 | + $test['failures']++; |
| 311 | + $test['triggered'] = 1; |
| 312 | + } else { |
| 313 | + $test['triggered'] = 0; |
| 314 | + $test['failures'] = 0; |
| 315 | + } |
314 | 316 | } |
315 | 317 |
|
316 | 318 | plugin_servcheck_debug('Updating Statistics', $test); |
317 | 319 |
|
318 | | -db_execute_prepared("INSERT INTO plugin_servcheck_log |
| 320 | +db_execute_prepared('INSERT INTO plugin_servcheck_log |
319 | 321 | (test_id, lastcheck, cert_expire, result, http_code, error, |
320 | 322 | total_time, namelookup_time, connect_time, redirect_time, |
321 | 323 | redirect_count, size_download, speed_download, result_search, |
322 | 324 | curl_return_code) |
323 | | - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", |
| 325 | + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', |
324 | 326 | array($test['id'], date('Y-m-d H:i:s', $results['time']), date('Y-m-d H:i:s', $exp), |
325 | 327 | $results['result'], |
326 | 328 | $results['options']['http_code'], $results['error'], |
|
0 commit comments