-
Notifications
You must be signed in to change notification settings - Fork 36
/
setup.php
1107 lines (971 loc) · 38.6 KB
/
setup.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
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
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?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/ |
+-------------------------------------------------------------------------+
*/
function plugin_monitor_install() {
/* core plugin functionality */
api_plugin_register_hook('monitor', 'top_header_tabs', 'monitor_show_tab', 'setup.php');
api_plugin_register_hook('monitor', 'top_graph_header_tabs', 'monitor_show_tab', 'setup.php');
api_plugin_register_hook('monitor', 'top_graph_refresh', 'monitor_top_graph_refresh', 'setup.php');
api_plugin_register_hook('monitor', 'draw_navigation_text', 'monitor_draw_navigation_text', 'setup.php');
api_plugin_register_hook('monitor', 'config_form', 'monitor_config_form', 'setup.php');
api_plugin_register_hook('monitor', 'config_settings', 'monitor_config_settings', 'setup.php');
api_plugin_register_hook('monitor', 'config_arrays', 'monitor_config_arrays', 'setup.php');
api_plugin_register_hook('monitor', 'poller_bottom', 'monitor_poller_bottom', 'setup.php');
api_plugin_register_hook('monitor', 'page_head', 'plugin_monitor_page_head', 'setup.php');
/* device actions and interaction */
api_plugin_register_hook('monitor', 'api_device_save', 'monitor_api_device_save', 'setup.php');
api_plugin_register_hook('monitor', 'device_action_array', 'monitor_device_action_array', 'setup.php');
api_plugin_register_hook('monitor', 'device_action_execute', 'monitor_device_action_execute', 'setup.php');
api_plugin_register_hook('monitor', 'device_action_prepare', 'monitor_device_action_prepare', 'setup.php');
api_plugin_register_hook('monitor', 'device_remove', 'monitor_device_remove', 'setup.php');
/* add new filter for device */
api_plugin_register_hook('monitor', 'device_filters', 'monitor_device_filters', 'setup.php');
api_plugin_register_hook('monitor', 'device_sql_where', 'monitor_device_sql_where', 'setup.php');
api_plugin_register_hook('monitor', 'device_table_bottom', 'monitor_device_table_bottom', 'setup.php');
api_plugin_register_realm('monitor', 'monitor.php', 'View Monitoring Dashboard', 1);
set_config_option('monitor_view', 'default');
set_config_option('monitor_grouping', 'default');
set_config_option('monitor_trim', '4000');
monitor_setup_table();
}
function monitor_device_filters($filters) {
$criticalities = array(
'-1' => __('Any', 'monitor'),
'0' => __('None', 'monitor'),
'1' => __('Low', 'monitor'),
'2' => __('Medium', 'monitor'),
'3' => __('High', 'monitor'),
'4' => __('Mission Critical', 'monitor')
);
$filters['criticality'] = array(
'friendly_name' => __('Criticality', 'monitor'),
'method' => 'drop_array',
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
'array' => $criticalities,
'value' => '-1'
);
return $filters;
}
function monitor_device_sql_where($sql_where) {
if (get_request_var('criticality') >= 0) {
$sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . ' monitor_criticality = ' . get_request_var('criticality');
}
return $sql_where;
}
function monitor_device_table_bottom() {
$criticalities = array(
'-1' => __('Any', 'monitor'),
'0' => __('None', 'monitor'),
'1' => __('Low', 'monitor'),
'2' => __('Medium', 'monitor'),
'3' => __('High', 'monitor'),
'4' => __('Mission Critical', 'monitor')
);
if (version_compare(CACTI_VERSION, '1.3.0', '<')) {
$select = '<td>' . __('Criticality') . '</td><td><select id="criticality">';
foreach($criticalities as $index => $crit) {
if ($index == get_request_var('criticality')) {
$select .= '<option selected value="' . $index . '">' . $crit . '</option>';
} else {
$select .= '<option value="' . $index . '">' . $crit . '</option>';
}
}
$select .= '</select></td>';
?>
<script type='text/javascript'>
$(function() {
$('#rows').parent().after('<?php print $select;?>');
<?php if (get_selected_theme() != 'classic') {?>
$('#criticality').selectmenu({
change: function() {
applyFilter();
}
});
<?php } else { ?>
$('#criticality').change(function() {
applyFilter();
});
<?php } ?>
});
applyFilter = function() {
strURL = 'host.php';
strURL += '?host_status=' + $('#host_status').val();
if ($('#availability_method').length) {
strURL += '&availability_method=' + $('#availability_method').val();
}
strURL += '&host_template_id=' + $('#host_template_id').val();
strURL += '&site_id=' + $('#site_id').val();
strURL += '&criticality=' + $('#criticality').val();
strURL += '&poller_id=' + $('#poller_id').val();
strURL += '&location=' + $('#location').val();
strURL += '&rows=' + $('#rows').val();
strURL += '&filter=' + $('#filter').val();
strURL += '&header=false';
if (typeof loadUrl == 'undefined') {
loadPageNoHeader(strURL);
} else {
loadUrl({ url: strURL });
}
};
</script>
<?php
}
}
function plugin_monitor_uninstall() {
db_execute('DROP TABLE IF EXISTS plugin_monitor_notify_history');
db_execute('DROP TABLE IF EXISTS plugin_monitor_reboot_history');
db_execute('DROP TABLE IF EXISTS plugin_monitor_uptime');
}
function plugin_monitor_page_head() {
global $config;
print get_md5_include_css('plugins/monitor/monitor.css') . PHP_EOL;
if (file_exists($config['base_path'] . '/plugins/monitor/themes/' . get_selected_theme() . '/monitor.css')) {
print get_md5_include_css('plugins/monitor/themes/' . get_selected_theme() . '/monitor.css') . PHP_EOL;
}
}
function plugin_monitor_check_config() {
global $config;
// Here we will check to ensure everything is configured
monitor_check_upgrade();
include_once($config['library_path'] . '/database.php');
$r = read_config_option('monitor_refresh');
if ($r == '' || $r < 1 || $r > 300) {
set_config_option('monitor_refresh', '300');
}
return true;
}
function plugin_monitor_upgrade() {
// Here we will upgrade to the newest version
monitor_check_upgrade();
return false;
}
function monitor_check_upgrade() {
$files = array('plugins.php', 'monitor.php');
if (isset($_SERVER['PHP_SELF']) && !in_array(basename($_SERVER['PHP_SELF']), $files)) {
return;
}
$info = plugin_monitor_version();
$current = $info['version'];
$old = db_fetch_cell('SELECT version FROM plugin_config WHERE directory = "monitor"');
if ($current != $old) {
monitor_setup_table();
api_plugin_register_hook('monitor', 'page_head', 'plugin_monitor_page_head', 'setup.php', 1);
db_execute('ALTER TABLE host MODIFY COLUMN monitor char(3) DEFAULT "on"');
db_execute('ALTER TABLE plugin_monitor_uptime
MODIFY COLUMN uptime BIGINT unsigned NOT NULL default "0"');
api_plugin_db_add_column('monitor', 'host', array('name' => 'monitor_icon', 'type' => 'varchar(30)', 'NULL' => false, 'default' => '', 'after' => 'monitor_alert'));
if (function_exists('api_plugin_upgrade_register')) {
api_plugin_upgrade_register('monitor');
} else {
db_execute_prepared("UPDATE plugin_config
SET version = ?, name = ?, author = ?, webpage = ?
WHERE directory = ?",
array(
$info['version'],
$info['longname'],
$info['author'],
$info['homepage'],
$info['name']
)
);
}
}
}
function plugin_monitor_version() {
global $config;
$info = parse_ini_file($config['base_path'] . '/plugins/monitor/INFO', true);
return $info['info'];
}
function monitor_device_action_execute($action) {
global $config, $fields_host_edit;
if ($action != 'monitor_enable' && $action != 'monitor_disable' && $action != 'monitor_settings') {
return $action;
}
$selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
if ($selected_items != false) {
if ($action == 'monitor_enable' || $action == 'monitor_disable') {
for ($i = 0; ($i < count($selected_items)); $i++) {
if ($action == 'monitor_enable') {
db_execute_prepared('UPDATE host
SET monitor = "on"
WHERE deleted = ""
AND id = ?',
array($selected_items[$i]));
} else if ($action == 'monitor_disable') {
db_execute_prepared('UPDATE host
SET monitor = ""
WHERE deleted = ""
AND id = ?',
array($selected_items[$i]));
}
}
} else {
for ($i = 0; ($i < count($selected_items)); $i++) {
reset($fields_host_edit);
foreach($fields_host_edit as $field_name => $field_array) {
if (isset_request_var("t_$field_name")) {
if ($field_name == 'monitor_alert_baseline') {
$cur_time = db_fetch_cell_prepared('SELECT cur_time
FROM host
WHERE deleted = ""
AND id = ?',
array($selected_items[$i]));
if ($cur_time > 0) {
db_execute_prepared('UPDATE host
SET monitor_alert = CEIL(avg_time*?)
WHERE deleted = ""
AND id = ?',
array(get_nfilter_request_var($field_name), $selected_items[$i]));
}
} elseif ($field_name == 'monitor_warn_baseline') {
$cur_time = db_fetch_cell_prepared('SELECT cur_time
FROM host
WHERE deleted = ""
AND id = ?',
array($selected_items[$i]));
if ($cur_time > 0) {
db_execute_prepared('UPDATE host
SET monitor_warn = CEIL(avg_time*?)
WHERE deleted = ""
AND id = ?',
array(get_nfilter_request_var($field_name), $selected_items[$i]));
}
} else {
db_execute_prepared("UPDATE host
SET $field_name = ?
WHERE deleted=''
AND id = ?",
array(get_nfilter_request_var($field_name), $selected_items[$i]));
}
}
}
}
}
}
return $action;
}
function monitor_device_remove($devices) {
db_execute('DELETE FROM plugin_monitor_notify_history WHERE host_id IN(' . implode(',', $devices) . ')');
db_execute('DELETE FROM plugin_monitor_reboot_history WHERE host_id IN(' . implode(',', $devices) . ')');
db_execute('DELETE FROM plugin_monitor_uptime WHERE host_id IN(' . implode(',', $devices) . ')');
return $devices;
}
function monitor_device_action_prepare($save) {
global $host_list, $fields_host_edit;
if (!isset($save['drp_action'])) {
return $save;
} else {
$action = $save['drp_action'];
if ($action != 'monitor_enable' && $action != 'monitor_disable' && $action != 'monitor_settings') {
return $save;
}
if ($action == 'monitor_enable' || $action == 'monitor_disable') {
if ($action == 'monitor_enable') {
$action_description = 'enable';
} else if ($action == 'monitor_disable') {
$action_description = 'disable';
}
print "<tr>
<td colspan='2' class='even'>
<p>" . __('Click \'Continue\' to %s monitoring on these Device(s)', $action_description, 'monitor') . "</p>
<p><div class='itemlist'><ul>" . $save['host_list'] . "</ul></div></p>
</td>
</tr>";
} else {
print "<tr>
<td colspan='2' class='even'>
<p>" . __('Click \'Continue\' to Change the Monitoring settings for the following Device(s). Remember to check \'Update this Field\' to indicate which columns to update.', 'monitor') . "</p>
<p><div class='itemlist'><ul>" . $save['host_list'] . "</ul></div></p>
</td>
</tr>";
$form_array = array();
$fields = array(
'monitor',
'monitor_text',
'monitor_criticality',
'monitor_warn',
'monitor_alert',
'monitor_warn_baseline',
'monitor_alert_baseline',
'monitor_icon'
);
foreach($fields as $field) {
$form_array += array($field => $fields_host_edit[$field]);
$form_array[$field]['value'] = '';
$form_array[$field]['form_id'] = 0;
$form_array[$field]['sub_checkbox'] = array(
'name' => 't_' . $field,
'friendly_name' => __('Update this Field', 'monitor'),
'value' => ''
);
}
draw_edit_form(
array(
'config' => array('no_form_tag' => true),
'fields' => $form_array
)
);
}
return $save;
}
}
function monitor_device_action_array($device_action_array) {
$device_action_array['monitor_settings'] = __('Change Monitoring Options', 'monitor');
$device_action_array['monitor_enable'] = __('Enable Monitoring', 'monitor');
$device_action_array['monitor_disable'] = __('Disable Monitoring', 'monitor');
return $device_action_array;
}
function monitor_scan_dir() {
global $config;
$ext = array('.wav', '.mp3');
$d = dir($config['base_path'] . '/plugins/monitor/sounds/');
$files = array();
while (false !== ($entry = $d->read())) {
if ($entry != '.' && $entry != '..' && in_array(strtolower(substr($entry,-4)),$ext)) {
$files[$entry] = $entry;
}
}
$d->close();
asort($files); // sort the files
array_unshift($files, 'None'); // prepend the None option
return $files;
}
function monitor_config_settings() {
global $tabs, $formats, $settings, $criticalities, $page_refresh_interval, $config, $settings_user, $tabs_graphs;
include_once($config['base_path'] . '/lib/reports.php');
if (get_nfilter_request_var('tab') == 'monitor') {
$formats = reports_get_format_files();
} elseif (empty($formats)) {
$formats = array();
}
$criticalities = array(
0 => __('Disabled', 'monitor'),
1 => __('Low', 'monitor'),
2 => __('Medium', 'monitor'),
3 => __('High', 'monitor'),
4 => __('Mission Critical', 'monitor')
);
$log_retentions = array(
'-1' => __('Indefinitely', 'monitor'),
'31' => __('%d Month', 1, 'monitor'),
'62' => __('%d Months', 2, 'monitor'),
'93' => __('%d Months', 3, 'monitor'),
'124' => __('%d Months', 4, 'monitor'),
'186' => __('%d Months', 6, 'monitor'),
'365' => __('%d Year', 1, 'monitor')
);
$font_sizes = array(
'20' => '20px',
'30' => '30px',
'40' => '40px',
'50' => '50px',
'60' => '60px',
'70' => '70px'
);
if (function_exists('auth_augment_roles')) {
auth_augment_roles(__('Normal User'), array('monitor.php'));
}
$tabs_graphs += array('monitor' => __('Monitor Settings', 'monitor'));
$settings_user += array(
'monitor' => array(
'monitor_sound' => array(
'friendly_name' => __('Alarm Sound', 'monitor'),
'description' => __('This is the sound file that will be played when a Device goes down.', 'monitor'),
'method' => 'drop_array',
'array' => monitor_scan_dir(),
'default' => 'attn-noc.wav',
),
'monitor_sound_loop' => array(
'friendly_name' => __('Loop Alarm Sound', 'monitor'),
'description' => __('Play the above sound on a loop when a Device goes down.', 'monitor'),
'method' => 'checkbox',
),
'monitor_legend' => array(
'friendly_name' => __('Show Icon Legend', 'monitor'),
'description' => __('Check this to show an icon legend on the Monitor display', 'monitor'),
'method' => 'checkbox',
),
'monitor_uptime' => array(
'friendly_name' => __('Show Uptime', 'monitor'),
'description' => __('Check this to show Uptime on the Monitor display', 'monitor'),
'method' => 'checkbox',
),
'monitor_error_zoom' => array(
'friendly_name' => __('Zoom to Errors', 'monitor'),
'description' => __('Check this to zoom to errored items on the Monitor display', 'monitor'),
'method' => 'checkbox',
),
'monitor_error_background' => array(
'friendly_name' => __('Zoom Background', 'monitor'),
'description' => __('Background Color for Zoomed Errors on the Monitor display', 'monitor'),
'method' => 'drop_color',
),
'monitor_error_fontsize' => array(
'friendly_name' => __('Zoom Fontsize', 'monitor'),
'description' => __('Check this to zoom to errored items on the Monitor display', 'monitor'),
'method' => 'drop_array',
'default' => '50',
'array' => $font_sizes
)
)
);
if (get_current_page() != 'settings.php') {
return;
}
$tabs['monitor'] = __('Monitor', 'monitor');
$temp = array(
'monitor_header' => array(
'friendly_name' => __('Monitor Settings', 'monitor'),
'method' => 'spacer',
'collapsible' => 'true'
),
'monitor_new_enabled' => array(
'friendly_name' => __('Enable on new devices', 'monitor'),
'description' => __('Check this to automatically enable monitoring when creating new devices', 'monitor'),
'method' => 'checkbox',
),
'monitor_log_storage' => array(
'friendly_name' => __('Notification/Reboot Log Retention', 'monitor'),
'description' => __('Keep Notification and Reboot Logs for this number of days.', 'monitor'),
'method' => 'drop_array',
'default' => '31',
'array' => $log_retentions
),
'monitor_sound' => array(
'friendly_name' => __('Alarm Sound', 'monitor'),
'description' => __('This is the sound file that will be played when a Device goes down.', 'monitor'),
'method' => 'drop_array',
'array' => monitor_scan_dir(),
'default' => 'attn-noc.wav',
),
'monitor_sound_loop' => array(
'friendly_name' => __('Loop Alarm Sound', 'monitor'),
'description' => __('Play the above sound on a loop when a Device goes down.', 'monitor'),
'method' => 'checkbox',
),
'monitor_refresh' => array(
'friendly_name' => __('Refresh Interval', 'monitor'),
'description' => __('This is the time in seconds before the page refreshes. (1 - 300)', 'monitor'),
'method' => 'drop_array',
'default' => '60',
'array' => $page_refresh_interval
),
'monitor_legend' => array(
'friendly_name' => __('Show Icon Legend', 'monitor'),
'description' => __('Check this to show an icon legend on the Monitor display', 'monitor'),
'method' => 'checkbox',
),
'monitor_grouping' => array(
'friendly_name' => __('Grouping', 'monitor'),
'description' => __('This is how monitor will Group Devices.', 'monitor'),
'method' => 'drop_array',
'default' => 'default',
'array' => array(
'default' => __('Default', 'monitor'),
'default_by_permissions' => __('Default with permissions', 'monitor'),
'group_by_tree' => __('Tree', 'monitor'),
'group_by_device_template' => __('Device Template', 'monitor'),
)
),
'monitor_view' => array(
'friendly_name' => __('View', 'monitor'),
'description' => __('This is how monitor will render Devices.', 'monitor'),
'method' => 'drop_array',
'default' => 'default',
'array' => array(
'default' => __('Default', 'monitor'),
'list' => __('List', 'monitor'),
'tiles' => __('Tiles', 'monitor'),
'tilesadt' => __('Tiles & Downtime', 'monitor')
)
),
'monitor_format_header' => array(
'friendly_name' => __('Notification Report Format', 'monitor'),
'method' => 'spacer',
'collapsible' => 'true'
),
'monitor_format_file' => array(
'friendly_name' => __('Format File to Use', 'monitor'),
'method' => 'drop_array',
'default' => 'default.format',
'description' => __('Choose the custom html wrapper and CSS file to use. This file contains both html and CSS to wrap around your report. If it contains more than simply CSS, you need to place a special <REPORT> tag inside of the file. This format tag will be replaced by the report content. These files are located in the \'formats\' directory.', 'monitor'),
'array' => $formats
),
'monitor_threshold' => array(
'friendly_name' => __('Ping Threshold Notifications', 'monitor'),
'method' => 'spacer',
'collapsible' => 'true'
),
'monitor_warn_criticality' => array(
'friendly_name' => __('Warning Latency Notification', 'monitor'),
'description' => __('If a Device has a Round Trip Ping Latency above the Warning Threshold and above the Criticality below, subscribing emails to the Device will receive an email notification. Select \'Disabled\' to Disable. The Thold Plugin is required to enable this feature.', 'monitor'),
'method' => 'drop_array',
'default' => '0',
'array' => $criticalities
),
'monitor_alert_criticality' => array(
'friendly_name' => __('Alert Latency Notification', 'monitor'),
'description' => __('If a Device has a Round Trip Ping Latency above the Alert Threshold and above the Criticality below, subscribing emails to the Device will receive an email notification. Select \'Disabled\' to Disable. The Thold Plugin is required to enable this feature.', 'monitor'),
'method' => 'drop_array',
'default' => '0',
'array' => $criticalities
),
'monitor_resend_frequency' => array(
'friendly_name' => __('How Often to Resend Emails', 'monitor'),
'description' => __('How often should emails notifications be sent to subscribers for these Devices if they are exceeding their latency thresholds', 'monitor'),
'method' => 'drop_array',
'default' => '0',
'array' => array(
'0' => __('Every Occurrence', 'monitor'),
'20' => __('Every %d Minutes', 20, 'monitor'),
'30' => __('Every %d Minutes', 30, 'monitor'),
'60' => __('Every Hour', 'monitor'),
'120' => __('Every %d Hours', 2, 'monitor'),
'240' => __('Every %d Hours', 4, 'monitor')
)
),
'monitor_reboot' => array(
'friendly_name' => __('Reboot Notifications', 'monitor'),
'method' => 'spacer',
'collapsible' => 'true'
),
'monitor_reboot_notify' => array(
'friendly_name' => __('Send Reboot Notifications', 'monitor'),
'method' => 'checkbox',
'description' => __('Should Device Reboot Notifications be sent to users?', 'monitor'),
'default' => 'on',
),
'monitor_send_one_email' => array(
'friendly_name' => __('Send one Email to all addresses', 'monitor'),
'description' => __('If checked, the system will send one Email only to all addresses.', 'monitor'),
'method' => 'checkbox',
'default' => 'on'
),
'monitor_reboot_thold' => array(
'friendly_name' => __('Include Threshold Alert Lists', 'monitor'),
'method' => 'checkbox',
'description' => __('Should Threshold Alert Lists also receive Notification', 'monitor'),
'default' => 'on',
),
'monitor_subject' => array(
'friendly_name' => __('Subject', 'monitor'),
'description' => __('Enter a Reboot message subject for the Reboot Notification.', 'monitor'),
'method' => 'textbox',
'default' => __('Cacti Device Reboot Notification', 'monitor'),
'size' => 60,
'max_length' => 60
),
'monitor_body' => array(
'friendly_name' => __('Email Body', 'monitor'),
'description' => __('Enter an Email body to include in the Reboot Notification message. Currently, the only supported replacement tag accepted is <DETAILS>', 'monitor'),
'method' => 'textarea',
'textarea_rows' => 4,
'textarea_cols' => 80,
'default' => __('<h1>Monitor Reboot Notification</h1><p>The following Device\'s were Rebooted. See details below for additional information.</p><br><DETAILS>', 'monitor')
),
'monitor_email_header' => array(
'friendly_name' => __('Notification Email Addresses', 'monitor'),
'method' => 'spacer',
'collapsible' => 'true'
),
'monitor_fromname' => array(
'friendly_name' => __('From Name', 'monitor'),
'description' => __('Enter the Email Name to send the notifications from', 'monitor'),
'method' => 'textbox',
'size' => '60',
'max_length' => '255'
),
'monitor_fromemail' => array(
'friendly_name' => __('From Address', 'monitor'),
'description' => __('Enter the Email Address to send the notification from', 'monitor'),
'method' => 'textbox',
'size' => '60',
'max_length' => '255'
),
'monitor_list' => array(
'friendly_name' => __('Notification List', 'thold'),
'description' => __('Select a Notification List below. All Emails subscribed to the notification list will be notified.', 'thold'),
'method' => 'drop_sql',
'sql' => 'SELECT id, name FROM plugin_notification_lists ORDER BY name',
'default' => '',
'none_value' => __('None', 'monitor')
),
'monitor_emails' => array(
'friendly_name' => __('Email Addresses', 'monitor'),
'description' => __('Enter a comma delimited list of Email addresses to inform of a reboot event.', 'monitor'),
'method' => 'textarea',
'textarea_rows' => 2,
'textarea_cols' => 80,
'default' => ''
)
);
if (isset($settings['monitor'])) {
$settings['monitor'] = array_merge($settings['monitor'], $temp);
} else {
$settings['monitor'] = $temp;
}
}
function monitor_config_arrays() {
global $fa_icons;
$fa_icons = array(
'server' => array(
'display' => __('Server', 'monitor'),
'class' => 'fa fa-server deviceUp',
'style' => ''
),
'print' => array(
'display' => __('Printer', 'monitor'),
'class' => 'fa fa-print deviceUp',
'style' => ''
),
'desktop' => array(
'display' => __('Desktop PC', 'monitor'),
'class' => 'fa fa-desktop deviceUp',
'style' => ''
),
'laptop' => array(
'display' => __('Laptop/notebook', 'monitor'),
'class' => 'fa fa-laptop deviceUp',
'style' => ''
),
'wifi' => array(
'display' => __('Wifi', 'monitor'),
'class' => 'fa fa-wifi deviceUp',
'style' => ''
),
'network-wired' => array(
'display' => __('Wired network', 'monitor'),
'class' => 'fa fa-network-wired deviceUp',
'style' => ''
),
'database' => array(
'display' => __('Database', 'monitor'),
'class' => 'fa fa-database deviceUp',
'style' => ''
),
'clock' => array(
'display' => __('Clock', 'monitor'),
'class' => 'fa fa-clock deviceUp',
'style' => ''
),
'asterisk' => array(
'display' => __('Asterisk', 'monitor'),
'class' => 'fas fa-asterisk deviceUp',
'style' => ''
),
'hdd' => array(
'display' => __('Harddisk', 'monitor'),
'class' => 'fa fa-hdd deviceUp',
'style' => ''
),
'boxes' => array(
'display' => __('Boxes', 'monitor'),
'class' => 'fa fa-boxes deviceUp',
'style' => ''
),
'phone' => array(
'display' => __('Phone', 'monitor'),
'class' => 'fa fa-phone deviceUp',
'style' => ''
),
'cloud' => array(
'display' => __('Cloud', 'monitor'),
'class' => 'fa fa-cloud deviceUp',
'style' => ''
)
);
if (!function_exists('form_dropicon')) {
foreach($fa_icons as $key => $data) {
$nfa_icons[$key] = $data['display'];
}
$fa_icons = $nfa_icons;
}
monitor_check_upgrade();
}
function monitor_top_graph_refresh($refresh) {
if (get_current_page() != 'monitor.php') {
return $refresh;
}
$r = read_config_option('monitor_refresh');
if ($r == '' or $r < 1) {
return $refresh;
}
return $r;
}
function monitor_show_tab() {
global $config;
monitor_check_upgrade();
if (api_user_realm_auth('monitor.php')) {
if (substr_count($_SERVER['REQUEST_URI'], 'monitor.php')) {
print '<a href="' . $config['url_path'] . 'plugins/monitor/monitor.php"><img src="' . $config['url_path'] . 'plugins/monitor/images/tab_monitor_down.gif" alt="' . __('Monitor', 'monitor') . '"></a>';
} else {
print '<a href="' . $config['url_path'] . 'plugins/monitor/monitor.php"><img src="' . $config['url_path'] . 'plugins/monitor/images/tab_monitor.gif" alt="' . __('Monitor', 'monitor') . '"></a>';
}
}
}
function monitor_config_form() {
global $config, $fields_host_edit, $criticalities, $fa_icons;
$baselines = array(
'0' => __('Do not Change', 'monitor'),
'1.20' => __('%d Percent Above Average', 20, 'monitor'),
'1.30' => __('%d Percent Above Average', 30, 'monitor'),
'1.40' => __('%d Percent Above Average', 40, 'monitor'),
'1.50' => __('%d Percent Above Average', 50, 'monitor'),
'1.60' => __('%d Percent Above Average', 60, 'monitor'),
'1.70' => __('%d Percent Above Average', 70, 'monitor'),
'1.80' => __('%d Percent Above Average', 80, 'monitor'),
'1.90' => __('%d Percent Above Average', 90, 'monitor'),
'2.00' => __('%d Percent Above Average', 100, 'monitor'),
'2.20' => __('%d Percent Above Average', 120, 'monitor'),
'2.40' => __('%d Percent Above Average', 140, 'monitor'),
'2.50' => __('%d Percent Above Average', 150, 'monitor'),
'3.00' => __('%d Percent Above Average', 200, 'monitor'),
'4.00' => __('%d Percent Above Average', 300, 'monitor'),
'5.00' => __('%d Percent Above Average', 400, 'monitor'),
'6.00' => __('%d Percent Above Average', 500, 'monitor')
);
$fields_host_edit2 = $fields_host_edit;
$fields_host_edit3 = array();
foreach ($fields_host_edit2 as $f => $a) {
$fields_host_edit3[$f] = $a;
if ($f == 'disabled') {
$fields_host_edit3['monitor_header'] = array(
'friendly_name' => __('Device Monitoring Settings', 'monitor'),
'method' => 'spacer',
'collapsible' => 'true'
);
$fields_host_edit3['monitor'] = array(
'method' => 'checkbox',
'friendly_name' => __('Monitor Device', 'monitor'),
'description' => __('Check this box to monitor this Device on the Monitor Tab.', 'monitor'),
'value' => '|arg1:monitor|',
'form_id' => false
);
$host_id = get_nfilter_request_var('id');
if (empty($host_id) || !is_numeric($host_id)) {
$fields_host_edit3['monitor']['default'] = monitor_get_default($host_id);
}
$fields_host_edit3['monitor_criticality'] = array(
'friendly_name' => __('Device Criticality', 'monitor'),
'description' => __('What is the Criticality of this Device.', 'monitor'),
'method' => 'drop_array',
'array' => $criticalities,
'value' => '|arg1:monitor_criticality|',
'default' => '0',
);
$fields_host_edit3['monitor_warn'] = array(
'friendly_name' => __('Ping Warning Threshold', 'monitor'),
'description' => __('If the round-trip latency via any of the predefined Cacti ping methods raises above this threshold, log a warning or send email based upon the Devices Criticality and Monitor setting. The unit is in milliseconds. Setting to 0 disables. The Thold Plugin is required to leverage this functionality.', 'monitor'),
'method' => 'textbox',
'size' => '10',
'max_length' => '5',
'placeholder' => __('milliseconds', 'monitor'),
'value' => '|arg1:monitor_warn|',
'default' => '',
);
$fields_host_edit3['monitor_alert'] = array(
'friendly_name' => __('Ping Alert Threshold', 'monitor'),
'description' => __('If the round-trip latency via any of the predefined Cacti ping methods raises above this threshold, log an alert or send an email based upon the Devices Criticality and Monitor setting. The unit is in milliseconds. Setting to 0 disables. The Thold Plugin is required to leverage this functionality.', 'monitor'),
'method' => 'textbox',
'size' => '10',
'max_length' => '5',
'placeholder' => __('milliseconds', 'monitor'),
'value' => '|arg1:monitor_alert|',
'default' => '',
);
$fields_host_edit3['monitor_warn_baseline'] = array(
'friendly_name' => __('Re-Baseline Warning', 'monitor'),
'description' => __('The percentage above the current average ping time to consider a Warning Threshold. If updated, this will automatically adjust the Ping Warning Threshold.', 'monitor'),
'method' => 'drop_array',
'default' => '0',
'value' => '0',
'array' => $baselines
);
$fields_host_edit3['monitor_alert_baseline'] = array(
'friendly_name' => __('Re-Baseline Alert', 'monitor'),
'description' => __('The percentage above the current average ping time to consider a Alert Threshold. If updated, this will automatically adjust the Ping Alert Threshold.', 'monitor'),
'method' => 'drop_array',
'default' => '0',
'value' => '0',
'array' => $baselines
);
$fields_host_edit3['monitor_text'] = array(
'friendly_name' => __('Down Device Message', 'monitor'),
'description' => __('This is the message that will be displayed when this Device is reported as down.', 'monitor'),
'method' => 'textarea',
'max_length' => 1000,
'textarea_rows' => 2,
'textarea_cols' => 80,
'value' => '|arg1:monitor_text|',
'default' => '',
);
if (function_exists('form_dropicon')) {
$method = 'drop_icon';
} else {
$method = 'drop_array';
}
$fields_host_edit3['monitor_icon'] = array(
'friendly_name' => __('Device icon', 'monitor'),
'description' => __('You can select device icon.', 'monitor'),
'method' => $method,
'default' => '0',
'value' => '|arg1:monitor_icon|',
'array' => $fa_icons,
);
}
}
$fields_host_edit = $fields_host_edit3;
}
function monitor_get_default($host_id) {
$monitor_new_device = '';
if ($host_id <= 0) {
$monitor_new_device = read_config_option('monitor_new_enabled');
}
return $monitor_new_device;
}
function monitor_api_device_save($save) {
global $fa_icons;
$monitor_default = monitor_get_default($save['id']);
if (isset_request_var('monitor')) {
$save['monitor'] = form_input_validate(get_nfilter_request_var('monitor'), 'monitor', $monitor_default, true, 3);
} else {
$save['monitor'] = form_input_validate($monitor_default, 'monitor', '', true, 3);
}
if (isset_request_var('monitor_text')) {
$save['monitor_text'] = form_input_validate(get_nfilter_request_var('monitor_text'), 'monitor_text', '', true, 3);
} else {
$save['monitor_text'] = form_input_validate('', 'monitor_text', '', true, 3);
}
if (isset_request_var('monitor_criticality')) {
$save['monitor_criticality'] = form_input_validate(get_nfilter_request_var('monitor_criticality'), 'monitor_criticality', '^[0-9]+$', true, 3);
} else {
$save['monitor_criticality'] = form_input_validate('', 'monitor_criticality', '', true, 3);
}
if (isset_request_var('monitor_warn')) {
$save['monitor_warn'] = form_input_validate(get_nfilter_request_var('monitor_warn'), 'monitor_warn', '^[0-9]+$', true, 3);
} else {
$save['monitor_warn'] = form_input_validate('', 'monitor_warn', '', true, 3);
}
if (isset_request_var('monitor_alert')) {
$save['monitor_alert'] = form_input_validate(get_nfilter_request_var('monitor_alert'), 'monitor_alert', '^[0-9]+$', true, 3);
} else {
$save['monitor_alert'] = form_input_validate('', 'monitor_alert', '', true, 3);
}
if (isset_request_var('monitor_icon') && array_key_exists(get_nfilter_request_var('monitor_icon'), $fa_icons)) {
$save['monitor_icon'] = get_nfilter_request_var('monitor_icon');
} else {
$save['monitor_icon'] = '';
}
if (!isempty_request_var('monitor_alert_baseline') && !empty($save['id'])) {
$cur_time = db_fetch_cell_prepared('SELECT cur_time