-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy paththold_templates.php
1485 lines (1311 loc) · 58 KB
/
thold_templates.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
/*
ex: set tabstop=4 shiftwidth=4 autoindent:
+-------------------------------------------------------------------------+
| Copyright (C) 2011 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_once('./include/auth.php');
include_once($config['base_path'] . '/plugins/thold/thold_functions.php');
$thold_actions = array(
1 => 'Export',
2 => 'Delete'
);
$action = '';
if (isset($_POST['action'])) {
$action = $_POST['action'];
} elseif (isset($_GET['action'])) {
$action = $_GET['action'];
}
if (isset($_POST['drp_action']) && $_POST['drp_action'] == 2) {
$action = 'delete';
}
if (isset($_POST['drp_action']) && $_POST['drp_action'] == 1) {
$action = 'export';
}
if (isset($_REQUEST['import'])) {
$action = 'import';
}
switch ($action) {
case 'add':
template_add();
break;
case 'save':
if (isset($_POST["save_component_import"])) {
template_import();
}elseif (isset($_POST['save']) && $_POST['save'] == 'edit') {
template_save_edit();
if (isset($_SESSION["graph_return"])) {
$return_to = $_SESSION["graph_return"];
unset($_SESSION["graph_return"]);
kill_session_var("graph_return");
header('Location: ' . $return_to);
}
} elseif (isset($_POST['save']) && $_POST['save'] == 'add') {
}
break;
case 'delete':
template_delete();
break;
case 'export':
template_export();
break;
case 'import':
include_once('./include/top_header.php');
import();
include_once('./include/bottom_footer.php');
break;
case 'edit':
include_once('./include/top_header.php');
template_edit();
include_once('./include/bottom_footer.php');
break;
default:
include_once('./include/top_header.php');
templates();
include_once('./include/bottom_footer.php');
break;
}
function template_export() {
$output = "<templates>\n";
if (sizeof($_POST)) {
foreach($_POST as $t=>$v) {
if (substr($t, 0,4) == 'chk_') {
$id = substr($t, 4);
if (is_numeric($id)) {
$data = db_fetch_row("SELECT * FROM thold_template WHERE id=$id");
if (sizeof($data)) {
$data_template_hash = db_fetch_cell("SELECT hash
FROM data_template
WHERE id=" . $data["data_template_id"]);
$data_source_hash = db_fetch_cell("SELECT hash
FROM data_template_rrd
WHERE id=" . $data["data_source_id"]);
unset($data['id']);
$data['data_template_id'] = $data_template_hash;
$data['data_source_id'] = $data_source_hash;
$output .= array2xml($data);
}
}
}
}
}
$output .= "</templates>";
header("Content-type: application/xml");
header("Content-Disposition: attachment; filename=thold_template_export.xml");
print $output;
exit;
}
function template_delete() {
foreach($_POST as $t=>$v) {
if (substr($t, 0,4) == 'chk_') {
$id = substr($t, 4);
input_validate_input_number($id);
plugin_thold_log_changes($id, 'deleted_template', array('id' => $id));
db_fetch_assoc("delete from thold_template where id = $id LIMIT 1");
db_execute('DELETE FROM plugin_thold_template_contact WHERE template_id=' . $id);
db_execute("UPDATE thold_data SET template = '', template_enabled = 'off' WHERE template = $id");
}
}
Header('Location: thold_templates.php');
exit;
}
function template_add() {
global $colors;
if ((!isset($_REQUEST['save'])) || ($_REQUEST['save'] == '')) {
$data_templates = array_rekey(db_fetch_assoc('select id, name from data_template order by name'), "id", "name");
include_once('./include/top_header.php');
?>
<script type="text/javascript">
<!--
function applyTholdFilterChange(objForm, type) {
if ((type == 'dt') && (document.getElementById("data_source_id"))) {
document.getElementById("data_source_id").value = "";
}
if (document.getElementById("save")) {
document.getElementById("save").value = "";
}
document.tholdform.submit();
}
-->
</script>
<?php
html_start_box('<strong>Threshold Template Creation Wizard</strong>', '50%', $colors['header'], '3', 'center', '');
print "<tr><td><form action=thold_templates.php method='post' name='tholdform'>";
if (!isset($_REQUEST["data_template_id"])) $_REQUEST["data_template_id"] = '';
if (!isset($_REQUEST["data_source_id"])) $_REQUEST["data_source_id"] = '';
if ($_REQUEST["data_template_id"] == '') {
print '<center><h3>Please select a Data Template</h3></center>';
} else if ($_REQUEST["data_source_id"] == '') {
print '<center><h3>Please select a Data Source</h3></center>';
} else {
print '<center><h3>Please press "Create" to create your Threshold Template</h3></center>';
}
/* display the data template dropdown */
?>
<table align='center'>
<tr>
<td width='70' style='white-space:nowrap;'>
<b>Data Template:</b>
</td>
<td style='width:1;'>
<select name=data_template_id onChange="applyTholdFilterChange(document.tholdform, 'dt')">
<option value="">None</option><?php
foreach ($data_templates as $id => $name) {
echo "<option value='" . $id . "'" . ($id == $_REQUEST['data_template_id'] ? ' selected' : '') . '>' . $name . '</option>';
}?>
</select>
</td>
</tr><?php
if ($_REQUEST['data_template_id'] != '') {
$data_template_id = $_REQUEST['data_template_id'];
$data_fields = array();
$temp = db_fetch_assoc('select id, local_data_template_rrd_id, data_source_name, data_input_field_id from data_template_rrd where local_data_template_rrd_id = 0 and data_template_id = ' . $data_template_id);
foreach ($temp as $d) {
if ($d['data_input_field_id'] != 0) {
$temp2 = db_fetch_assoc('select name, data_name from data_input_fields where id = ' . $d['data_input_field_id']);
$data_fields[$d['id']] = $temp2[0]['data_name'] . ' (' . $temp2[0]['name'] . ')';
} else {
$temp2[0]['name'] = $d['data_source_name'];
$data_fields[$d['id']] = $temp2[0]['name'];
}
}
/* display the data source dropdown */
?>
<tr>
<td width='70' style='white-space:nowrap;'>
<b>Data Source:</b>
</td>
<td>
<select id='data_source_id' name='data_source_id' onChange="applyTholdFilterChange(document.tholdform, 'ds')">
<option value="">None</option><?php
foreach ($data_fields as $id => $name) {
echo "<option value='" . $id . "'" . ($id == $_REQUEST['data_source_id'] ? ' selected' : '') . '>' . $name . '</option>';
}?>
</select>
</td>
</tr>
<?php
}
if ($_REQUEST["data_source_id"] != '') {
echo '<tr><td colspan=2><input type=hidden name=action value="add"><input id="save" type=hidden name="save" value="save"><br><center><input type="submit" value="Create"></center></td></tr>';
} else {
echo '<tr><td colspan=2><input type=hidden name=action value="add"><br><br><br></td></tr>';
}
echo '</table></form></td></tr>';
html_end_box();
include_once('./include/bottom_footer.php');
} else {
$data_template_id = $_REQUEST['data_template_id'];
$data_source_id = $_REQUEST['data_source_id'];
$save['id'] = '';
$save['hash'] = get_hash_thold_template(0);
$save['data_template_id'] = $data_template_id;
$temp = db_fetch_assoc('select id, name from data_template where id=' . $data_template_id);
$save['name'] = $temp[0]['name'];
$save['data_template_name'] = $temp[0]['name'];
$save['data_source_id'] = $data_source_id;
$temp = db_fetch_assoc('select id, local_data_template_rrd_id, data_source_name, data_input_field_id from data_template_rrd where id = ' . $data_source_id);
$save['data_source_name'] = $temp[0]['data_source_name'];
$save['name'] .= ' [' . $temp[0]['data_source_name'] . ']';
if ($temp[0]['data_input_field_id'] != 0) {
$temp2 = db_fetch_assoc('select name from data_input_fields where id = ' . $temp[0]['data_input_field_id']);
} else {
$temp2[0]['name'] = $temp[0]['data_source_name'];
}
$save['data_source_friendly'] = $temp2[0]['name'];
$save['thold_enabled'] = 'on';
$save['thold_type'] = 0;
$save['repeat_alert'] = read_config_option('alert_repeat');
$id = sql_save($save, 'thold_template');
if ($id) {
plugin_thold_log_changes($id, 'modified_template', $save);
Header("Location: thold_templates.php?action=edit&id=$id");
exit;
} else {
raise_message('thold_save');
Header('Location: thold_templates.php?action=add');
exit;
}
}
}
function template_save_edit() {
/* ================= input validation ================= */
input_validate_input_number(get_request_var_post('id'));
input_validate_input_number(get_request_var_post('thold_type'));
input_validate_input_number(get_request_var_post('thold_hi'));
input_validate_input_number(get_request_var_post('thold_low'));
input_validate_input_number(get_request_var_post('thold_fail_trigger'));
input_validate_input_number(get_request_var_post('time_hi'));
input_validate_input_number(get_request_var_post('time_low'));
input_validate_input_number(get_request_var_post('time_fail_trigger'));
input_validate_input_number(get_request_var_post('time_fail_length'));
input_validate_input_number(get_request_var_post('thold_warning_type'));
input_validate_input_number(get_request_var_post('thold_warning_hi'));
input_validate_input_number(get_request_var_post('thold_warning_low'));
input_validate_input_number(get_request_var_post('thold_warning_fail_trigger'));
input_validate_input_number(get_request_var_post('time_warning_hi'));
input_validate_input_number(get_request_var_post('time_warning_low'));
input_validate_input_number(get_request_var_post('time_warning_fail_trigger'));
input_validate_input_number(get_request_var_post('time_warning_fail_length'));
input_validate_input_number(get_request_var_post('bl_ref_time_range'));
input_validate_input_number(get_request_var_post('bl_pct_down'));
input_validate_input_number(get_request_var_post('bl_pct_up'));
input_validate_input_number(get_request_var_post('bl_fail_trigger'));
input_validate_input_number(get_request_var_post('repeat_alert'));
input_validate_input_number(get_request_var_post('data_type'));
input_validate_input_number(get_request_var_post('cdef'));
input_validate_input_number(get_request_var_post('notify_warning'));
input_validate_input_number(get_request_var_post('notify_alert'));
/* ==================================================== */
/* clean up date1 string */
if (isset($_POST['name'])) {
$_POST['name'] = trim(str_replace(array("\\", "'", '"'), '', get_request_var_post('name')));
}
/* save: data_template */
$save['id'] = $_POST['id'];
$save['hash'] = get_hash_thold_template($save['id']);
$save['name'] = $_POST['name'];
$save['thold_type'] = $_POST['thold_type'];
// High / Low
$save['thold_hi'] = $_POST['thold_hi'];
$save['thold_low'] = $_POST['thold_low'];
$save['thold_fail_trigger'] = $_POST['thold_fail_trigger'];
// Time Based
$save['time_hi'] = $_POST['time_hi'];
$save['time_low'] = $_POST['time_low'];
$save['time_fail_trigger'] = $_POST['time_fail_trigger'];
$save['time_fail_length'] = $_POST['time_fail_length'];
if (isset($_POST['thold_fail_trigger']) && $_POST['thold_fail_trigger'] != '') {
$save['thold_fail_trigger'] = $_POST['thold_fail_trigger'];
} else {
$alert_trigger = read_config_option('alert_trigger');
if ($alert_trigger != '' && is_numeric($alert_trigger)) {
$save['thold_fail_trigger'] = $alert_trigger;
} else {
$save['thold_fail_trigger'] = 5;
}
}
/*** Warnings ***/
// High / Low Warnings
$save['thold_warning_hi'] = $_POST['thold_warning_hi'];
$save['thold_warning_low'] = $_POST['thold_warning_low'];
$save['thold_warning_fail_trigger'] = $_POST['thold_warning_fail_trigger'];
// Time Based Warnings
$save['time_warning_hi'] = $_POST['time_warning_hi'];
$save['time_warning_low'] = $_POST['time_warning_low'];
$save['time_warning_fail_trigger'] = $_POST['time_warning_fail_trigger'];
$save['time_warning_fail_length'] = $_POST['time_warning_fail_length'];
if (isset($_POST['thold_warning_fail_trigger']) && $_POST['thold_warning_fail_trigger'] != '') {
$save['thold_warning_fail_trigger'] = $_POST['thold_warning_fail_trigger'];
} else {
$alert_trigger = read_config_option('alert_trigger');
if ($alert_trigger != '' && is_numeric($alert_trigger)) {
$save['thold_warning_fail_trigger'] = $alert_trigger;
} else {
$save['thold_warning_fail_trigger'] = 5;
}
}
if (isset($_POST['thold_enabled'])) {
$save['thold_enabled'] = 'on';
} else {
$save['thold_enabled'] = 'off';
}
if (isset($_POST['exempt'])) {
$save['exempt'] = 'on';
} else {
$save['exempt'] = 'off';
}
if (isset($_POST['restored_alert'])) {
$save['restored_alert'] = 'on';
} else {
$save['restored_alert'] = 'off';
}
if (isset($_POST['bl_ref_time_range']) && $_POST['bl_ref_time_range'] != '') {
$save['bl_ref_time_range'] = $_POST['bl_ref_time_range'];
} else {
$alert_bl_timerange_def = read_config_option('alert_bl_timerange_def');
if ($alert_bl_timerange_def != '' && is_numeric($alert_bl_timerange_def)) {
$save['bl_ref_time_range'] = $alert_bl_timerange_def;
} else {
$save['bl_ref_time_range'] = 10800;
}
}
$save['bl_pct_down'] = $_POST['bl_pct_down'];
$save['bl_pct_up'] = $_POST['bl_pct_up'];
if (isset($_POST['bl_fail_trigger']) && $_POST['bl_fail_trigger'] != '') {
$save['bl_fail_trigger'] = $_POST['bl_fail_trigger'];
} else {
$alert_bl_trigger = read_config_option('alert_bl_trigger');
if ($alert_bl_trigger != '' && is_numeric($alert_bl_trigger)) {
$save['bl_fail_trigger'] = $alert_bl_trigger;
} else {
$save['bl_fail_trigger'] = 3;
}
}
if (isset($_POST['repeat_alert']) && $_POST['repeat_alert'] != '') {
$save['repeat_alert'] = $_POST['repeat_alert'];
} else {
$alert_repeat = read_config_option('alert_repeat');
if ($alert_repeat != '' && is_numeric($alert_repeat)) {
$save['repeat_alert'] = $alert_repeat;
} else {
$save['repeat_alert'] = 12;
}
}
$save['notify_extra'] = $_POST['notify_extra'];
$save['notify_warning_extra'] = $_POST['notify_warning_extra'];
$save['notify_warning'] = $_POST['notify_warning'];
$save['notify_alert'] = $_POST['notify_alert'];
$save['cdef'] = $_POST['cdef'];
$save['data_type'] = $_POST['data_type'];
$save['percent_ds'] = $_POST['percent_ds'];
$save['expression'] = $_POST['expression'];
if (!is_error_message()) {
$id = sql_save($save, 'thold_template');
if ($id) {
raise_message(1);
if (isset($_POST['notify_accounts']) && is_array($_POST['notify_accounts'])) {
thold_save_template_contacts ($id, $_POST['notify_accounts']);
} elseif (!isset($_POST['notify_accounts'])) {
thold_save_template_contacts ($id, array());
}
thold_template_update_thresholds ($id);
plugin_thold_log_changes($id, 'modified_template', $save);
} else {
raise_message(2);
}
}
if ((is_error_message()) || (empty($_POST['id']))) {
header('Location: thold_templates.php?action=edit&id=' . (empty($id) ? $_POST['id'] : $id));
} else {
header('Location: thold_templates.php');
}
}
function template_edit() {
global $colors;
/* ================= input validation ================= */
input_validate_input_number(get_request_var('id'));
/* ==================================================== */
$id = $_GET['id'];
$thold_item_data = db_fetch_assoc('SELECT * FROM thold_template WHERE id=' . $id);
$thold_item_data = count($thold_item_data) > 0 ? $thold_item_data[0] : $thold_item_data;
$temp = db_fetch_assoc('SELECT id, name FROM data_template WHERE id=' . $thold_item_data['data_template_id']);
foreach ($temp as $d) {
$data_templates[$d['id']] = $d['name'];
}
$temp = db_fetch_assoc('SELECT id, data_source_name, data_input_field_id
FROM data_template_rrd
WHERE id=' . $thold_item_data['data_source_id']);
$source_id = $temp[0]['data_input_field_id'];
if ($source_id != 0) {
$temp2 = db_fetch_assoc('SELECT id, name FROM data_input_fields WHERE id=' . $source_id);
foreach ($temp2 as $d) {
$data_fields[$d['id']] = $d['name'];
}
} else {
$data_fields[$temp[0]['id']]= $temp[0]['data_source_name'];
}
$send_notification_array = array();
$users = db_fetch_assoc("SELECT plugin_thold_contacts.id, plugin_thold_contacts.data,
plugin_thold_contacts.type, user_auth.full_name
FROM plugin_thold_contacts, user_auth
WHERE user_auth.id=plugin_thold_contacts.user_id
AND plugin_thold_contacts.data!=''
ORDER BY user_auth.full_name ASC, plugin_thold_contacts.type ASC");
if (!empty($users)) {
foreach ($users as $user) {
$send_notification_array[$user['id']] = $user['full_name'] . ' - ' . ucfirst($user['type']);
}
}
if (isset($thold_item_data['id'])) {
$sql = 'SELECT contact_id as id FROM plugin_thold_template_contact WHERE template_id=' . $thold_item_data['id'];
} else {
$sql = 'SELECT contact_id as id FROM plugin_thold_template_contact WHERE template_id=0';
}
$step = db_fetch_cell('SELECT rrd_step FROM data_template_data WHERE data_template_id = ' . $thold_item_data['data_template_id'], FALSE);
if ($step == 60) {
$repeatarray = array(0 => 'Never', 1 => 'Every Minute', 2 => 'Every 2 Minutes', 3 => 'Every 3 Minutes', 4 => 'Every 4 Minutes', 5 => 'Every 5 Minutes', 10 => 'Every 10 Minutes', 15 => 'Every 15 Minutes', 20 => 'Every 20 Minutes', 30 => 'Every 30 Minutes', 45 => 'Every 45 Minutes', 60 => 'Every Hour', 120 => 'Every 2 Hours', 180 => 'Every 3 Hours', 240 => 'Every 4 Hours', 360 => 'Every 6 Hours', 480 => 'Every 8 Hours', 720 => 'Every 12 Hours', 1440 => 'Every Day', 2880 => 'Every 2 Days', 10080 => 'Every Week', 20160 => 'Every 2 Weeks', 43200 => 'Every Month');
$alertarray = array(0 => 'Never', 1 => '1 Minute', 2 => '2 Minutes', 3 => '3 Minutes', 4 => '4 Minutes', 5 => '5 Minutes', 10 => '10 Minutes', 15 => '15 Minutes', 20 => '20 Minutes', 30 => '30 Minutes', 45 => '45 Minutes', 60 => '1 Hour', 120 => '2 Hours', 180 => '3 Hours', 240 => '4 Hours', 360 => '6 Hours', 480 => '8 Hours', 720 => '12 Hours', 1440 => '1 Day', 2880 => '2 Days', 10080 => '1 Week', 20160 => '2 Weeks', 43200 => '1 Month');
$timearray = array(1 => '1 Minute', 2 => '2 Minutes', 3 => '3 Minutes', 4 => '4 Minutes', 5 => '5 Minutes', 6 => '6 Minutes', 7 => '7 Minutes', 8 => '8 Minutes', 9 => '9 Minutes', 10 => '10 Minutes', 12 => '12 Minutes', 15 => '15 Minutes', 20 => '20 Minutes', 24 => '24 Minutes', 30 => '30 Minutes', 45 => '45 Minutes', 60 => '1 Hour', 120 => '2 Hours', 180 => '3 Hours', 240 => '4 Hours', 288 => '4.8 Hours', 360 => '6 Hours', 480 => '8 Hours', 720 => '12 Hours', 1440 => '1 Day', 2880 => '2 Days', 10080 => '1 Week', 20160 => '2 Weeks', 43200 => '1 Month');
} else if ($step == 300) {
$repeatarray = array(0 => 'Never', 1 => 'Every 5 Minutes', 2 => 'Every 10 Minutes', 3 => 'Every 15 Minutes', 4 => 'Every 20 Minutes', 6 => 'Every 30 Minutes', 8 => 'Every 45 Minutes', 12 => 'Every Hour', 24 => 'Every 2 Hours', 36 => 'Every 3 Hours', 48 => 'Every 4 Hours', 72 => 'Every 6 Hours', 96 => 'Every 8 Hours', 144 => 'Every 12 Hours', 288 => 'Every Day', 576 => 'Every 2 Days', 2016 => 'Every Week', 4032 => 'Every 2 Weeks', 8640 => 'Every Month');
$alertarray = array(0 => 'Never', 1 => '5 Minutes', 2 => '10 Minutes', 3 => '15 Minutes', 4 => '20 Minutes', 6 => '30 Minutes', 8 => '45 Minutes', 12 => '1 Hour', 24 => '2 Hours', 36 => '3 Hours', 48 => '4 Hours', 72 => '6 Hours', 96 => '8 Hours', 144 => '12 Hours', 288 => '1 Day', 576 => '2 Days', 2016 => '1 Week', 4032 => '2 Weeks', 8640 => '1 Month');
$timearray = array(1 => '5 Minutes', 2 => '10 Minutes', 3 => '15 Minutes', 4 => '20 Minutes', 6 => '30 Minutes', 8 => '45 Minutes', 12 => '1 Hour', 24 => '2 Hours', 36 => '3 Hours', 48 => '4 Hours', 72 => '6 Hours', 96 => '8 Hours', 144 => '12 Hours', 288 => '1 Day', 576 => '2 Days', 2016 => '1 Week', 4032 => '2 Weeks', 8640 => '1 Month');
} else {
$repeatarray = array(0 => 'Never', 1 => 'Every Polling', 2 => 'Every 2 Pollings', 3 => 'Every 3 Pollings', 4 => 'Every 4 Pollings', 6 => 'Every 6 Pollings', 8 => 'Every 8 Pollings', 12 => 'Every 12 Pollings', 24 => 'Every 24 Pollings', 36 => 'Every 36 Pollings', 48 => 'Every 48 Pollings', 72 => 'Every 72 Pollings', 96 => 'Every 96 Pollings', 144 => 'Every 144 Pollings', 288 => 'Every 288 Pollings', 576 => 'Every 576 Pollings', 2016 => 'Every 2016 Pollings');
$alertarray = array(0 => 'Never', 1 => '1 Polling', 2 => '2 Pollings', 3 => '3 Pollings', 4 => '4 Pollings', 6 => '6 Pollings', 8 => '8 Pollings', 12 => '12 Pollings', 24 => '24 Pollings', 36 => '36 Pollings', 48 => '48 Pollings', 72 => '72 Pollings', 96 => '96 Pollings', 144 => '144 Pollings', 288 => '288 Pollings', 576 => '576 Pollings', 2016 => '2016 Pollings');
$timearray = array(1 => '1 Polling', 2 => '2 Pollings', 3 => '3 Pollings', 4 => '4 Pollings', 6 => '6 Pollings', 8 => '8 Pollings', 12 => '12 Pollings', 24 => '24 Pollings', 36 => '36 Pollings', 48 => '48 Pollings', 72 => '72 Pollings', 96 => '96 Pollings', 144 => '144 Pollings', 288 => '288 Pollings', 576 => '576 Pollings', 2016 => '2016 Pollings');
}
$thold_types = array (
0 => 'High / Low Values',
1 => 'Baseline Deviation',
2 => 'Time Based',
);
$data_types = array (
0 => 'Exact Value',
1 => 'CDEF',
2 => 'Percentage',
3 => 'RPN Expression'
);
$rra_steps = db_fetch_assoc("SELECT rra.steps
FROM data_template_data d
JOIN data_template_data_rra a
ON d.id=a.data_template_data_id
JOIN rra
ON a.rra_id=rra.id
WHERE rra.steps>1
AND d.data_template_id=" . $thold_item_data['data_template_id'] . "
AND d.local_data_template_data_id=0
ORDER BY steps");
$reference_types = array();
foreach($rra_steps as $rra_step) {
$seconds = $step * $rra_step['steps'];
$reference_types[$seconds] = $timearray[$rra_step['steps']] . " Average" ;
}
$data_fields2 = array();
$temp = db_fetch_assoc('SELECT id, local_data_template_rrd_id, data_source_name,
data_input_field_id
FROM data_template_rrd
WHERE local_data_template_rrd_id=0
AND data_template_id=' . $thold_item_data['data_template_id']);
foreach ($temp as $d) {
if ($d['data_input_field_id'] != 0) {
$temp2 = db_fetch_assoc('SELECT id, name, data_name
FROM data_input_fields
WHERE id=' . $d['data_input_field_id'] . '
ORDER BY data_name');
$data_fields2[$d['data_source_name']] = $temp2[0]['data_name'] . ' (' . $temp2[0]['name'] . ')';
} else {
$temp2[0]['name'] = $d['data_source_name'];
$data_fields2[$d['data_source_name']] = $temp2[0]['name'];
}
}
$replacements = db_fetch_assoc("SELECT DISTINCT field_name
FROM data_local AS dl
INNER JOIN (SELECT DISTINCT field_name, snmp_query_id FROM host_snmp_cache) AS hsc
ON dl.snmp_query_id=hsc.snmp_query_id
WHERE dl.data_template_id=" . $thold_item_data['data_template_id']);
$nr = array();
if (sizeof($replacements)) {
foreach($replacements as $r) {
$nr[] = "<span style='color:blue;'>|query_" . $r['field_name'] . "|</span>";
}
}
$vhf = explode("|", trim(VALID_HOST_FIELDS, "()"));
if (sizeof($vhf)) {
foreach($vhf as $r) {
$nr[] = "<span style='color:blue;'>|" . $r . "|</span>";
}
}
$replacements = "<br><b>Replacement Fields:</b> " . implode(", ", $nr);
$dss = db_fetch_assoc("SELECT data_source_name FROM data_template_rrd WHERE data_template_id=" . $thold_item_data['data_template_id'] . " AND local_data_id=0");
if (sizeof($dss)) {
foreach($dss as $ds) {
$dsname[] = "<span style='color:blue;'>|ds:" . $ds["data_source_name"] . "|</span>";
}
}
$datasources = "<br><b>Data Sources:</b> " . implode(", ", $dsname);
print "<form name='THold' action='thold_templates.php' method='post'>\n";
html_start_box('', '100%', $colors['header'], '3', 'center', '');
$form_array = array(
'general_header' => array(
'friendly_name' => 'Mandatory settings',
'method' => 'spacer',
),
'name' => array(
'friendly_name' => 'Template Name',
'method' => 'textbox',
'max_length' => 100,
'default' => $thold_item_data['data_template_name'] . ' [' . $thold_item_data['data_source_name'] . ']',
'description' => 'Provide the THold Template a meaningful name. Host Substritution and Data Query Substitution variables can be used as well as |graph_title| for the Graph Title',
'value' => isset($thold_item_data['name']) ? $thold_item_data['name'] : ''
),
'data_template_name' => array(
'friendly_name' => 'Data Template',
'method' => 'drop_array',
'default' => 'NULL',
'description' => 'Data Template that you are using. (This can not be changed)',
'value' => $thold_item_data['data_template_id'],
'array' => $data_templates,
),
'data_field_name' => array(
'friendly_name' => 'Data Field',
'method' => 'drop_array',
'default' => 'NULL',
'description' => 'Data Field that you are using. (This can not be changed)',
'value' => $thold_item_data['id'],
'array' => $data_fields,
),
'thold_enabled' => array(
'friendly_name' => 'Enabled',
'method' => 'checkbox',
'default' => 'on',
'description' => 'Whether or not this threshold will be checked and alerted upon.',
'value' => isset($thold_item_data['thold_enabled']) ? $thold_item_data['thold_enabled'] : ''
),
'exempt' => array(
'friendly_name' => 'Weekend Exemption',
'description' => 'If this is checked, this Threshold will not alert on weekends.',
'method' => 'checkbox',
'default' => 'off',
'value' => isset($thold_item_data['exempt']) ? $thold_item_data['exempt'] : ''
),
'restored_alert' => array(
'friendly_name' => 'Disable Restoration Email',
'description' => 'If this is checked, Thold will not send an alert when the threshold has returned to normal status.',
'method' => 'checkbox',
'default' => 'off',
'value' => isset($thold_item_data['restored_alert']) ? $thold_item_data['restored_alert'] : ''
),
'thold_type' => array(
'friendly_name' => 'Threshold Type',
'method' => 'drop_array',
'on_change' => 'changeTholdType()',
'array' => $thold_types,
'default' => read_config_option('thold_type'),
'description' => 'The type of Threshold that will be monitored.',
'value' => isset($thold_item_data['thold_type']) ? $thold_item_data['thold_type'] : ''
),
'repeat_alert' => array(
'friendly_name' => 'Re-Alert Cycle',
'method' => 'drop_array',
'array' => $repeatarray,
'default' => read_config_option('alert_repeat'),
'description' => 'Repeat alert after this amount of time has pasted since the last alert.',
'value' => isset($thold_item_data['repeat_alert']) ? $thold_item_data['repeat_alert'] : ''
),
'thold_warning_header' => array(
'friendly_name' => 'High / Low Warning Settings',
'method' => 'spacer',
),
'thold_warning_hi' => array(
'friendly_name' => 'High Warning Threshold',
'method' => 'textbox',
'max_length' => 100,
'size' => 10,
'description' => 'If set and data source value goes above this number, alert will be triggered',
'value' => isset($thold_item_data['thold_warning_hi']) ? $thold_item_data['thold_warning_hi'] : ''
),
'thold_warning_low' => array(
'friendly_name' => 'Low Warning Threshold',
'method' => 'textbox',
'max_length' => 100,
'size' => 10,
'description' => 'If set and data source value goes below this number, alert will be triggered',
'value' => isset($thold_item_data['thold_warning_low']) ? $thold_item_data['thold_warning_low'] : ''
),
'thold_warning_fail_trigger' => array(
'friendly_name' => 'Min Warning Trigger Duration',
'method' => 'drop_array',
'array' => $alertarray,
'description' => 'The amount of time the data source must be in a breach condition for an alert to be raised.',
'value' => isset($thold_item_data['thold_warning_fail_trigger']) ? $thold_item_data['thold_warning_fail_trigger'] : read_config_option('alert_trigger')
),
'thold_header' => array(
'friendly_name' => 'High / Low Settings',
'method' => 'spacer',
),
'thold_hi' => array(
'friendly_name' => 'High Threshold',
'method' => 'textbox',
'max_length' => 100,
'size' => 10,
'description' => 'If set and data source value goes above this number, alert will be triggered',
'value' => isset($thold_item_data['thold_hi']) ? $thold_item_data['thold_hi'] : ''
),
'thold_low' => array(
'friendly_name' => 'Low Threshold',
'method' => 'textbox',
'max_length' => 100,
'size' => 10,
'description' => 'If set and data source value goes below this number, alert will be triggered',
'value' => isset($thold_item_data['thold_low']) ? $thold_item_data['thold_low'] : ''
),
'thold_fail_trigger' => array(
'friendly_name' => 'Min Trigger Duration',
'method' => 'drop_array',
'array' => $alertarray,
'description' => 'The amount of time the data source must be in a breach condition for an alert to be raised.',
'value' => isset($thold_item_data['thold_fail_trigger']) ? $thold_item_data['thold_fail_trigger'] : read_config_option('alert_trigger')
),
'time_warning_header' => array(
'friendly_name' => 'Time Based Warning Settings',
'method' => 'spacer',
),
'time_warning_hi' => array(
'friendly_name' => 'High Warning Threshold',
'method' => 'textbox',
'max_length' => 100,
'size' => 10,
'description' => 'If set and data source value goes above this number, warning will be triggered',
'value' => isset($thold_item_data['time_warning_hi']) ? $thold_item_data['time_warning_hi'] : ''
),
'time_warning_low' => array(
'friendly_name' => 'Low Warning Threshold',
'method' => 'textbox',
'max_length' => 100,
'size' => 10,
'description' => 'If set and data source value goes below this number, warning will be triggered',
'value' => isset($thold_item_data['time_warning_low']) ? $thold_item_data['time_warning_low'] : ''
),
'time_warning_fail_trigger' => array(
'friendly_name' => 'Warning Trigger Count',
'method' => 'textbox',
'max_length' => 5,
'size' => 10,
'default' => read_config_option('thold_warning_time_fail_trigger'),
'description' => 'The number of times the data source must be in breach condition prior to issuing a warning.',
'value' => isset($thold_item_data['time_warning_fail_trigger']) ? $thold_item_data['time_warning_fail_trigger'] : read_config_option('alert_trigger')
),
'time_warning_fail_length' => array(
'friendly_name' => 'Warning Time Period Length',
'method' => 'drop_array',
'array' => $timearray,
'description' => 'The amount of time in the past to check for threshold breaches.',
'value' => isset($thold_item_data['time_warning_fail_length']) ? $thold_item_data['time_warning_fail_length'] : (read_config_option('thold_time_fail_length') > 0 ? read_config_option('thold_warning_time_fail_length') : 1)
),
'time_header' => array(
'friendly_name' => 'Time Based Settings',
'method' => 'spacer',
),
'time_hi' => array(
'friendly_name' => 'High Threshold',
'method' => 'textbox',
'max_length' => 100,
'size' => 10,
'description' => 'If set and data source value goes above this number, alert will be triggered',
'value' => isset($thold_item_data['time_hi']) ? $thold_item_data['time_hi'] : ''
),
'time_low' => array(
'friendly_name' => 'Low Threshold',
'method' => 'textbox',
'max_length' => 100,
'size' => 10,
'description' => 'If set and data source value goes below this number, alert will be triggered',
'value' => isset($thold_item_data['time_low']) ? $thold_item_data['time_low'] : ''
),
'time_fail_trigger' => array(
'friendly_name' => 'Trigger Count',
'method' => 'textbox',
'max_length' => 5,
'size' => 10,
'description' => 'The number of times the data source must be in breach condition prior to issuing an alert.',
'value' => isset($thold_item_data['time_fail_trigger']) ? $thold_item_data['time_fail_trigger'] : read_config_option('thold_time_fail_trigger')
),
'time_fail_length' => array(
'friendly_name' => 'Time Period Length',
'method' => 'drop_array',
'array' => $timearray,
'description' => 'The amount of time in the past to check for threshold breaches.',
'value' => isset($thold_item_data['time_fail_length']) ? $thold_item_data['time_fail_length'] : (read_config_option('thold_time_fail_length') > 0 ? read_config_option('thold_time_fail_length') : 2)
),
'baseline_header' => array(
'friendly_name' => 'Baseline Monitoring',
'method' => 'spacer',
),
'bl_ref_time_range' => array(
'friendly_name' => 'Time reference in the past',
'method' => 'drop_array',
'array' => $reference_types,
'description' => 'Specifies the point in the past (based on rrd resolution) that will be used as a reference',
'value' => isset($thold_item_data['bl_ref_time_range']) ? $thold_item_data['bl_ref_time_range'] : read_config_option('alert_bl_timerange_def')
),
'bl_pct_up' => array(
'friendly_name' => 'Baseline Deviation UP',
'method' => 'textbox',
'max_length' => 3,
'size' => 10,
'description' => 'Specifies allowed deviation in percentage for the upper bound threshold. If not set, upper bound threshold will not be checked at all.',
'value' => isset($thold_item_data['bl_pct_up']) ? $thold_item_data['bl_pct_up'] : read_config_option("alert_bl_percent_def")
),
'bl_pct_down' => array(
'friendly_name' => 'Baseline Deviation DOWN',
'method' => 'textbox',
'max_length' => 3,
'size' => 10,
'description' => 'Specifies allowed deviation in percentage for the lower bound threshold. If not set, lower bound threshold will not be checked at all.',
'value' => isset($thold_item_data['bl_pct_down']) ? $thold_item_data['bl_pct_down'] : read_config_option("alert_bl_percent_def")
),
'bl_fail_trigger' => array(
'friendly_name' => 'Baseline Trigger Count',
'method' => 'textbox',
'max_length' => 3,
'size' => 10,
'description' => 'Number of consecutive times the data source must be in a breached condition for an alert to be raised.<br>Leave empty to use default value (<b>Default: ' . read_config_option('alert_bl_trigger') . ' cycles</b>)',
'value' => isset($thold_item_data['bl_fail_trigger']) ? $thold_item_data['bl_fail_trigger'] : read_config_option("alert_bl_trigger")
),
'data_manipulation' => array(
'friendly_name' => 'Data Manipulation',
'method' => 'spacer',
),
'data_type' => array(
'friendly_name' => 'Data Type',
'method' => 'drop_array',
'on_change' => 'changeDataType()',
'array' => $data_types,
'description' => 'Special formatting for the given data.',
'value' => isset($thold_item_data['data_type']) ? $thold_item_data['data_type'] : read_config_option('data_type')
),
'cdef' => array(
'friendly_name' => 'Threshold CDEF',
'method' => 'drop_array',
'default' => 'NULL',
'description' => 'Apply this CDEF before returning the data.',
'value' => isset($thold_item_data['cdef']) ? $thold_item_data['cdef'] : 0,
'array' => thold_cdef_select_usable_names()
),
'percent_ds' => array(
'friendly_name' => 'Percent Datasource',
'method' => 'drop_array',
'default' => 'NULL',
'description' => 'Second Datasource Item to use as total value to calculate percentage from.',
'value' => isset($thold_item_data['percent_ds']) ? $thold_item_data['percent_ds'] : 0,
'array' => $data_fields2,
),
'expression' => array(
'friendly_name' => 'RPN Expression',
'method' => 'textbox',
'default' => '',
'description' => 'An RPN Expression is an RRDtool Compatible RPN Expression. Syntax includes
all functions below in addition to both Host and Data Query replacement expressions such as
<span style="color:blue;">|query_ifSpeed|</span>. To use a Data Source in the RPN Expression, you must use the syntax: <span style="color:blue;">|ds:dsname|</span>. For example, <span style="color:blue;">|ds:traffic_in|</span> will get the current value
of the traffic_in Data Source for the RRDfile(s) associated with the Graph. Any Data Source for a Graph can be included.<br>Math Operators: <span style="color:blue;">+, -, /, *, %, ^</span><br>Functions: <span style="color:blue;">SIN, COS, TAN, ATAN, SQRT, FLOOR, CEIL, DEG2RAD, RAD2DEG, ABS, EXP, LOG, ATAN, ADNAN</span><br>Flow Operators: <span style="color:blue;">UN, ISINF, IF, LT, LE, GT, GE, EQ, NE</span><br>Comparison Functions: <span style="color:blue;">MAX, MIN, INF, NEGINF, NAN, UNKN, COUNT, PREV</span>'.$replacements.$datasources,
'value' => isset($thold_item_data['expression']) ? $thold_item_data['expression'] : '',
'max_length' => '255',
'size' => '80'
),
'other_header' => array(
'friendly_name' => 'Other setting',
'method' => 'spacer',
),
'notify_warning' => array(
'friendly_name' => 'Warning Notification List',
'method' => 'drop_sql',
'description' => 'You may specify choose a Notification List to receive Warnings for this Data Source',
'value' => isset($thold_item_data['notify_warning']) ? $thold_item_data['notify_warning'] : '',
'none_value' => 'None',
'sql' => 'SELECT id, name FROM plugin_notification_lists ORDER BY name'
),
'notify_alert' => array(
'friendly_name' => 'Alert Notification List',
'method' => 'drop_sql',
'description' => 'You may specify choose a Notification List to receive Alerts for this Data Source',
'value' => isset($thold_item_data['notify_alert']) ? $thold_item_data['notify_alert'] : '',
'none_value' => 'None',
'sql' => 'SELECT id, name FROM plugin_notification_lists ORDER BY name'
),
);
if (read_config_option("thold_disable_legacy") != 'on') {
$extra = array(
'notify_accounts' => array(
'friendly_name' => 'Notify accounts',
'method' => 'drop_multi',
'description' => 'This is a listing of accounts that will be notified when this threshold is breached.<br><br><br><br>',
'array' => $send_notification_array,
'sql' => $sql,
),
'notify_extra' => array(
'friendly_name' => 'Alert Emails',
'method' => 'textarea',
'textarea_rows' => 3,
'textarea_cols' => 50,
'description' => 'You may specify here extra Emails to receive alerts for this data source (comma separated)',
'value' => isset($thold_item_data['notify_extra']) ? $thold_item_data['notify_extra'] : ''
),
'notify_warning_extra' => array(
'friendly_name' => 'Warning Emails',
'method' => 'textarea',
'textarea_rows' => 3,
'textarea_cols' => 50,
'description' => 'You may specify here extra Emails to receive warnings for this data source (comma separated)',
'value' => isset($thold_item_data['notify_warning_extra']) ? $thold_item_data['notify_warning_extra'] : ''
)
);
$form_array += $extra;
} else {
$extra = array(
'notify_accounts' => array(
'method' => 'hidden',
'value' => 'ignore',
),
'notify_extra' => array(
'method' => 'hidden',
'value' => isset($thold_item_data['notify_extra']) ? $thold_item_data['notify_extra'] : ''
),
'notify_warning_extra' => array(
'method' => 'hidden',
'value' => isset($thold_item_data['notify_warning_extra']) ? $thold_item_data['notify_warning_extra'] : ''
)
);
$form_array += $extra;
}
draw_edit_form(
array(
'config' => array(
'no_form_tag' => true
),
'fields' => $form_array
)
);
form_hidden_box("save", "edit", "");
form_hidden_box("id", $id, "");
html_end_box();
form_save_button('thold_templates.php?id=' . $id, 'save');
?>
<!-- Make it look intelligent :) -->
<script language="JavaScript">
function changeTholdType() {
type = document.getElementById('thold_type').value;
switch(type) {
case '0': // Hi/Low
thold_toggle_hilow('');
thold_toggle_baseline('none');
thold_toggle_time('none');
break;
case '1': // Baseline
thold_toggle_hilow('none');
thold_toggle_baseline('');
thold_toggle_time('none');
break;
case '2': // Time Based
thold_toggle_hilow('none');
thold_toggle_baseline('none');
thold_toggle_time('');
break;
}