forked from Cacti/plugin_servcheck
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.php
More file actions
640 lines (536 loc) · 30.6 KB
/
setup.php
File metadata and controls
640 lines (536 loc) · 30.6 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
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2025 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/ |
+-------------------------------------------------------------------------+
*/
function plugin_servcheck_install () {
api_plugin_register_hook('servcheck', 'draw_navigation_text', 'plugin_servcheck_draw_navigation_text', 'setup.php');
api_plugin_register_hook('servcheck', 'config_arrays', 'plugin_servcheck_config_arrays', 'setup.php');
api_plugin_register_hook('servcheck', 'poller_bottom', 'plugin_servcheck_poller_bottom', 'setup.php');
api_plugin_register_hook('servcheck', 'replicate_out', 'servcheck_replicate_out', 'setup.php');
api_plugin_register_hook('servcheck', 'config_settings', 'servcheck_config_settings', 'setup.php');
api_plugin_register_realm('servcheck', 'servcheck_test.php,servcheck_restapi.php,servcheck_credential.php,servcheck_curl_code.php,servcheck_proxy.php,servcheck_ca.php', __('Service Check Admin', 'servcheck'), 1);
plugin_servcheck_setup_table();
}
function plugin_servcheck_uninstall () {
db_execute('DROP TABLE IF EXISTS plugin_servcheck_test');
db_execute('DROP TABLE IF EXISTS plugin_servcheck_log');
db_execute('DROP TABLE IF EXISTS plugin_servcheck_proxies');
db_execute('DROP TABLE IF EXISTS plugin_servcheck_proxy');
db_execute('DROP TABLE IF EXISTS plugin_servcheck_processes');
db_execute('DROP TABLE IF EXISTS plugin_servcheck_contacts');
db_execute('DROP TABLE IF EXISTS plugin_servcheck_ca');
db_execute('DROP TABLE IF EXISTS plugin_servcheck_restapi_method');
db_execute('DROP TABLE IF EXISTS plugin_servcheck_credential');
}
function plugin_servcheck_check_config () {
// Here we will check to ensure everything is configured
plugin_servcheck_upgrade();
return true;
}
function plugin_servcheck_upgrade() {
global $config;
require_once(__DIR__ . '/includes/functions.php');
$info = plugin_servcheck_version();
$new = $info['version'];
$old = db_fetch_cell('SELECT version FROM plugin_config WHERE directory="servcheck"');
db_execute_prepared('UPDATE plugin_realms
SET file = ?
WHERE file LIKE "%servcheck_test.php%"',
array('servcheck_test.php,servcheck_restapi.php,servcheck_credential.php,servcheck_curl_code.php,servcheck_proxy.php,servcheck_ca.php'));
api_plugin_register_hook('servcheck', 'replicate_out', 'servcheck_replicate_out', 'setup.php', '1');
api_plugin_register_hook('servcheck', 'config_settings', 'servcheck_config_settings', 'setup.php', '1');
if (cacti_version_compare($old, '0.3', '<')) {
if (!db_column_exists('plugin_servcheck_test', 'ipaddress')) {
db_add_column('plugin_servcheck_test', array('name' => 'ipaddress', 'type' => 'varchar(46)', 'NULL' => false, 'default' => '', 'after' => 'hostname'));
}
// 0.3 contains a lot of changes. I tried to convert old data but for sure make a backup
db_execute('DROP TABLE IF EXISTS plugin_servcheck_contacts');
db_execute('CREATE TABLE plugin_servcheck_test_backup AS SELECT * FROM plugin_servcheck_test');
db_execute('CREATE TABLE plugin_servcheck_log_backup AS SELECT * FROM plugin_servcheck_log');
db_execute('CREATE TABLE plugin_servcheck_proxies_backup AS SELECT * FROM plugin_servcheck_proxies');
if (db_table_exists('plugin_servcheck_restapi_method')) {
db_execute('CREATE TABLE plugin_servcheck_restapi_method_backup AS SELECT * FROM plugin_servcheck_restapi_method');
}
if (db_column_exists('plugin_servcheck_test', 'display_name')) {
db_execute('ALTER TABLE plugin_servcheck_test RENAME COLUMN display_name TO name');
}
if (db_column_exists('plugin_servcheck_test', 'ca')) {
db_execute('ALTER TABLE plugin_servcheck_test RENAME COLUMN ca TO ca_id');
}
if (db_column_exists('plugin_servcheck_test', 'proxy_server')) {
db_execute('ALTER TABLE plugin_servcheck_test RENAME COLUMN proxy_server TO proxy_id');
}
if (db_column_exists('plugin_servcheck_test', 'timeout_trigger')) {
db_execute('ALTER TABLE plugin_servcheck_test RENAME COLUMN timeout_trigger TO duration_trigger');
db_execute('ALTER TABLE plugin_servcheck_test MODIFY duration_trigger decimal(4,2) default "0"');
}
api_plugin_db_add_column('servcheck', 'plugin_servcheck_test', array('name' => 'duration_count', 'type' => 'int(3)', 'NULL' => false, 'unsigned' => true, 'default' => '3', 'after' => 'duration_trigger'));
api_plugin_db_add_column('servcheck', 'plugin_servcheck_test', array('name' => 'snmp_oid', 'type' => "varchar(255)", 'NULL' => false, 'default' => ''));
api_plugin_db_add_column('servcheck', 'plugin_servcheck_test', array('name' => 'ssh_command', 'type' => "varchar(255)", 'NULL' => false, 'default' => ''));
api_plugin_db_add_column('servcheck', 'plugin_servcheck_test', array('name' => 'cred_id', 'type' => 'int(11)', 'NULL' => false, 'unsigned' => true, 'default' => '0'));
api_plugin_db_add_column('servcheck', 'plugin_servcheck_test', array('name' => 'triggered_duration', 'type' => 'int(11)', 'NULL' => false, 'unsigned' => true, 'default' => '0'));
db_add_column('plugin_servcheck_test', array('name' => 'attempt', 'type' => 'int(2)', 'NULL' => false, 'default' => '3', 'after' => 'type'));
db_add_column('plugin_servcheck_test', array('name' => 'notify', 'type' => 'char(2)', 'NULL' => false, 'default' => 'on'));
db_execute('ALTER TABLE plugin_servcheck_log MODIFY curl_return_code int(3) default NULL');
db_execute('ALTER TABLE plugin_servcheck_log MODIFY cert_expire timestamp default "0000-00-00 00:00:00"');
db_add_column('plugin_servcheck_log', array('name' => 'attempt', 'type' => 'int(2)', 'NULL' => false, 'default' => '0', 'after' => 'lastcheck'));
$exist = db_fetch_cell("SELECT COUNT(*)
FROM information_schema.tables
WHERE table_schema = SCHEMA()
AND table_name = 'plugin_servcheck_proxies'");
if ($exist) {
db_execute('ALTER TABLE plugin_servcheck_proxies RENAME TO plugin_servcheck_proxy');
}
api_plugin_db_add_column('servcheck', 'plugin_servcheck_proxy', array('name' => 'cred_id', 'type' => 'int(11)', 'NULL' => false, 'unsigned' => true, 'default' => '0'));
$data = array();
$data['columns'][] = array('name' => 'id', 'type' => 'int(11)', 'NULL' => false, 'auto_increment' => true);
$data['columns'][] = array('name' => 'name', 'type' => 'varchar(100)', 'NULL' => true, 'default' => '');
$data['columns'][] = array('name' => 'type', 'type' => "enum('userpass','basic','apikey', 'oauth2', 'cookie', 'snmp','snmp3','sshkey')", 'NULL' => false, 'default' => 'userpass');
$data['columns'][] = array('name' => 'data', 'type' => 'text', 'NULL' => true, 'default' => '');
$data['primary'] = 'id';
$data['type'] = 'InnoDB';
$data['comment'] = 'Holds Credentials';
api_plugin_db_table_create('servcheck', 'plugin_servcheck_credential', $data);
// convert log data from 0.2 version
if (!db_column_exists('plugin_servcheck_log', 'duration')) {
api_plugin_db_add_column('servcheck', 'plugin_servcheck_log', array('name' => 'curl_response', 'type' => 'text', 'NULL' => true, 'default' => NULL));
api_plugin_db_add_column('servcheck', 'plugin_servcheck_log', array('name' => 'duration', 'type' => 'float', 'NULL' => false, 'default' => 0));
db_execute('UPDATE plugin_servcheck_log SET total_time = 0 WHERE total_time IS NULL');
db_execute('UPDATE plugin_servcheck_log SET duration = total_time');
db_execute("UPDATE plugin_servcheck_log SET curl_response = CONCAT(
'HTTP code: ', http_code, ', ',
'DNS time: ', ROUND(namelookup_time,3), ', ',
'Conn. time: ', ROUND(connect_time,3), ', ',
'Redir. time: ', ROUND(redirect_time,3), ', ',
'Redir. count: ', redirect_count, ', ',
'Download: ', ROUND(size_download,3), ', ',
'Speed: ', ROUND(speed_download,3), ', ',
'CURL code: ', curl_return_code
)");
db_remove_column('plugin_servcheck_log', 'http_code');
db_remove_column('plugin_servcheck_log', 'total_time');
db_remove_column('plugin_servcheck_log', 'namelookup_time');
db_remove_column('plugin_servcheck_log', 'connect_time');
db_remove_column('plugin_servcheck_log', 'redirect_time');
db_remove_column('plugin_servcheck_log', 'redirect_count');
db_remove_column('plugin_servcheck_log', 'size_download');
db_remove_column('plugin_servcheck_log', 'speed_download');
db_remove_column('plugin_servcheck_log', 'curl_return_code');
}
// convert credentials to separated tab
$records = db_fetch_assoc("SELECT * FROM plugin_servcheck_test
WHERE username != '' OR password !='' AND type != 'restapi'");
if (cacti_sizeof($records)) {
foreach ($records as $record) {
$cred = array();
$cred['type'] = 'userpass';
$cred['username'] = servcheck_show_text($record['username']);
$cred['password'] = servcheck_show_text($record['password']);
$enc = servcheck_encrypt_credential($cred);
db_execute_prepared('INSERT INTO plugin_servcheck_credential
(name, type, data) VALUES (?, ?, ?)',
array('upgrade/convert_test_' . $record['id'], $cred['type'], $enc));
db_execute_prepared('UPDATE plugin_servcheck_test
SET cred_id = ? WHERE id = ?',
array(db_fetch_insert_id(), $record['id']));
}
}
$records = db_fetch_assoc("SELECT * FROM plugin_servcheck_proxy WHERE username != '' OR password !=''");
if (cacti_sizeof($records)) {
foreach ($records as $record) {
$cred = array();
$cred['type'] = 'userpass';
$cred['username'] = $record['username'];
$cred['password'] = $record['password'];
$enc = servcheck_encrypt_credential($cred);
db_execute_prepared('INSERT INTO plugin_servcheck_credential
(name, type, data) VALUES (?, ?, ?)',
array('upgrade/convert_proxy_' . $record['id'], $cred['type'], $enc));
db_execute_prepared('UPDATE plugin_servcheck_proxy
SET cred_id = ? WHERE id = ?',
array(db_fetch_insert_id(), $record['id']));
}
}
if (db_table_exists('plugin_servcheck_restapi_method')) {
$records = db_fetch_assoc("SELECT * FROM plugin_servcheck_restapi_method");
if (cacti_sizeof($records)) {
foreach ($records as $record) {
if ($record['type'] == 'no') {
continue;
}
$cred = array();
if ($record['type'] == 'basic') {
$cred['type'] = 'basic';
$cred['username'] = servcheck_show_text($record['username']);
$cred['password'] = servcheck_show_text($record['password']);
$cred['data_url'] = $record['data_url'];
} elseif ($record['type'] == 'apikey') {
$cred['type'] = 'apikey';
$cred['option_apikey'] = 'post';
$cred['token_name'] = $record['username'];
$cred['data_url'] = $record['data_url'];
$cred['token_value'] = servcheck_show_text($record['cred_value']);
} elseif ($record['type'] == 'oauth2') {
$cred['type'] = 'oauth2';
$cred['oauth_client_id'] = servcheck_show_text($record['username']);
$cred['oauth_client_secret'] = servcheck_show_text($record['password']);
$cred['token_value'] = servcheck_show_text($record['cred_value']);
$cred['token_name'] = $record['cred_name'];
$cred['cred_valiedity'] = $record['cred_validity'];
$cred['data_url'] = $record['data_url'];
$cred['login_url'] = $record['login_url'];
} elseif ($record['type'] == 'cookie') {
$cred['type'] = 'cookie';
$cred['option_cookie'] = 'json';
$cred['username'] = servcheck_show_text($record['username']);
$cred['password'] = servcheck_show_text($record['password']);
$cred['data_url'] = $record['data_url'];
$cred['login_url'] = $record['login_url'];
}
$enc = servcheck_encrypt_credential($cred);
$test_id = db_fetch_cell_prepared ('SELECT id FROM plugin_servcheck_test
WHERE restapi_id = ? LIMIT 1',
array($record['id']));
db_execute_prepared('INSERT INTO plugin_servcheck_credential
(name, type, data) VALUES (?, ?, ?)',
array('upgrade/convert_restapi_' . $record['id'], $cred['type'], $enc));
db_execute_prepared('UPDATE plugin_servcheck_test
set type = ?, cred_id = ?
WHERE id = ?',
array('rest_' . $cred['type'], db_fetch_insert_id(), $test_id));
}
}
}
db_remove_column('plugin_servcheck_test', 'username');
db_remove_column('plugin_servcheck_test', 'password');
db_remove_column('plugin_servcheck_test', 'restapi_id');
db_remove_column('plugin_servcheck_proxy', 'username');
db_remove_column('plugin_servcheck_proxy', 'password');
// Set the new version
db_execute_prepared("UPDATE plugin_config
SET version = ?, author = ?, webpage = ?
WHERE directory = 'servcheck'",
array($info['version'], $info['author'], $info['homepage'])
);
}
return true;
}
function plugin_servcheck_version() {
global $config;
$info = parse_ini_file($config['base_path'] . '/plugins/servcheck/INFO', true);
return $info['info'];
}
function plugin_servcheck_setup_table() {
$data = array();
$data['columns'][] = array('name' => 'id', 'type' => 'int(11)', 'NULL' => false, 'auto_increment' => true);
$data['columns'][] = array('name' => 'type', 'type' => 'varchar(30)', 'NULL' => false, 'default' => 'web_http');
$data['columns'][] = array('name' => 'notify', 'type' => 'char(2)', 'NULL' => false, 'default' => 'on');
$data['columns'][] = array('name' => 'attempt', 'type' => 'int(2)', 'NULL' => false, 'default' => '3');
$data['columns'][] = array('name' => 'name', 'type' => 'varchar(64)', 'NULL' => false, 'default' => '');
$data['columns'][] = array('name' => 'poller_id', 'type' => 'int(11)', 'NULL' => false, 'unsigned' => true, 'default' => '1');
$data['columns'][] = array('name' => 'enabled', 'type' => 'varchar(2)', 'NULL' => false, 'default' => 'on');
$data['columns'][] = array('name' => 'hostname', 'type' => 'varchar(120)', 'NULL' => false, 'default' => '');
$data['columns'][] = array('name' => 'ipaddress', 'type' => 'varchar(46)', 'NULL' => false, 'default' => '');
$data['columns'][] = array('name' => 'path', 'type' => 'varchar(256)', 'NULL' => false);
$data['columns'][] = array('name' => 'dns_query', 'type' => 'varchar(100)', 'NULL' => false, 'default' => '');
$data['columns'][] = array('name' => 'ldapsearch', 'type' => 'varchar(200)', 'NULL' => false, 'default' => '');
$data['columns'][] = array('name' => 'snmp_oid', 'type' => "varchar(255)", 'NULL' => false, 'default' => '');
$data['columns'][] = array('name' => 'ssh_command', 'type' => "varchar(255)", 'NULL' => false, 'default' => '');
$data['columns'][] = array('name' => 'search', 'type' => 'varchar(1024)', 'NULL' => false);
$data['columns'][] = array('name' => 'search_maint', 'type' => 'varchar(1024)', 'NULL' => false);
$data['columns'][] = array('name' => 'search_failed', 'type' => 'varchar(1024)', 'NULL' => false);
$data['columns'][] = array('name' => 'requiresauth', 'type' => 'varchar(2)', 'NULL' => false, 'default' => '');
$data['columns'][] = array('name' => 'proxy_id', 'type' => 'int(11)', 'NULL' => false, 'unsigned' => true, 'default' => '0');
$data['columns'][] = array('name' => 'ca_id', 'type' => 'int(11)', 'NULL' => false, 'unsigned' => true, 'default' => '0');
$data['columns'][] = array('name' => 'checkcert', 'type' => 'char(2)', 'NULL' => false, 'default' => 'on');
$data['columns'][] = array('name' => 'certexpirenotify', 'type' => 'char(2)', 'NULL' => false, 'default' => 'on');
$data['columns'][] = array('name' => 'notify_list', 'type' => 'int(10)', 'NULL' => false, 'unsigned' => true, 'default' => '0');
$data['columns'][] = array('name' => 'notify_accounts', 'type' => 'varchar(256)', 'NULL' => false);
$data['columns'][] = array('name' => 'notify_extra', 'type' => 'varchar(256)', 'NULL' => false);
$data['columns'][] = array('name' => 'notify_format', 'type' => 'int(3)', 'NULL' => false, 'unsigned' => true, 'default' => '0');
$data['columns'][] = array('name' => 'notes', 'type' => 'text', 'NULL' => false, 'default' => '');
$data['columns'][] = array('name' => 'external_id', 'type' => 'varchar(20)', 'NULL' => false, 'default' => '');
$data['columns'][] = array('name' => 'how_often', 'type' => 'int(11)', 'NULL' => false, 'unsigned' => true, 'default' => '1');
$data['columns'][] = array('name' => 'downtrigger', 'type' => 'int(11)', 'NULL' => false, 'unsigned' => true, 'default' => '3');
$data['columns'][] = array('name' => 'duration_trigger', 'type' => 'decimal(4,2)', 'NULL' => false, 'unsigned' => true, 'default' => '0');
$data['columns'][] = array('name' => 'duration_count', 'type' => 'int(3)', 'NULL' => false, 'unsigned' => true, 'default' => '3');
$data['columns'][] = array('name' => 'stats_ok', 'type' => 'int(11)', 'NULL' => false, 'unsigned' => true, 'default' => '0');
$data['columns'][] = array('name' => 'stats_bad', 'type' => 'int(11)', 'NULL' => false, 'unsigned' => true, 'default' => '0');
$data['columns'][] = array('name' => 'failures', 'type' => 'int(11)', 'NULL' => false, 'unsigned' => true, 'default' => '0');
$data['columns'][] = array('name' => 'triggered', 'type' => 'int(11)', 'NULL' => false, 'unsigned' => true, 'default' => '0');
$data['columns'][] = array('name' => 'triggered_duration', 'type' => 'int(11)', 'NULL' => false, 'unsigned' => true, 'default' => '0');
$data['columns'][] = array('name' => 'lastcheck', 'type' => 'timestamp', 'NULL' => false, 'default' => '0000-00-00 00:00:00');
$data['columns'][] = array('name' => 'last_exp_notify', 'type' => 'timestamp', 'NULL' => false, 'default' => '0000-00-00 00:00:00');
$data['columns'][] = array('name' => 'last_returned_data', 'type' => 'blob', 'NULL' => true, 'default' => '');
$data['columns'][] = array('name' => 'cred_id', 'type' => 'int(11)', 'NULL' => false, 'unsigned' => true, 'default' => '0');
$data['primary'] = 'id';
$data['keys'][] = array('name' => 'lastcheck', 'columns' => 'lastcheck');
$data['keys'][] = array('name' => 'triggered', 'columns' => 'triggered');
$data['keys'][] = array('name' => 'enabled', 'columns' => 'enabled');
$data['type'] = 'InnoDB';
$data['comment'] = 'Holds servcheck Service Check Definitions';
api_plugin_db_table_create('servcheck', 'plugin_servcheck_test', $data);
$data = array();
$data['columns'][] = array('name' => 'id', 'type' => 'int(11)', 'NULL' => false, 'auto_increment' => true);
$data['columns'][] = array('name' => 'test_id', 'type' => 'int(11)', 'NULL' => false, 'unsigned' => true, 'default' => '0');
$data['columns'][] = array('name' => 'lastcheck', 'type' => 'timestamp', 'NULL' => false, 'default' => '0000-00-00 00:00:00');
$data['columns'][] = array('name' => 'attempt', 'type' => 'int(2)', 'NULL' => false, 'default' => '0');
$data['columns'][] = array('name' => 'result', 'type' => "enum('ok','not yet','error')", 'NULL' => false, 'default' => 'not yet');
$data['columns'][] = array('name' => 'result_search', 'type' => "enum('ok','not ok','failed ok','failed not ok', 'maint ok','not yet', 'not tested')", 'NULL' => false, 'default' => 'not yet');
$data['columns'][] = array('name' => 'curl_response', 'type' => 'text', 'NULL' => true, 'default' => NULL);
$data['columns'][] = array('name' => 'cert_expire', 'type' => 'timestamp', 'NULL' => false, 'default' => '0000-00-00 00:00:00');
$data['columns'][] = array('name' => 'error', 'type' => 'varchar(256)', 'NULL' => true, 'default' => 'NULL');
$data['columns'][] = array('name' => 'duration', 'type' => 'float', 'NULL' => false, 'default' => 0);
$data['primary'] = 'id';
$data['keys'][] = array('name' => 'test_id', 'columns' => 'test_id');
$data['keys'][] = array('name' => 'lastcheck', 'columns' => 'lastcheck');
$data['keys'][] = array('name' => 'result', 'columns' => 'result');
$data['type'] = 'InnoDB';
$data['comment'] = 'Holds servcheck Service Check Logs';
api_plugin_db_table_create('servcheck', 'plugin_servcheck_log', $data);
$data = array();
$data['columns'][] = array('name' => 'id', 'type' => 'bigint', 'NULL' => false, 'auto_increment' => true);
$data['columns'][] = array('name' => 'poller_id', 'type' => 'int(11)', 'NULL' => false, 'unsigned' => true, 'default' => '1');
$data['columns'][] = array('name' => 'test_id', 'type' => 'int(11)', 'NULL' => false, 'unsigned' => true);
$data['columns'][] = array('name' => 'pid', 'type' => 'int(11)', 'NULL' => false);
$data['columns'][] = array('name' => 'time', 'type' => 'timestamp', 'default' => 'CURRENT_TIMESTAMP', 'NULL' => false);
$data['primary'] = 'id';
$data['keys'][] = array('name' => 'pid', 'columns' => 'pid');
$data['keys'][] = array('name' => 'test_id', 'columns' => 'test_id');
$data['keys'][] = array('name' => 'time', 'columns' => 'time');
$data['type'] = 'InnoDB';
$data['comment'] = 'Holds running process information';
api_plugin_db_table_create('servcheck', 'plugin_servcheck_processes', $data);
$data = array();
$data['columns'][] = array('name' => 'id', 'type' => 'int(11)', 'NULL' => false, 'auto_increment' => true);
$data['columns'][] = array('name' => 'name', 'type' => 'varchar(30)', 'NULL' => true, 'default' => '');
$data['columns'][] = array('name' => 'hostname', 'type' => 'varchar(64)', 'NULL' => true, 'default' => '');
$data['columns'][] = array('name' => 'http_port', 'type' => 'mediumint(8)', 'NULL' => true, 'default' => '80');
$data['columns'][] = array('name' => 'https_port', 'type' => 'mediumint(8)', 'NULL' => true, 'default' => '443');
$data['columns'][] = array('name' => 'cred_id', 'type' => 'int(11)', 'NULL' => false, 'unsigned' => true, 'default' => '0');
$data['primary'] = 'id';
$data['keys'][] = array('name' => 'hostname', 'columns' => 'hostname');
$data['keys'][] = array('name' => 'name', 'columns' => 'name');
$data['type'] = 'InnoDB';
$data['comment'] = 'Holds Proxy Information for Connections';
api_plugin_db_table_create('servcheck', 'plugin_servcheck_proxy', $data);
$data = array();
$data['columns'][] = array('name' => 'id', 'type' => 'int(11)', 'NULL' => false, 'auto_increment' => true);
$data['columns'][] = array('name' => 'name', 'type' => 'varchar(100)', 'NULL' => false, 'default' => '');
$data['columns'][] = array('name' => 'cert', 'type' => 'text');
$data['primary'] = 'id';
$data['type'] = 'InnoDB';
$data['comment'] = 'Holds CA certificates';
api_plugin_db_table_create('servcheck', 'plugin_servcheck_ca', $data);
$data = array();
$data['columns'][] = array('name' => 'id', 'type' => 'int(11)', 'NULL' => false, 'auto_increment' => true);
$data['columns'][] = array('name' => 'name', 'type' => 'varchar(100)', 'NULL' => true, 'default' => '');
$data['columns'][] = array('name' => 'type', 'type' => "enum('userpass','basic','apikey', 'oauth2', 'cookie', 'snmp','snmp3','sshkey')", 'NULL' => false, 'default' => 'userpass');
$data['columns'][] = array('name' => 'data', 'type' => 'text', 'NULL' => true, 'default' => '');
$data['primary'] = 'id';
$data['type'] = 'InnoDB';
$data['comment'] = 'Holds Credentials';
api_plugin_db_table_create('servcheck', 'plugin_servcheck_credential', $data);
}
function plugin_servcheck_poller_bottom() {
global $config;
require_once($config['library_path'] . '/database.php');
$command_string = trim(read_config_option('path_php_binary'));
// If its not set, just assume its in the path
if (trim($command_string) == '')
$command_string = 'php';
$extra_args = ' -q ' . $config['base_path'] . '/plugins/servcheck/poller_servcheck.php';
exec_background($command_string, $extra_args);
}
function plugin_servcheck_config_arrays() {
global $menu, $user_auth_realms, $user_auth_realm_filenames;
$menu[__('Management')]['plugins/servcheck/servcheck_test.php'] = __('Service Checker', 'servcheck');
$files = array('index.php', 'plugins.php', 'servcheck_test.php');
if (in_array(get_current_page(), $files)) {
plugin_servcheck_check_config();
}
}
function plugin_servcheck_draw_navigation_text($nav) {
$nav['servcheck_test.php:'] = array(
'title' => __('Service Checks', 'servcheck'),
'mapping' => 'index.php:',
'url' => 'servcheck_test.php',
'level' => '1'
);
$nav['servcheck_test.php:edit'] = array(
'title' => __('Service Check Edit', 'servcheck'),
'mapping' => 'index.php:',
'url' => 'servcheck_test.php',
'level' => '1'
);
$nav['servcheck_test.php:save'] = array(
'title' => __('Service Check Save', 'servcheck'),
'mapping' => 'index.php:',
'url' => 'servcheck_test.php',
'level' => '1'
);
$nav['servcheck_restapi.php:'] = array(
'title' => __('Rest API', 'servcheck'),
'mapping' => 'index.php:',
'url' => 'servcheck_restapi.php',
'level' => '1'
);
$nav['servcheck_restapi.php:edit'] = array(
'title' => __('Rest API Edit', 'servcheck'),
'mapping' => 'index.php:',
'url' => 'servcheck_restapi.php',
'level' => '1'
);
$nav['servcheck_restapi.php:save'] = array(
'title' => __('Rest API Save', 'servcheck'),
'mapping' => 'index.php:',
'url' => 'servcheck_restapi.php',
'level' => '1'
);
$nav['servcheck_credential.php:'] = array(
'title' => __('Credential', 'servcheck'),
'mapping' => 'index.php:',
'url' => 'servcheck_credential.php',
'level' => '1'
);
$nav['servcheck_credential.php:edit'] = array(
'title' => __('Credential Edit', 'servcheck'),
'mapping' => 'index.php:',
'url' => 'servcheck_credential.php',
'level' => '1'
);
$nav['servcheck_credential.php:save'] = array(
'title' => __('Credential Save', 'servcheck'),
'mapping' => 'index.php:',
'url' => 'servcheck_credential.php',
'level' => '1'
);
$nav['servcheck_proxy.php:'] = array(
'title' => __('Web Proxy', 'servcheck'),
'mapping' => 'index.php:',
'url' => 'servcheck_proxy.php',
'level' => '1'
);
$nav['servcheck_proxy.php:edit'] = array(
'title' => __('Web Proxy Edit', 'servcheck'),
'mapping' => 'index.php:',
'url' => 'servcheck_proxy.php',
'level' => '1'
);
$nav['servcheck_proxy.php:save'] = array(
'title' => __('Save Web Proxy', 'servcheck'),
'mapping' => 'index.php:',
'url' => 'servcheck_proxy.php',
'level' => '1'
);
$nav['servcheck_ca.php:'] = array(
'title' => __('CA', 'servcheck'),
'mapping' => 'index.php:',
'url' => 'servcheck_ca.php',
'level' => '1'
);
$nav['servcheck_ca.php:edit'] = array(
'title' => __('CA Edit', 'servcheck'),
'mapping' => 'index.php:',
'url' => 'servcheck_ca.php',
'level' => '1'
);
$nav['servcheck_ca.php:save'] = array(
'title' => __('Save CA', 'servcheck'),
'mapping' => 'index.php:',
'url' => 'servcheck_ca.php',
'level' => '1'
);
return $nav;
}
function servcheck_replicate_out($data) {
$remote_poller_id = $data['remote_poller_id'];
$rcnn_id = $data['rcnn_id'];
$class = $data['class'];
cacti_log('INFO: Replicating for the servcheck Plugin', false, 'REPLICATE');
$tables = array(
'plugin_servcheck_proxy',
'plugin_servcheck_test',
'plugin_servcheck_credential',
'plugin_servcheck_ca',
'plugin_servcheck_restapi_method'
);
if ($class == 'all') {
foreach($tables as $table) {
$tdata = db_fetch_assoc('SELECT * FROM ' . $table);
replicate_out_table($rcnn_id, $tdata, $table, $remote_poller_id);
}
}
return $data;
}
function servcheck_config_settings() {
global $tabs, $settings;
$tabs['servcheck'] = __('Servcheck', 'servcheck');
$settings['servcheck'] = array(
'servcheck_display_header' => array(
'friendly_name' => __('Notification Preferences', 'servcheck'),
'method' => 'spacer',
),
'servcheck_send_email_separately' => array(
'friendly_name' => __('Send Email separately for each address', 'servcheck'),
'description' => __('If checked, this will cause all Emails to be sent separately for each address.', 'servcheck'),
'method' => 'checkbox',
'default' => '',
),
'servcheck_disable_notification' => array(
'friendly_name' => __('Stop sending all notification', 'servcheck'),
'description' => __('If checked, servcheck will not send any emails. You can also disable notification only for specific tests', 'servcheck'),
'method' => 'checkbox',
'default' => '',
),
'servcheck_enable_scripts' => array(
'friendly_name' => __('Enable Command Execution', 'servcheck'),
'description' => __('Checking this box will enable the ability to run commands on Servcheck events.', 'servcheck'),
'method' => 'checkbox',
'default' => ''
),
'servcheck_change_command' => array(
'friendly_name' => __('Status Change Command', 'servcheck'),
'description' => __('When a basic or search or certificate expiration test returns different result, run the following command... This command must NOT include command line arguments... However, the following variables can be pulled from the environment of the script:<br><SERVCHECK_TEST_NAME> <SERVCHECK_EXTERNAL_ID> <SERVCHECK_TEST_TYPE> <SERVCHECK_POLLER_ID> <SERVCHECK_RESULT> <SERVCHECK_RESULT_SEARCH> <SERVCHECK_CERTIFICATE_EXPIRATION>', 'servcheck'),
'method' => 'filepath',
'file_type' => 'binary',
'size' => '100',
'max_length' => '100',
'default' => ''
),
'servcheck_certificate_expiry_days' => array(
'friendly_name' => __('Certificate expiry date advanced notification email', 'servcheck'),
'description' => __('If SSL/TLS service certificate expiration is enabled, set how many days advanced notice period before certificate expiry date the system will send notification', 'sercheck'),
'method' => 'drop_array',
'array' => array(
'-1' => __('Disabled', 'servcheck'),
'3' => __('3 days in advance', 'servcheck'),
'7' => __('1 week in advance', 'servcheck'),
'21' => __('3 weeks in advance', 'servcheck'),
'30' => __('30 days in advance', 'servcheck'),
'60' => __('60 days in advance', 'servcheck'),
'90' => __('90 days in advance', 'servcheck'),
),
'default' => 7
),
);
}