forked from Cacti/cacti
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_queries.php
1427 lines (1200 loc) · 48.9 KB
/
data_queries.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-2019 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/ |
+-------------------------------------------------------------------------+
*/
include('./include/auth.php');
include_once('./lib/data_query.php');
include_once('./lib/poller.php');
include_once('./lib/utility.php');
$dq_actions = array(
1 => __('Delete')
);
/* set default action */
set_default_action();
switch (get_request_var('action')) {
case 'save':
form_save();
break;
case 'actions':
form_actions();
break;
case 'item_moveup_dssv':
data_query_item_moveup_dssv();
header('Location: data_queries.php?header=false&action=item_edit&id=' . get_filter_request_var('snmp_query_graph_id') . '&snmp_query_id=' . get_filter_request_var('snmp_query_id'));
break;
case 'item_movedown_dssv':
data_query_item_movedown_dssv();
header('Location: data_queries.php?header=false&action=item_edit&id=' . get_filter_request_var('snmp_query_graph_id') . '&snmp_query_id=' . get_filter_request_var('snmp_query_id'));
break;
case 'item_remove_dssv':
data_query_item_remove_dssv();
header('Location: data_queries.php?header=false&action=item_edit&id=' . get_filter_request_var('snmp_query_graph_id') . '&snmp_query_id=' . get_filter_request_var('snmp_query_id'));
break;
case 'item_moveup_gsv':
data_query_item_moveup_gsv();
header('Location: data_queries.php?header=false&action=item_edit&id=' . get_filter_request_var('snmp_query_graph_id') . '&snmp_query_id=' . get_filter_request_var('snmp_query_id'));
break;
case 'item_movedown_gsv':
data_query_item_movedown_gsv();
header('Location: data_queries.php?header=false&action=item_edit&id=' . get_filter_request_var('snmp_query_graph_id') . '&snmp_query_id=' . get_filter_request_var('snmp_query_id'));
break;
case 'item_remove_gsv':
data_query_item_remove_gsv();
header('Location: data_queries.php?header=false&action=item_edit&id=' . get_filter_request_var('snmp_query_graph_id') . '&snmp_query_id=' . get_filter_request_var('snmp_query_id'));
break;
case 'item_remove_confirm':
data_query_item_remove_confirm();
break;
case 'item_remove':
data_query_item_remove();
header('Location: data_queries.php?header=false&action=edit&id=' . get_filter_request_var('snmp_query_id'));
break;
case 'item_edit':
top_header();
data_query_item_edit();
bottom_footer();
break;
case 'remove':
data_query_remove();
header ('Location: data_queries.php');
break;
case 'edit':
top_header();
data_query_edit();
bottom_footer();
break;
default:
top_header();
data_query();
bottom_footer();
break;
}
/* --------------------------
The Save Function
-------------------------- */
function form_save() {
if (isset_request_var('save_component_snmp_query')) {
get_filter_request_var('id');
get_filter_request_var('data_input_id');
$save['id'] = get_request_var('id');
$save['hash'] = get_hash_data_query(get_nfilter_request_var('id'));
$save['name'] = form_input_validate(get_nfilter_request_var('name'), 'name', '', false, 3);
$save['description'] = form_input_validate(get_nfilter_request_var('description'), 'description', '', true, 3);
$save['xml_path'] = form_input_validate(get_nfilter_request_var('xml_path'), 'xml_path', '', false, 3);
$save['data_input_id'] = get_request_var('data_input_id');
// Detect changing input id
if (!empty($save['id'])) {
$previous_input_id = db_fetch_cell_prepared('SELECT data_input_id
FROM snmp_query
WHERE id = ?',
array($save['id']));
}
if (!is_error_message()) {
$snmp_query_id = sql_save($save, 'snmp_query');
if ($snmp_query_id) {
raise_message(1);
data_query_update_input_method($snmp_query_id, $previous_input_id, $save['data_input_id']);
update_replication_crc(0, 'poller_replicate_snmp_query_crc');
} else {
raise_message(2);
}
}
header('Location: data_queries.php?header=false&action=edit&id=' . (empty($snmp_query_id) ? get_request_var('id') : $snmp_query_id));
} elseif (isset_request_var('save_component_snmp_query_item') && !isset_request_var('svg_x') && !isset_request_var('svds_x')) {
/* ================= input validation ================= */
get_filter_request_var('id');
get_filter_request_var('snmp_query_id');
get_filter_request_var('graph_template_id');
/* ==================================================== */
$save['id'] = get_request_var('id');
$save['hash'] = get_hash_data_query(get_nfilter_request_var('id'), 'data_query_graph');
$save['snmp_query_id'] = get_request_var('snmp_query_id');
$save['name'] = form_input_validate(get_nfilter_request_var('name'), 'name', '', false, 3);
$save['graph_template_id'] = get_request_var('graph_template_id');
$header = '';
$errors = false;
if (!is_error_message()) {
if ($save['id'] > 0) {
$errors = api_data_query_errors($save['id'], $_POST);
}
if ($errors === false) {
$snmp_query_graph_id = sql_save($save, 'snmp_query_graph');
if ($snmp_query_graph_id) {
raise_message(1);
/* if the user changed the graph template, go through and delete everything that
was associated with the old graph template */
if (get_nfilter_request_var('graph_template_id') != get_nfilter_request_var('graph_template_id_prev')) {
db_execute_prepared('DELETE
FROM snmp_query_graph_rrd_sv
WHERE snmp_query_graph_id = ?',
array($snmp_query_graph_id));
db_execute_prepared('DELETE
FROM snmp_query_graph_sv
WHERE snmp_query_graph_id = ?',
array($snmp_query_graph_id));
}
db_execute_prepared('DELETE
FROM snmp_query_graph_rrd
WHERE snmp_query_graph_id = ?',
array($snmp_query_graph_id));
foreach ($_POST as $var => $val) {
if (preg_match('/^dsdt_([0-9]+)_([0-9]+)_check/i', $var)) {
$data_template_id = preg_replace('/^dsdt_([0-9]+)_([0-9]+).+/', "\\1", $var);
$data_template_rrd_id = preg_replace('/^dsdt_([0-9]+)_([0-9]+).+/', "\\2", $var);
/* ================= input validation ================= */
input_validate_input_number($data_template_id);
input_validate_input_number($data_template_rrd_id);
/* ==================================================== */
db_execute_prepared('REPLACE INTO snmp_query_graph_rrd
(snmp_query_graph_id, data_template_id, data_template_rrd_id, snmp_field_name)
VALUES (?, ?, ?, ?)',
array(
$snmp_query_graph_id,
$data_template_id,
$data_template_rrd_id,
get_nfilter_request_var('dsdt_' .
$data_template_id . '_' .
$data_template_rrd_id . '_snmp_field_output')
)
);
}
}
if (isset_request_var('header') && get_nfilter_request_var('header') == 'false') {
$header = '&header=false';
} else {
$header = '&header=fasle';
}
} else {
raise_message(2);
$header = '&header=false';
}
} else {
$header = '&header=false';
}
}
header('Location: data_queries.php?header=false&action=item_edit' . $header . '&id=' . (empty($snmp_query_graph_id) ? get_request_var('id') : $snmp_query_graph_id) . '&snmp_query_id=' . get_request_var('snmp_query_id'));
} elseif (isset_request_var('svg_x')) {
/* ================= input validation ================= */
get_filter_request_var('id');
get_filter_request_var('snmp_query_id');
get_filter_request_var('graph_template_id');
/* ==================================================== */
if (isset_request_var('header') && get_nfilter_request_var('header') == 'false') {
$header = '&header=false';
} else {
$header = '';
}
if (isempty_request_var('svg_text')) {
raise_message(39);
header('Location: data_queries.php?header=false&action=item_edit' . $header . '&id=' . get_request_var('id') . '&snmp_query_id=' . get_request_var('snmp_query_id'));
return;
} elseif (isempty_request_var('svg_field')) {
raise_message(38);
header('Location: data_queries.php?header=false&action=item_edit' . $header . '&id=' . get_request_var('id') . '&snmp_query_id=' . get_request_var('snmp_query_id'));
return;
}
/* suggested values -- graph templates */
$sequence = get_sequence(0, 'sequence', 'snmp_query_graph_sv', 'snmp_query_graph_id=' . get_filter_request_var('id') . " AND field_name = " . db_qstr(get_nfilter_request_var('svg_field')));
$hash = get_hash_data_query(0, 'data_query_sv_graph');
$header = '';
db_execute_prepared('INSERT INTO snmp_query_graph_sv
(hash, snmp_query_graph_id, sequence, field_name, text)
VALUES (?, ?, ?, ?, ?)',
array(
$hash,
get_request_var('id'),
$sequence,
get_nfilter_request_var('svg_field'),
get_nfilter_request_var('svg_text')
)
);
clear_messages();
if (isset_request_var('header') && get_nfilter_request_var('header') == 'false') {
$header = '&header=false';
} else {
$header = '';
}
header('Location: data_queries.php?header=false&action=item_edit' . $header . '&id=' . get_request_var('id') . '&snmp_query_id=' . get_request_var('snmp_query_id'));
} elseif (isset_request_var('svds_x')) {
/* ================= input validation ================= */
get_filter_request_var('id');
get_filter_request_var('snmp_query_id');
get_filter_request_var('graph_template_id');
/* ==================================================== */
if (isset_request_var('header') && get_nfilter_request_var('header') == 'false') {
$header = '&header=false';
} else {
$header = '';
}
foreach ($_POST as $var => $val) {
if (preg_match('/^svds_([0-9]+)_x/i', $var, $matches)) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
if (isempty_request_var('svds_' . $matches[1] . '_text')) {
raise_message(39);
header('Location: data_queries.php?header=false&action=item_edit' . $header . '&id=' . get_request_var('id') . '&snmp_query_id=' . get_request_var('snmp_query_id'));
return;
} elseif (isempty_request_var('svds_' . $matches[1] . '_field')) {
raise_message(38);
header('Location: data_queries.php?header=false&action=item_edit' . $header . '&id=' . get_request_var('id') . '&snmp_query_id=' . get_request_var('snmp_query_id'));
return;
}
$sequence = get_sequence(0, 'sequence', 'snmp_query_graph_rrd_sv', 'snmp_query_graph_id=' . get_request_var('id') . ' AND data_template_id=' . $matches[1] . " AND field_name='" . get_nfilter_request_var('svds_' . $matches[1] . '_field') . "'");
$hash = get_hash_data_query(0, 'data_query_sv_data_source');
db_execute_prepared('INSERT INTO snmp_query_graph_rrd_sv
(hash, snmp_query_graph_id, data_template_id, sequence, field_name, text)
VALUES (?, ?, ?, ?, ?, ?)',
array(
$hash, get_request_var('id'),
$matches[1],
$sequence,
get_nfilter_request_var('svds_' . $matches[1] . '_field'),
get_nfilter_request_var('svds_' . $matches[1] . '_text')
)
);
clear_messages();
if (isset_request_var('header') && get_nfilter_request_var('header') == 'false') {
$header = '&header=false';
} else {
$header = '';
}
header('Location: data_queries.php?header=false&action=item_edit' . $header . '&id=' . get_request_var('id') . '&snmp_query_id=' . get_request_var('snmp_query_id'));
break;
}
}
}
}
function form_actions() {
global $dq_actions;
/* ================= input validation ================= */
get_filter_request_var('drp_action', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^([a-zA-Z0-9_]+)$/')));
/* ==================================================== */
/* if we are to save this form, instead of display it */
if (isset_request_var('selected_items')) {
$selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
if ($selected_items != false) {
if (get_nfilter_request_var('drp_action') == '1') { /* delete */
for ($i=0;($i<cacti_count($selected_items));$i++) {
data_query_remove($selected_items[$i]);
}
}
}
header('Location: data_queries.php?header=false');
exit;
}
/* setup some variables */
$dq_list = ''; $i = 0;
/* loop through each of the data queries and process them */
foreach ($_POST as $var => $val) {
if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
$name = db_fetch_cell_prepared('SELECT name
FROM snmp_query
WHERE id = ?',
array($matches[1]));
$dq_list .= '<li>' . html_escape($name) . '</li>';
$dq_array[$i] = $matches[1];
$i++;
}
}
top_header();
form_start('data_queries.php');
html_start_box($dq_actions[get_nfilter_request_var('drp_action')], '60%', '', '3', 'center', '');
if (isset($dq_array) && cacti_sizeof($dq_array)) {
if (get_nfilter_request_var('drp_action') == '1') { /* delete */
$graphs = array();
print "<tr>
<td class='textArea' class='odd'>
<p>" . __n('Click \'Continue\' to delete the following Data Query.', 'Click \'Continue\' to delete following Data Queries.', cacti_sizeof($dq_array)) . "</p>
<div class='itemlist'><ul>$dq_list</ul></div>
</td>
</tr>\n";
}
$save_html = "<input type='button' class='ui-button ui-corner-all ui-widget' value='" . __esc('Cancel') . "' onClick='cactiReturnTo()'> <input type='submit' class='ui-button ui-corner-all ui-widget' value='" . __esc('Continue') . "' title='" . __n('Delete Data Query', 'Delete Data Query', cacti_sizeof($dq_array)) . "'>";
} else {
raise_message(40);
header('Location: data_queries.php?header=false');
exit;
}
print "<tr>
<td class='saveRow'>
<input type='hidden' name='action' value='actions'>
<input type='hidden' name='selected_items' value='" . (isset($dq_array) ? serialize($dq_array) : '') . "'>
<input type='hidden' name='drp_action' value='" . html_escape(get_nfilter_request_var('drp_action')) . "'>
$save_html
</td>
</tr>\n";
html_end_box();
form_end();
bottom_footer();
}
/* ----------------------------
Data Query Graph Functions
---------------------------- */
function data_query_item_movedown_gsv() {
/* ================= input validation ================= */
get_filter_request_var('id');
get_filter_request_var('snmp_query_graph_id');
/* ==================================================== */
move_item_down('snmp_query_graph_sv', get_request_var('id'), 'snmp_query_graph_id=' . get_request_var('snmp_query_graph_id') . " AND field_name = " . db_qstr(get_nfilter_request_var('field_name')));
}
function data_query_item_moveup_gsv() {
/* ================= input validation ================= */
get_filter_request_var('id');
get_filter_request_var('snmp_query_graph_id');
/* ==================================================== */
move_item_up('snmp_query_graph_sv', get_request_var('id'), 'snmp_query_graph_id=' . get_request_var('snmp_query_graph_id') . " AND field_name = " . db_qstr(get_nfilter_request_var('field_name')));
}
function data_query_item_remove_gsv() {
/* ================= input validation ================= */
get_filter_request_var('id');
/* ==================================================== */
db_execute_prepared('DELETE FROM snmp_query_graph_sv
WHERE id = ?',
array(get_request_var('id')));
}
function data_query_item_movedown_dssv() {
/* ================= input validation ================= */
get_filter_request_var('id');
get_filter_request_var('data_template_id');
get_filter_request_var('snmp_query_graph_id');
/* ==================================================== */
move_item_down('snmp_query_graph_rrd_sv', get_request_var('id'), 'data_template_id=' . get_request_var('data_template_id') . ' AND snmp_query_graph_id=' . get_request_var('snmp_query_graph_id') . " AND field_name = " . db_qstr(get_nfilter_request_var('field_name')));
}
function data_query_item_moveup_dssv() {
/* ================= input validation ================= */
get_filter_request_var('id');
get_filter_request_var('data_template_id');
get_filter_request_var('snmp_query_graph_id');
/* ==================================================== */
move_item_up('snmp_query_graph_rrd_sv', get_request_var('id'), 'data_template_id=' . get_request_var('data_template_id') . ' AND snmp_query_graph_id=' . get_request_var('snmp_query_graph_id') . " AND field_name = " . db_qstr(get_nfilter_request_var('field_name')));
}
function data_query_sv_check_sequences($type, $snmp_query_graph_id, $field_name) {
if ($type == 'ds' || $type == 'gr') {
if ($type == 'ds') {
$table = 'snmp_query_graph_rrd_sv';
} else {
$table = 'snmp_query_graph_sv';
}
} else {
return false;
}
$bad_seq = db_fetch_cell_prepared("SELECT COUNT(sequence)
FROM $table
WHERE sequence <= 0
AND field_name = ?
AND snmp_query_graph_id = ?",
array($field_name, $snmp_query_graph_id));
$dup_seq = db_fetch_cell_prepared("SELECT SUM(count)
FROM (
SELECT sequence, COUNT(sequence) AS count
FROM $table
WHERE field_name = ?
AND snmp_query_graph_id = ?
GROUP BY sequence
) AS t
WHERE t.count > 1",
array($field_name, $snmp_query_graph_id));
// report any bad or duplicate sequencs to the log for reporting purposes
if ($bad_seq > 0) {
cacti_log('WARN: Found ' . $bad_seq . " Bad Sequences in $table Table", false, 'WEBUI', POLLER_VERBOSITY_HIGH);
}
if ($dup_seq > 0) {
cacti_log('WARN: Found ' . $dup_seq . " Duplicated Sequences in $table Table", false, 'WEBUI', POLLER_VERBOSITY_HIGH);
}
if ($bad_seq > 0 || $dup_seq > 0) {
// resequence the list so it has no gaps, and 0 values will appear at the top
// since thats where they would have been displayed
db_execute_prepared("SET @seq = 0;
UPDATE $table
SET sequence = (@seq:=@seq+1)
WHERE field_name = ?
AND snmp_query_graph_id = ?
ORDER BY sequence, id;",
array($field_name, $snmp_query_graph_id));
}
}
function data_query_item_remove_dssv() {
/* ================= input validation ================= */
get_filter_request_var('id');
/* ==================================================== */
db_execute_prepared('DELETE
FROM snmp_query_graph_rrd_sv
WHERE id = ?',
array(get_request_var('id')));
}
function data_query_item_remove_confirm() {
global $vdef_functions, $vdef_item_types, $custom_vdef_data_source_types;
/* ================= input validation ================= */
get_filter_request_var('id');
get_filter_request_var('snmp_query_id');
/* ==================================================== */
form_start('data_queries.php?action=edit&id' . get_request_var('snmp_query_id'));
html_start_box('', '100%', '', '3', 'center', '');
$graph_template = db_fetch_row_prepared('SELECT *
FROM snmp_query_graph
WHERE id = ?',
array(get_request_var('id')));
?>
<tr>
<td class='topBoxAlt'>
<p><?php print __('Click \'Continue\' to delete the following Data Query Graph Association.');?></p>
<p><?php print __('Graph Name: %s', $graph_template['name']);?><br>
</td>
</tr>
<tr>
<td class='right'>
<input type='button' class='ui-button ui-corner-all ui-widget' id='cancel' value='<?php print __esc('Cancel');?>' onClick='$("#cdialog").dialog("close");' name='cancel'>
<input type='button' class='ui-button ui-corner-all ui-widget' id='continue' value='<?php print __esc('Continue');?>' name='continue' title='<?php print __esc('Remove VDEF Item');?>'>
</td>
</tr>
<?php
html_end_box();
form_end();
?>
<script type='text/javascript'>
$(function() {
$('#continue').click(function(data) {
$.post('data_queries.php?action=item_remove', {
__csrf_magic: csrfMagicToken,
snmp_query_id: <?php print get_request_var('snmp_query_id');?>,
id: <?php print get_request_var('id');?>
}, function(data) {
$('#cdialog').dialog('close');
loadPageNoHeader('data_queries.php?action=edit&header=false&id=<?php print get_request_var('snmp_query_id');?>');
});
});
});
</script>
<?php
}
function data_query_item_remove() {
/* ================= input validation ================= */
get_filter_request_var('id');
/* ==================================================== */
db_execute_prepared('DELETE
FROM snmp_query_graph
WHERE id = ?',
array(get_request_var('id')));
db_execute_prepared('DELETE
FROM snmp_query_graph_rrd
WHERE snmp_query_graph_id = ?',
array(get_request_var('id')));
db_execute_prepared('DELETE
FROM snmp_query_graph_rrd_sv
WHERE snmp_query_graph_id = ?',
array(get_request_var('id')));
db_execute_prepared('DELETE
FROM snmp_query_graph_sv
WHERE snmp_query_graph_id = ?',
array(get_request_var('id')));
}
function data_query_item_edit() {
global $fields_data_query_item_edit;
/* ================= input validation ================= */
get_filter_request_var('id');
get_filter_request_var('snmp_query_id');
/* ==================================================== */
if (!isempty_request_var('id')) {
$snmp_query_item = db_fetch_row_prepared('SELECT *
FROM snmp_query_graph
WHERE id = ?',
array(get_request_var('id')));
}
$snmp_query = db_fetch_row_prepared('SELECT name, xml_path
FROM snmp_query
WHERE id = ?',
array(get_request_var('snmp_query_id')));
if (cacti_sizeof($snmp_query)) {
$header_label = __('Associated Graph/Data Templates [edit: %s]', html_escape($snmp_query['name']));
} else {
$header_label = __('Associated Graph/Data Templates [new]');
}
form_start('data_queries.php', 'data_queries');
html_start_box($header_label, '100%', true, '3', 'center', '');
draw_edit_form(
array(
'config' => array('no_form_tag' => true),
'fields' => inject_form_variables($fields_data_query_item_edit, (isset($snmp_query_item) ? $snmp_query_item : array()), $_REQUEST)
)
);
html_end_box(true, true);
?>
<script type='text/javascript'>
function assignDataQueryGraphName(init) {
if (init == false || $('#name').val() == '') {
$('#name').val($('#graph_template_id').children(':selected').text());
}
}
$(function() {
$('form#data_queries').find('#graph_template_id').change(function() {
assignDataQueryGraphName(false);
});
assignDataQueryGraphName(true);
});
</script>
<?php
if (!empty($snmp_query_item['id'])) {
html_start_box( __('Associated Data Templates'), '100%', '', '3', 'center', '');
$data_templates = db_fetch_assoc_prepared('SELECT data_template.id, data_template.name
FROM (data_template, data_template_rrd, graph_templates_item)
WHERE graph_templates_item.task_item_id = data_template_rrd.id
AND data_template_rrd.data_template_id = data_template.id
AND data_template_rrd.local_data_id = 0
AND graph_templates_item.local_graph_id = 0
AND graph_templates_item.graph_template_id = ?
GROUP BY data_template.id
ORDER BY data_template.name', array($snmp_query_item['graph_template_id']));
$i = 0;
if (cacti_sizeof($data_templates)) {
foreach ($data_templates as $data_template) {
print "<tr class='tableHeader'>
<th class='tableSubHeaderColumn'>" . __('Data Template - %s', $data_template['name']) . '</th>
</tr>';
$data_template_rrds = db_fetch_assoc_prepared('SELECT dtr.id, dtr.data_source_name,
sqgr.snmp_field_name, sqgr.snmp_query_graph_id
FROM data_template_rrd AS dtr
LEFT JOIN snmp_query_graph_rrd AS sqgr
ON sqgr.data_template_rrd_id = dtr.id
AND sqgr.snmp_query_graph_id = ?
AND sqgr.data_template_id = ?
WHERE dtr.data_template_id = ?
AND dtr.local_data_id = 0
ORDER BY dtr.data_source_name',
array(get_request_var('id'), $data_template['id'], $data_template['id']));
$i = 0;
if (cacti_sizeof($data_template_rrds)) {
foreach ($data_template_rrds as $data_template_rrd) {
if (empty($data_template_rrd['snmp_query_graph_id'])) {
$old_value = '';
} else {
$old_value = 'on';
}
form_alternate_row();
?>
<td>
<table>
<tr>
<td style='width:200px;'>
<?php print __('Data Source');?>
</td>
<td style='width:200px;'>
<?php print $data_template_rrd['data_source_name'];?>
</td>
<td>
<?php
$snmp_queries = get_data_query_array(get_request_var('snmp_query_id'));
$xml_outputs = array();
if (isset($snmp_queries['fields']) && cacti_sizeof($snmp_queries['fields'])) {
foreach ($snmp_queries['fields'] as $field_name => $field_array) {
if ($field_array['direction'] == 'output' || $field_array['direction'] == 'input-output') {
$xml_outputs[$field_name] = $field_name . ' (' . $field_array['name'] . ')';
}
}
}
form_dropdown('dsdt_' . $data_template['id'] . '_' . $data_template_rrd['id'] . '_snmp_field_output',$xml_outputs,'','',$data_template_rrd['snmp_field_name'],'','');?>
</td>
<td class='right'>
<?php form_checkbox('dsdt_' . $data_template['id'] . '_' . $data_template_rrd['id'] . '_check', $old_value, '', '', '', get_request_var('id'), '', _('If this Graph Template requires the Data Template Data Source to the left, select the correct XML output column and then to enable the mapping either check or toggle here.')); print '<br>';?>
</td>
</tr>
</table>
</td>
<?php
form_end_row();
}
}
}
}
html_end_box();
html_start_box(__('Suggested Values - Graphs'), '100%', '', '3', 'center', '');
/* suggested values for graphs templates */
$suggested_values = db_fetch_assoc_prepared('SELECT text, field_name, snmp_query_graph_id, id
FROM snmp_query_graph_sv
WHERE snmp_query_graph_id = ?
ORDER BY field_name, sequence',
array(get_request_var('id')));
html_header(array(
array('display' => __('Name'), 'align' => 'left'),
array('display' => __('Order'), 'align' => 'center'),
array('display' => __('Equation'), 'align' => 'left')
), 2);
$i = 0;
$total_values = cacti_sizeof($suggested_values);
if ($total_values) {
foreach ($suggested_values as $suggested_value) {
data_query_sv_check_sequences('gr', $suggested_value['snmp_query_graph_id'], $suggested_value['field_name']);
form_alternate_row();
$show_up = false;
$show_down = false;
// Handle up true
if ($i != 0) {
$show_up = true;
}
// Handle down true
if ($total_values > 1 && $i < $total_values-1) {
$show_down = true;
}
?>
<td class='left'>
<?php print html_escape($suggested_value['field_name']);?>
</td>
<td class='center'>
<?php if ($show_down) {?>
<a class='remover fa fa-caret-down moveArrow' title='<?php print __('Move Down');?>' href='<?php print html_escape('data_queries.php?action=item_movedown_gsv&snmp_query_graph_id=' . get_request_var('id') . '&id=' . $suggested_value['id'] . '&snmp_query_id=' . get_request_var('snmp_query_id') . '&field_name=' . $suggested_value['field_name']);?>'></a>
<?php } else {?>
<span class='moveArrowNone'></span>
<?php } ?>
<?php if ($show_up) {?>
<a class='remover fa fa-caret-up moveArrow' title='<?php print __('Move Up');?>' href='<?php print html_escape('data_queries.php?action=item_moveup_gsv&snmp_query_graph_id=' . get_request_var('id') . '&id=' . $suggested_value['id'] . '&snmp_query_id=' . get_request_var('snmp_query_id') . '&field_name=' . $suggested_value['field_name']);?>'></a>
<?php } else {?>
<span class='moveArrowNone'></span>
<?php } ?>
</td>
<td class='left'>
<?php print html_escape($suggested_value['text']);?>
</td>
<td class='right'>
<a class='remover deleteMarker fa fa-times' title='<?php print html_escape(__('Delete'));?>' href='<?php print html_escape('data_queries.php?action=item_remove_gsv&snmp_query_graph_id=' . get_request_var('id') . '&id=' . $suggested_value['id'] . '&snmp_query_id=' . get_request_var('snmp_query_id'));?>'></a>
</td>
<?php
form_end_row();
$i++;
}
} else {
print "<tr><td colspan='4'><em>" . __('No Suggested Values Found') . "</em></td></tr>";
}
form_alternate_row();
?>
<td colspan='4'>
<table>
<tr>
<td class='nowrap'>
<?php print __('Field Name');?>
</td>
<td>
<input type='text' class='ui-state-default ui-corner-all' id='svg_field' size='15'>
</td>
<td class='nowrap'>
<?php print __('Suggested Value');?>
</td>
<td>
<input type='text' class='ui-state-default ui-corner-all' id='svg_text' size='60'>
</td>
<td>
<input type='button' class='ui-button ui-corner-all ui-widget' id='svg_x' name='svg_x' value='<?php print __esc('Add');?>' title='<?php print __('Add Graph Title Suggested Name');?>'>
</td>
</tr>
</table>
</td>
<?php
form_end_row();
html_end_box();
html_start_box( __('Suggested Values - Data Sources'), '100%', '', '3', 'center', '');
/* suggested values for data templates */
if (cacti_sizeof($data_templates)) {
foreach ($data_templates as $data_template) {
$suggested_values = db_fetch_assoc_prepared('SELECT text, field_name, snmp_query_graph_id, id
FROM snmp_query_graph_rrd_sv
WHERE snmp_query_graph_id = ?
AND data_template_id = ?
ORDER BY field_name, sequence', array(get_request_var('id'), $data_template['id']));
html_header(array(
array('display' => __('Name'), 'align' => 'left'),
array('display' => __('Order'), 'align' => 'center'),
array('display' => __('Equation'), 'align' => 'left')
), 2);
$i = 0;
$total_values = cacti_sizeof($suggested_values);
if ($total_values) {
$prev_name = '';
foreach ($suggested_values as $suggested_value) {
data_query_sv_check_sequences('ds', $suggested_value['snmp_query_graph_id'], $suggested_value['field_name']);
form_alternate_row();
$show_up = false;
$show_down = false;
// Handle up true
if ($i != 0) {
$show_up = true;
}
// Handle down true
if ($total_values > 1 && $i < $total_values-1) {
$show_down = true;
}
?>
<td class='left'>
<?php print html_escape($suggested_value['field_name']);?>
</td>
<td class='center'>
<?php if ($show_down) {?>
<a class='remover fa fa-caret-down moveArrow' title='<?php print __('Move Down');?>' href='<?php print html_escape('data_queries.php?action=item_movedown_dssv&snmp_query_graph_id=' . get_request_var('id') . '&id='. $suggested_value['id'] . '&snmp_query_id=' . get_request_var('snmp_query_id') . '&data_template_id=' . $data_template['id'] . '&field_name=' . $suggested_value['field_name']);?>'></a>
<?php } else {?>
<span class='moveArrowNone'></span>
<?php } ?>
<?php if ($show_up) {?>
<a class='remover fa fa-caret-up moveArrow' title='<?php print __('Move Up');?>' href='<?php print html_escape('data_queries.php?action=item_moveup_dssv&snmp_query_graph_id=' . get_request_var('id') . '&id=' . $suggested_value['id'] . '&snmp_query_id=' . get_request_var('snmp_query_id') . '&data_template_id=' . $data_template['id'] . '&field_name=' . $suggested_value['field_name']);?>'></a>
<?php } else {?>
<span class='moveArrowNone'></span>
<?php } ?>
</td>
<td class='nowrap left'>
<?php print html_escape($suggested_value['text']);?>
</td>
<td class='right'>
<a class='remover deleteMarker fa fa-times' title='<?php print __('Delete');?>' href='<?php print html_escape('data_queries.php?action=item_remove_dssv&snmp_query_graph_id=' . get_request_var('id') . '&id=' . $suggested_value['id'] . '&snmp_query_id=' . get_request_var('snmp_query_id') . '&data_template_id=' . $data_template['id']);?>'></a>
</td>
<?php
form_end_row();
$prev_name = $suggested_value['field_name'];
$i++;
}
} else {
print "<tr><td colspan='4'><em>" . __('No Suggested Values Found') . "</em></td></tr>";
}
form_alternate_row();
?>
<td colspan='4'>
<table>
<tr>
<td class='nowrap'>
<?php print __('Field Name');?>
</td>
<td>
<input type='text' class='svds_field ui-state-default ui-corner-all' id='svds_<?php print $data_template['id'];?>_field' name='svds_<?php print $data_template['id'];?>_field' size='15'>
</td>
<td class='nowrap'>
<?php print __('Suggested Value');?>
</td>
<td>
<input type='text' class='svds_text ui-state-default ui-corner-all' id='svds_<?php print $data_template['id'];?>_text' name='svds_<?php print $data_template['id'];?>_text' size='60'>
</td>
<td>
<input type='button' class='svds_x ui-button ui-corner-all ui-widget' id='svds_<?php print $data_template['id'];?>_x' name='svds_<?php print $data_template['id'];?>_x' value='<?php print __esc('Add');?>' title='<?php print __('Add Data Source Name Suggested Name');?>'>
</td>
</tr>
</table>
</td>
<?php
form_end_row();
}
}
html_end_box();
}
if (isset($snmp_query_item['graph_template_id'])) {
$item = $snmp_query_item['graph_template_id'];
} else {
$item = 0;
}
?>
<script type='text/javascript'>
var graph_template_id_prev=<?php print $item;?>;
$('.remover').click(function(event) {
event.preventDefault();
href=$(this).attr('href');
$.get(href)
.done(function(data) {
$('form[action="data_queries.php"]').unbind();
$('#main').html(data);
applySkin();
})
.fail(function(data) {
getPresentHTTPError(data);
});
});
$('input[id="svg_x"]').click(function() {
$.post('data_queries.php', {
graph_template_id_prev:graph_template_id_prev,
action:'save',
name:$('#name').val(),
graph_template_id:$('#graph_template_id').val(),
id:$('#id').val(),
header:'false',
save_component_snmp_query_item:'1',
snmp_query_id:$('#snmp_query_id').val(),
svg_field:$('#svg_field').val(),