-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrrdexport.php
934 lines (806 loc) · 45 KB
/
rrdexport.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
<?php
# TODO: This line for Dev only, Should remove before release
# include_once('./functions.php');
chdir(dirname(__FILE__));
chdir('../../');
include_once('./include/auth.php');
# include_once($config["base_path"] . '/plugins/rrdexport/functions.php');
$rrdexport_debug = false;
if(read_config_option('rrdexport_log_debug')!='') $rrdexport_debug=true;
function rrdexport_log($log) {
global $rrdexport_debug;
if($rrdexport_debug) cacti_log("RRDEXPORT DEBUG - " . $log);
}
define("MAX_DISPLAY_PAGES", 21);
$tabs = array(
"general" => "General",
"data_local" => "Data Sources"
);
$tabs = api_plugin_hook_function('rrdexport_tabs', $tabs);
$sc_intervals = array(86400 => 'Every Day', 604800 => 'Every Week');
$cf_types = array('AVERAGE' => 'AVERAGE', 'MAX' => 'MAX');
$schedule_actions = array(
1 => 'Delete',
2 => 'Run',
);
$assoc_actions = array(
1 => "Associate",
2 => "Disassociate"
);
$action = '';
if (array_key_exists('action', $_REQUEST)) {
$action = $_REQUEST['action'];
}
switch ($action) {
case 'save':
form_save();
break;
case 'actions':
form_actions();
break;
case 'edit':
include_once('./include/top_header.php');
schedule_edit();
include_once('./include/bottom_footer.php');
break;
default:
include_once('./include/top_header.php');
schedule_list();
include_once('./include/bottom_footer.php');
break;
}
function form_save() {
rrdexport_log("form save action");
if (isset($_POST["save_component"])) {
input_validate_input_number(get_request_var_post('id'));
input_validate_input_number(get_request_var_post('sc_interval'));
if (isset($_POST['name'])) {
$_POST['name'] = trim(str_replace(array("\\", "'", '"'), '', get_request_var_post('name')));
}
if (isset($_POST['cf_type'])) {
$_POST['cf_type'] = trim(str_replace(array("\\", "'", '"'), '', get_request_var_post('cf_type')));
}
if (isset($_POST['stime'])) {
$_POST['stime'] = trim(str_replace(array("\\", "'", '"'), '', get_request_var_post('stime')));
}
if(isset($_POST['id']) && ($_POST['id']!=0 || $_POST['id']!='')) {
$save['id'] = $_POST['id'];
rrdexport_log("save component schedule : id=" . $_POST['id']);
}else{
$save['id'] =0;
rrdexport_log("save component schedule : id=0 or create new schedule");
}
$save['name'] = $_POST['name'];
$save['cf_type'] = $_POST['cf_type'];
$save['stime'] = strtotime($_POST['stime']);
$save['sc_interval'] = $_POST['sc_interval'];
if (isset($_POST['enabled']))
$save['enabled'] = 'on';
else
$save['enabled'] = 'off';
rrdexport_log("save component schedule : ". serialize($save));
if (!is_error_message()) {
rrdexport_log("try save to plugin_rrdexport_schedules");
$id = sql_save($save, 'plugin_rrdexport_schedules');
if ($id) {
raise_message(1);
} else {
raise_message(2);
}
rrdexport_log("finished save");
}
header('Location: rrdexport.php?tab=data_local&action=edit&id=' . (empty($id) ? $_POST['id'] : $id));
exit;
}
}
function form_actions() {
global $colors, $schedule_actions, $assoc_actions;
/* if we are to save this form, instead of display it */
if (isset($_POST["selected_items"])) {
if (isset($_POST["save_schedule_list"])) {
if ($_POST["drp_action"] == "1") { /* delete */
$selected_items = unserialize(stripslashes($_POST["selected_items"]));
foreach($selected_items as $id) {
input_validate_input_number($id);
db_fetch_assoc("DELETE FROM plugin_rrdexport_schedules WHERE id = $id LIMIT 1");
db_fetch_assoc("DELETE FROM plugin_rrdexport_datasource WHERE schedule = $id");
}
}elseif ($_POST["drp_action"] == "2") { /* force run */
# schedule_execute();
}
header("Location: rrdexport.php");
exit;
}elseif (isset($_POST["save_datasource_list"])) {
$selected_items = unserialize(stripslashes($_POST["selected_items"]));
input_validate_input_number(get_request_var_post('schedule_id'));
if ($_POST["drp_action"] == "1") { /* associate */
for ($i=0;($i<count($selected_items));$i++) {
/* ================= input validation ================= */
input_validate_input_number($selected_items[$i]);
/* ==================================================== */
db_execute("REPLACE INTO plugin_rrdexport_datasource (local_data_id, schedule) VALUES (" . $selected_items[$i] . ", " . $_POST['schedule_id'] . ")");
}
}elseif ($_POST["drp_action"] == "2") { /* disassociate */
for ($i=0;($i<count($selected_items));$i++) {
/* ================= input validation ================= */
input_validate_input_number($selected_items[$i]);
/* ==================================================== */
db_execute("DELETE FROM plugin_rrdexport_datasource WHERE local_data_id=" . $selected_items[$i] . " AND schedule=" . $_POST['schedule_id']);
}
}
header("Location: rrdexport.php?action=edit&tab=data_local&id=" . get_request_var_request("schedule_id"));
exit;
}else{
api_plugin_hook_function('rrdexport_actions_execute');
}
}
/* setup some variables */
$list = "";
$array = array();
$schedule_list_name = "";
if (isset($_POST["schedule_id"])) {
$schedule_list_name = db_fetch_cell("SELECT name FROM plugin_rrdexport_schedules WHERE id=" . $_POST["schedule_id"]);
}
if (isset($_POST["save_schedule_list"])) {
/* loop through each of the schedule lists selected on the previous page and get more info about them */
while (list($var,$val) = each($_POST)) {
if (preg_match("/^chk_([0-9]+)$/", $var, $matches)) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
$list .= "<li><b>" . db_fetch_cell("SELECT name FROM plugin_rrdexport_schedules WHERE id=" . $matches[1]) . "</b></li>";
$array[] = $matches[1];
}
}
include_once("./include/top_header.php");
html_start_box("<strong>" . $schedule_actions{$_POST["drp_action"]} . " $schedule_list_name</strong>", "60%", $colors["header_panel"], "3", "center", "");
print "<form action='rrdexport.php' method='post'>\n";
if (sizeof($array)) {
if ($_POST["drp_action"] == "1") { /* delete */
print " <tr>
<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
<p>When you click \"Continue\", the following RRD Export Schedule(s) will be Deleted. Any Datasource(s) Associated with this Schedule will be lost.</p>
<ul>$list</ul>
</td>
</tr>\n";
$save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Delete RRD Export Schedule(s)'>";
}elseif ($_POST["drp_action"] == "2") { /* run */
print " <tr>
<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
<p>When you click \"Continue\", the following RRD Export Schedule(s) will be Run.</p>
<ul>$list</ul>
</td>
</tr>\n";
$save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Run RRD Export Schedule(s)'>";
}
} else {
print "<tr><td bgcolor='#" . $colors["form_alternate1"]. "'><span class='textError'>You must select at least one RRD Export Schedule.</span></td></tr>\n";
$save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
}
print " <tr>
<td align='right' bgcolor='#eaeaea'>
<input type='hidden' name='action' value='actions'>
<input type='hidden' name='save_schedule_list' value='1'>
<input type='hidden' name='selected_items' value='" . (isset($array) ? serialize($array) : '') . "'>
<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>
$save_html
</td>
</tr>\n";
html_end_box();
include_once("./include/bottom_footer.php");
}elseif (isset($_POST["save_datasource_list"])) {
/* loop through each of the notification lists selected on the previous page and get more info about them */
while (list($var,$val) = each($_POST)) {
if (preg_match("/^chk_([0-9]+)$/", $var, $matches)) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
$list .= "<li><b>" . db_fetch_cell("SELECT name_cache FROM data_template_data WHERE local_data_id = " . $matches[1]) . "</b></li>";
$array[] = $matches[1];
}
}
include_once("./include/top_header.php");
html_start_box("<strong>" . $assoc_actions{$_POST["drp_action"]} . " Datasource(s)</strong>", "60%", $colors["header_panel"], "3", "center", "");
print "<form action='rrdexport.php' method='post'>\n";
if (sizeof($array)) {
if ($_POST["drp_action"] == "1") { /* associate */
print " <tr>
<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
<p>When you click \"Continue\", the RRD Export Schedule '<b>" . $schedule_list_name . "</b>' will be associated with the Datasource(s) below.</p>
<ul>$list</ul>
</td>
</tr>\n";
$save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Associate Notification List(s)'>";
}elseif ($_POST["drp_action"] == "2") { /* disassociate */
print " <tr>
<td class='textArea' bgcolor='#" . $colors["form_alternate1"]. "'>
<p>When you click \"Continue\", the RRD Export Schedule '<b>" . $schedule_list_name . "</b>' will be disassociated from the Datasource(s) below.</p>
<ul>$list</ul>
</td>
</tr>\n";
$save_html = "<input type='button' value='Cancel' onClick='window.history.back()'> <input type='submit' value='Continue' title='Disassociate Notification List(s)'>";
}
} else {
print "<tr><td bgcolor='#" . $colors["form_alternate1"]. "'><span class='textError'>You must select at least one Datasource.</span></td></tr>\n";
$save_html = "<input type='button' value='Return' onClick='window.history.back()'>";
}
print " <tr>
<td align='right' bgcolor='#eaeaea'>
<input type='hidden' name='action' value='actions'>
<input type='hidden' name='schedule_id' value='". $_POST['schedule_id'] . "'>
<input type='hidden' name='save_datasource_list' value='1'>
<input type='hidden' name='selected_items' value='" . (isset($array) ? serialize($array) : '') . "'>
<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>
$save_html
</td>
</tr>\n";
html_end_box();
include_once("./include/bottom_footer.php");
} else {
api_plugin_hook_function('rrdexport_actions_prepare');
}
}
function schedule_edit() {
global $colors, $config, $tabs, $sc_intervals, $cf_types;
input_validate_input_number(get_request_var("id"));
/* set the default tab */
load_current_session_value("tab", "sess_rrdexport_tab", "general");
$current_tab = $_REQUEST["tab"];
if (sizeof($tabs) && isset($_REQUEST['id'])) {
/* draw the tabs */
print "<table class='tabs' width='100%' cellspacing='0' cellpadding='3' align='center'><tr>\n";
foreach (array_keys($tabs) as $tab_short_name) {
print "<td style='padding:3px 10px 2px 5px;background-color:" . (($tab_short_name == $current_tab) ? "silver;" : "#DFDFDF;") .
"white-space:nowrap;'" .
" width='1%' " .
" align='center' class='tab'>
<span class='textHeader'><a href='" . htmlspecialchars($config['url_path'] .
"plugins/rrdexport/rrdexport.php?action=edit&id=" . get_request_var_request('id') .
"&tab=" . $tab_short_name) .
"'>$tabs[$tab_short_name]</a></span>
</td>\n
<td width='1'></td>\n";
}
print "<td></td>\n</tr></table>\n";
}
if (isset($_REQUEST['id'])) {
$id = get_request_var_request('id');
$rrdexport_item_data = db_fetch_row('SELECT * FROM plugin_rrdexport_schedules WHERE id = ' . $id);
} else {
$id = 0;
$rrdexport_item_data = array('id' => $id, 'name' => 'New RRD Export Schedule', 'cf_type' => 'AVERAGE', 'enabled' => 'on', 'stime' => time(), 'sc_interval' => 86400);
}
$header_label = get_header_label();
if ($_REQUEST["tab"] == "general") {
html_start_box("<strong>General Settings</strong> " . htmlspecialchars($header_label), "100%", $colors["header"], "3", "center", "");
$form_array = array(
'general_header' => array(
'friendly_name' => 'RRD Export Schedule',
'method' => 'spacer',
),
'name' => array(
'friendly_name' => 'Schedule Name',
'method' => 'textbox',
'max_length' => 100,
'default' => $rrdexport_item_data['name'],
'description' => 'Name that represent these set of export',
'value' => isset($rrdexport_item_data['name']) ? $rrdexport_item_data['name'] : ''
),
'enabled' => array(
'friendly_name' => 'Enabled',
'method' => 'checkbox',
'default' => 'on',
'description' => 'Whether or not this schedule will be run.',
'value' => isset($rrdexport_item_data['enabled']) ? $rrdexport_item_data['enabled'] : ''
),
'cf_type' => array(
'friendly_name' => 'Rrd CF Values',
'method' => 'drop_array',
'array' => $cf_types,
'default' => 'AVERAGE',
'description' => 'This is the interval in which the start time will repeat.',
'value' => isset($rrdexport_item_data['cf_type']) ? $rrdexport_item_data['cf_type'] : 'AVERAGE'
),
'sc_interval' => array(
'friendly_name' => 'Interval',
'method' => 'drop_array',
'array' => $sc_intervals,
'default' => 86400,
'description' => 'This is the interval in which the start time will repeat.',
'value' => isset($rrdexport_item_data['sc_interval']) ? $rrdexport_item_data['sc_interval'] : 86400
),
'stime' => array(
'friendly_name' => 'Start Time',
'method' => 'textbox',
'max_length' => 100,
'description' => 'The start date / time for this schedule. Most date / time formats accepted.',
'default' => date("F j, Y, G:i", time()),
'value' => isset($rrdexport_item_data['stime']) ? date("l, F j, Y, G:i", $rrdexport_item_data['stime']) : ''
),
"save_component" => array(
"method" => "hidden",
"value" => "1"
),
"save" => array(
"method" => "hidden",
"value" => "edit"
),
"id" => array(
"method" => "hidden",
"value" => $id
)
);
draw_edit_form(
array(
"config" => array(),
"fields" => $form_array
)
);
html_end_box();
form_save_button('rrdexport.php', 'return');
?>
<script type="text/javascript" src="<?php echo $config['url_path']; ?>include/jscalendar/calendar.js"></script>
<script type="text/javascript" src="<?php echo $config['url_path']; ?>include/jscalendar/lang/calendar-en.js"></script>
<script type="text/javascript" src="<?php echo $config['url_path']; ?>include/jscalendar/calendar-setup.js"></script>
<script type='text/javascript'>
// Initialize the calendar
calendar=null;
// This function displays the calendar associated to the input field 'id'
function showCalendar(id) {
var el = document.getElementById(id);
if (calendar != null) {
// we already have some calendar created
calendar.hide(); // so we hide it first.
} else {
// first-time call, create the calendar.
var cal = new Calendar(true, null, selected, closeHandler);
cal.weekNumbers = false; // Do not display the week number
cal.showsTime = true; // Display the time
cal.time24 = true; // Hours have a 24 hours format
cal.showsOtherMonths = false; // Just the current month is displayed
calendar = cal; // remember it in the global var
cal.setRange(1900, 2070); // min/max year allowed.
cal.create();
}
calendar.setDateFormat('%A, %B %d, %Y, %H:%S'); // set the specified date format
calendar.parseDate(el.value); // try to parse the text in field
calendar.sel = el; // inform it what input field we use
// Display the calendar below the input field
calendar.showAtElement(el, "Br"); // show the calendar
return false;
}
// This function update the date in the input field when selected
function selected(cal, date) {
cal.sel.value = date; // just update the date in the input field.
}
// This function gets called when the end-user clicks on the 'Close' button.
// It just hides the calendar without destroying it.
function closeHandler(cal) {
cal.hide(); // hide the calendar
calendar = null;
}
stime.onclick=new Function("return showCalendar('stime')");
</script>
<?php
}elseif ($_REQUEST["tab"] == "data_local") {
datasource_list($header_label);
}else{
api_plugin_hook_function('rrdexport_show_tab', $header_label);
}
}
function datasource_list($header_label) {
global $colors, $assoc_actions, $item_rows, $config;
/* ================= input validation ================= */
input_validate_input_number(get_request_var_request("ds_rows"));
input_validate_input_number(get_request_var_request("host_id"));
input_validate_input_number(get_request_var_request("template_id"));
input_validate_input_number(get_request_var_request("method_id"));
input_validate_input_number(get_request_var_request("page"));
/* ==================================================== */
/* clean up search string */
if (isset($_REQUEST["filter"])) {
$_REQUEST["filter"] = sanitize_search_string(get_request_var("filter"));
# $_REQUEST["filter"] = sanitize_search_string(get_request_var_request("filter"));
}
/* clean up sort_column string */
if (isset($_REQUEST["sort_column"])) {
$_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column"));
}
/* clean up sort_direction string */
if (isset($_REQUEST["sort_direction"])) {
$_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction"));
}
/* clean up associated string */
if (isset($_REQUEST["associated"])) {
$_REQUEST["associated"] = sanitize_search_string(get_request_var("associated"));
#$_REQUEST["associated"] = sanitize_search_string(get_request_var_request("associated"));
}
/* if the user pushed the 'clear' button */
if (isset($_REQUEST["clear_x"])) {
kill_session_var("sess_rrdexport_current_page");
kill_session_var("sess_rrdexport_filter");
kill_session_var("sess_rrdexport_sort_column");
kill_session_var("sess_rrdexport_sort_direction");
kill_session_var("sess_rrdexport_rows");
kill_session_var("sess_rrdexport_host_id");
kill_session_var("sess_rrdexport_template_id");
kill_session_var("sess_rrdexport_method_id");
kill_session_var("sess_rrdexport_associated");
unset($_REQUEST["page"]);
unset($_REQUEST["filter"]);
unset($_REQUEST["sort_column"]);
unset($_REQUEST["sort_direction"]);
unset($_REQUEST["ds_rows"]);
unset($_REQUEST["host_id"]);
unset($_REQUEST["template_id"]);
unset($_REQUEST["method_id"]);
unset($_REQUEST["associated"]);
}
/* remember these search fields in session vars so we don't have to keep passing them around */
load_current_session_value("page", "sess_rrdexport_current_page", "1");
load_current_session_value("filter", "sess_rrdexport_filter", "");
load_current_session_value("sort_column", "sess_rrdexport_sort_column", "name_cache");
load_current_session_value("sort_direction", "sess_rrdexport_sort_direction", "ASC");
load_current_session_value("ds_rows", "sess_rrdexport_rows", read_config_option("num_rows_data_source"));
load_current_session_value("host_id", "sess_rrdexport_host_id", "-1");
load_current_session_value("template_id", "sess_rrdexport_template_id", "-1");
load_current_session_value("method_id", "sess_rrdexport_method_id", "-1");
load_current_session_value("associated", "sess_rrdexport_associated", "true");
$host = db_fetch_row("select hostname from host where id=" . get_request_var_request("host_id"));
/* if the number of rows is -1, set it to the default */
if (get_request_var_request("ds_rows") == -1) {
$_REQUEST["ds_rows"] = read_config_option("num_rows_data_source");
}
?>
<script type="text/javascript">
<!--
function applyDSFilterChange(objForm) {
strURL = '?tab=data_local&action=edit&id=<?php print get_request_var_request('id');?>'
strURL = strURL + '&host_id=' + objForm.host_id.value;
strURL = strURL + '&filter=' + objForm.filter.value;
strURL = strURL + '&ds_rows=' + objForm.ds_rows.value;
strURL = strURL + '&template_id=' + objForm.template_id.value;
strURL = strURL + '&method_id=' + objForm.method_id.value;
strURL = strURL + '&associated=' + objForm.associated.checked;
document.location = strURL;
}
function clearViewDeviceFilterChange(objForm) {
strURL = '?tab=data_local&action=edit&id=<?php print get_request_var_request('id');?>&clear_x=true'
document.location = strURL;
}
-->
</script>
<?php
html_start_box("<strong>Associated Data Sources</strong> " . htmlspecialchars($header_label), "100%", $colors["header"], "3", "center", "");
?>
<tr bgcolor="#<?php print $colors["panel"];?>">
<td>
<form name="form_data_sources" method="get" action="rrdexport.php">
<table cellpadding="0" cellspacing="0">
<tr>
<td width="50">
Host:
</td>
<td>
<select name="host_id" onChange="applyDSFilterChange(document.form_data_sources)">
<option value="-1"<?php if (get_request_var_request("host_id") == "-1") {?> selected<?php }?>>Any</option>
<option value="0"<?php if (get_request_var_request("host_id") == "0") {?> selected<?php }?>>None</option>
<?php
$hosts = db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname");
if (sizeof($hosts) > 0) {
foreach ($hosts as $host) {
print "<option value='" . $host["id"] . "'"; if (get_request_var_request("host_id") == $host["id"]) { print " selected"; } print ">" . title_trim(htmlspecialchars($host["name"]), 40) . "</option>\n";
}
}
?>
</select>
</td>
<td width="50">
Template:
</td>
<td width="1">
<select name="template_id" onChange="applyDSFilterChange(document.form_data_sources)">
<option value="-1"<?php if (get_request_var_request("template_id") == "-1") {?> selected<?php }?>>Any</option>
<option value="0"<?php if (get_request_var_request("template_id") == "0") {?> selected<?php }?>>None</option>
<?php
$templates = db_fetch_assoc("SELECT DISTINCT data_template.id, data_template.name
FROM data_template
INNER JOIN data_template_data
ON data_template.id=data_template_data.data_template_id
WHERE data_template_data.local_data_id>0
ORDER BY data_template.name");
if (sizeof($templates) > 0) {
foreach ($templates as $template) {
print "<option value='" . $template["id"] . "'"; if (get_request_var_request("template_id") == $template["id"]) { print " selected"; } print ">" . title_trim(htmlspecialchars($template["name"]), 40) . "</option>\n";
}
}
?>
</select>
</td>
<td nowrap style='white-space: nowrap;'>
<input type="submit" value="Go" title="Set/Refresh Filters">
<input type="submit" name="clear_x" value="Clear" title="Clear Filters">
</td>
</tr>
<tr>
<td width="50">
Method:
</td>
<td width="1">
<select name="method_id" onChange="applyDSFilterChange(document.form_data_sources)">
<option value="-1"<?php if (get_request_var_request("method_id") == "-1") {?> selected<?php }?>>Any</option>
<option value="0"<?php if (get_request_var_request("method_id") == "0") {?> selected<?php }?>>None</option>
<?php
$methods = db_fetch_assoc("SELECT DISTINCT data_input.id, data_input.name
FROM data_input
INNER JOIN data_template_data
ON data_input.id=data_template_data.data_input_id
WHERE data_template_data.local_data_id>0
ORDER BY data_input.name");
if (sizeof($methods) > 0) {
foreach ($methods as $method) {
print "<option value='" . $method["id"] . "'"; if (get_request_var_request("method_id") == $method["id"]) { print " selected"; } print ">" . title_trim(htmlspecialchars($method["name"]), 40) . "</option>\n";
}
}
?>
</select>
</td>
<td nowrap style='white-space: nowrap;' width="50">
Rows per Page:
</td>
<td width="1">
<select name="ds_rows" onChange="applyDSFilterChange(document.form_data_sources)">
<option value="-1"<?php if (get_request_var_request("ds_rows") == "-1") {?> selected<?php }?>>Default</option>
<?php
if (sizeof($item_rows) > 0) {
foreach ($item_rows as $key => $value) {
print "<option value='" . $key . "'"; if (get_request_var_request("ds_rows") == $key) { print " selected"; } print ">" . htmlspecialchars($value) . "</option>\n";
}
}
?>
</select>
</td>
</tr>
</table>
<table cellpadding="1" cellspacing="0">
<tr>
<td width="50">
Search:
</td>
<td width="1">
<input type="text" name="filter" size="40" value="<?php print htmlspecialchars(get_request_var_request("filter"));?>">
</td>
<td>
<input type='checkbox' name='associated' id='associated' onChange='applyDSFilterChange(document.form_data_sources)' <?php print ($_REQUEST['associated'] == 'true' || $_REQUEST['associated'] == 'on' ? 'checked':'');?>>
</td>
<td width="50">
Associated?
</td>
</tr>
</table>
<input type='hidden' name='tab' value='data_local'>
<input type='hidden' name='action' value='edit'>
<input type='hidden' name='page' value='1'>
<input type='hidden' name='id' value='<?php print get_request_var_request('id');?>'>
</form>
</td>
</tr>
<?php
html_end_box();
/* form the 'where' clause for our main sql query */
if (strlen(get_request_var_request("filter"))) {
$sql_where1 = "AND (data_template_data.name_cache like '%%" . get_request_var_request("filter") . "%%'" .
" OR data_template_data.local_data_id like '%%" . get_request_var_request("filter") . "%%'" .
" OR data_template.name like '%%" . get_request_var_request("filter") . "%%'" .
" OR data_input.name like '%%" . get_request_var_request("filter") . "%%')";
$sql_where2 = "AND (data_template_data.name_cache like '%%" . get_request_var_request("filter") . "%%'" .
" OR data_template.name like '%%" . get_request_var_request("filter") . "%%')";
}else{
$sql_where1 = "";
$sql_where2 = "";
}
if (get_request_var_request("host_id") == "-1") {
/* Show all items */
}elseif (get_request_var_request("host_id") == "0") {
$sql_where1 .= " AND data_local.host_id=0";
$sql_where2 .= " AND data_local.host_id=0";
}elseif (!empty($_REQUEST["host_id"])) {
$sql_where1 .= " AND data_local.host_id=" . get_request_var_request("host_id");
$sql_where2 .= " AND data_local.host_id=" . get_request_var_request("host_id");
}
if (get_request_var_request("template_id") == "-1") {
/* Show all items */
}elseif (get_request_var_request("template_id") == "0") {
$sql_where1 .= " AND data_template_data.data_template_id=0";
$sql_where2 .= " AND data_template_data.data_template_id=0";
}elseif (!empty($_REQUEST["host_id"])) {
$sql_where1 .= " AND data_template_data.data_template_id=" . get_request_var_request("template_id");
$sql_where2 .= " AND data_template_data.data_template_id=" . get_request_var_request("template_id");
}
if (get_request_var_request("method_id") == "-1") {
/* Show all items */
}elseif (get_request_var_request("method_id") == "0") {
$sql_where1 .= " AND data_template_data.data_input_id=0";
$sql_where2 .= " AND data_template_data.data_input_id=0";
}elseif (!empty($_REQUEST["method_id"])) {
$sql_where1 .= " AND data_template_data.data_input_id=" . get_request_var_request("method_id");
$sql_where2 .= " AND data_template_data.data_input_id=" . get_request_var_request("method_id");
}
if (get_request_var_request("associated") == "false") {
/* Show all items */
} else {
$sql_where1 .= " AND plugin_rrdexport_datasource.schedule=" . get_request_var_request('id');
}
$total_rows = sizeof(db_fetch_assoc("SELECT
data_local.id
FROM (data_local,data_template_data)
LEFT JOIN data_input
ON (data_input.id=data_template_data.data_input_id)
LEFT JOIN data_template
ON (data_local.data_template_id=data_template.id)
LEFT JOIN plugin_rrdexport_datasource
ON (data_local.id=plugin_rrdexport_datasource.local_data_id)
WHERE data_local.id=data_template_data.local_data_id
$sql_where1"));
$poller_intervals = array_rekey(db_fetch_assoc("SELECT data_template_data.local_data_id AS id,
Min(data_template_data.rrd_step*rra.steps) AS poller_interval
FROM data_template
INNER JOIN (data_local
INNER JOIN ((data_template_data_rra
INNER JOIN data_template_data ON data_template_data_rra.data_template_data_id=data_template_data.id)
INNER JOIN rra ON data_template_data_rra.rra_id = rra.id) ON data_local.id = data_template_data.local_data_id) ON data_template.id = data_template_data.data_template_id
$sql_where2
GROUP BY data_template_data.local_data_id"), "id", "poller_interval");
$data_sources = db_fetch_assoc("SELECT
data_template_data.local_data_id,
data_template_data.name_cache,
data_template_data.active,
data_input.name as data_input_name,
data_template.name as data_template_name,
data_local.host_id
FROM (data_local,data_template_data)
LEFT JOIN data_input ON (data_input.id=data_template_data.data_input_id)
LEFT JOIN data_template ON (data_local.data_template_id=data_template.id)
LEFT JOIN plugin_rrdexport_datasource ON plugin_rrdexport_datasource.local_data_id = data_local.id
WHERE data_local.id=data_template_data.local_data_id
$sql_where1
GROUP BY data_local.id
LIMIT " . (get_request_var_request("ds_rows")*(get_request_var_request("page")-1)) . "," . get_request_var_request("ds_rows"));
print "<form name='chk' method='post' action='rrdexport.php'>\n";
html_start_box("", "100%", $colors["header"], "3", "center", "");
/* generate page list */
$url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, get_request_var_request("ds_rows"), $total_rows, "rrdexport.php?tab=data_local&action=edit&id=". get_request_var_request('id') ."&filter=" . get_request_var_request("filter") . "&host_id=" . get_request_var_request("host_id"));
$nav = "<tr bgcolor='#" . $colors["header"] . "'>
<td colspan='7'>
<table width='100%' cellspacing='0' cellpadding='0' border='0'>
<tr>
<td align='left' class='textHeaderDark'>
<strong><< "; if (get_request_var_request("page") > 1) { $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("rrdexport.php?tab=data_local&action=edit&id=". get_request_var_request('id') ."&associated=" . get_request_var_request("associated") ."&filter=" . get_request_var_request("filter") . "&host_id=" . get_request_var_request("host_id") . "&page=" . (get_request_var_request("page")-1)) . "'>"; } $nav .= "Previous"; if (get_request_var_request("page") > 1) { $nav .= "</a>"; } $nav .= "</strong>
</td>\n
<td align='center' class='textHeaderDark'>
Showing Rows " . ((get_request_var_request("ds_rows")*(get_request_var_request("page")-1))+1) . " to " . ((($total_rows < get_request_var_request("ds_rows")) || ($total_rows < (get_request_var_request("ds_rows")*get_request_var_request("page")))) ? $total_rows : (get_request_var_request("ds_rows")*get_request_var_request("page"))) . " of $total_rows [$url_page_select]
</td>\n
<td align='right' class='textHeaderDark'>
<strong>"; if ((get_request_var_request("page") * get_request_var_request("ds_rows")) < $total_rows) { $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("rrdexport.php?tab=data_local&action=edit&id=". get_request_var_request('id') ."&associated=" . get_request_var_request("associated") ."&filter=" . get_request_var_request("filter") . "&host_id=" . get_request_var_request("host_id") . "&page=" . (get_request_var_request("page")+1)) . "'>"; } $nav .= "Next"; if ((get_request_var_request("page") * get_request_var_request("ds_rows")) < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong>
</td>\n
</tr>
</table>
</td>
</tr>\n";
print $nav;
html_header_checkbox(array("Scheduled","Name", "ID", "Data Input Method", "Poller Interval", "Active", "Template Name"));
$i = 0;
if (sizeof($data_sources) > 0) {
foreach ($data_sources as $data_source) {
$data_source["data_template_name"] = htmlspecialchars($data_source["data_template_name"]);
$data_name_cache = title_trim(htmlspecialchars($data_source["name_cache"]), read_config_option("max_title_data_source"));
if (trim(get_request_var_request("filter") != "")) {
$data_source['data_input_name'] = (preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", htmlspecialchars($data_source['data_input_name'])));
$data_source['data_template_name'] = preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", $data_source['data_template_name']);
$data_name_cache = preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", ($data_name_cache));
}
/* keep copy of data source for comparison */
$data_source_orig = $data_source;
$data_source = api_plugin_hook_function('data_sources_table', $data_source);
/* we're escaping strings here, so no need to escape them on form_selectable_cell */
if ($data_source_orig["data_template_name"] != $data_source["data_template_name"]) {
/* was changed by plugin, plugin has to take care for html-escaping */
$data_template_name = ((empty($data_source["data_template_name"])) ? "<em>None</em>" : $data_source["data_template_name"]);
} else {
/* we take care of html-escaping */
$data_template_name = ((empty($data_source["data_template_name"])) ? "<em>None</em>" : htmlspecialchars($data_source["data_template_name"]));
}
if ($data_source_orig["data_input_name"] != $data_source["data_input_name"]) {
/* was changed by plugin, plugin has to take care for html-escaping */
$data_input_name = ((empty($data_source["data_input_name"])) ? "<em>None</em>" : $data_source["data_input_name"]);
} else {
/* we take care of html-escaping, see above */
$data_input_name = ((empty($data_source["data_input_name"])) ? "<em>External</em>" : $data_source["data_input_name"]);
}
$poller_interval = ((isset($poller_intervals[$data_source["local_data_id"]])) ? $poller_intervals[$data_source["local_data_id"]] : 0);
if (db_fetch_cell("SELECT local_data_id FROM plugin_rrdexport_datasource WHERE schedule = " . get_request_var_request('id') . " AND local_data_id=" . $data_source["local_data_id"])) {
$schedule_names = '<span style="color:green;font-weight:bold;">Current List</span>';
} else {
$schedule_names = '';
}
if (sizeof($lists = db_fetch_assoc("SELECT name FROM plugin_rrdexport_schedules INNER JOIN plugin_rrdexport_datasource ON plugin_rrdexport_schedules.id=plugin_rrdexport_datasource.schedule WHERE local_data_id=" . $data_source["local_data_id"] . " AND plugin_rrdexport_schedules.id != " . get_request_var_request('id')))) {
foreach($lists as $sc) {
$schedule_names .= (strlen($schedule_names) ? ", ":"") . "<span style='color:purple;font-weight:bold;'>" . $sc['name'] . "</span>";
}
}
if ($schedule_names == '') {
$schedule_names = '<span style="color:red;font-weight:bold;">No Schedules</span>';
}
form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $data_source["local_data_id"]); $i++;
form_selectable_cell($schedule_names, $data_source['local_data_id']);
form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars($config['url_path'] . "data_sources.php?action=ds_edit&id=" . $data_source["local_data_id"]) . "' title='" . $data_source["name_cache"] . "'>" . ((get_request_var_request("filter") != "") ? preg_replace("/(" . preg_quote(get_request_var_request("filter"), "/") . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", title_trim(htmlspecialchars($data_source["name_cache"]), read_config_option("max_title_data_source"))) : title_trim(htmlspecialchars($data_source["name_cache"]), read_config_option("max_title_data_source"))) . "</a>", $data_source["local_data_id"]);
form_selectable_cell($data_source['local_data_id'], $data_source['local_data_id']);
form_selectable_cell($data_input_name, $data_source["local_data_id"]);
form_selectable_cell(get_poller_interval($poller_interval), $data_source["local_data_id"]);
form_selectable_cell(($data_source['active'] == "on" ? "Yes" : "No"), $data_source["local_data_id"]);
form_selectable_cell($data_template_name, $data_source["local_data_id"]);
form_checkbox_cell($data_source["name_cache"], $data_source["local_data_id"]);
form_end_row();
}
/* put the nav bar on the bottom as well */
print $nav;
}else{
print "<tr><td><em>No Data Sources</em></td></tr>";
}
html_end_box(false);
form_hidden_box("schedule_id", get_request_var_request("id"), "");
form_hidden_box("save_datasource_list", "1", "");
/* draw the dropdown containing a list of available actions for this form */
draw_actions_dropdown($assoc_actions);
print "</form>\n";
}
function get_poller_interval($seconds) {
if ($seconds == 0) {
return "<em>External</em>";
}else if ($seconds < 60) {
return "<em>" . $seconds . " Seconds</em>";
}else if ($seconds == 60) {
return "1 Minute";
}else{
return "<em>" . ($seconds / 60) . " Minutes</em>";
}
}
function get_header_label() {
if (!empty($_REQUEST["id"])) {
$_GET["id"] = $_REQUEST["id"];
$list = db_fetch_row("SELECT * FROM plugin_rrdexport_schedules WHERE id=" . $_REQUEST["id"]);
$header_label = "[edit: " . $list["name"] . "]";
} else {
$header_label = "[new]";
}
return $header_label;
}
function schedule_list() {
global $colors, $schedule_actions, $sc_intervals;
html_start_box('<strong>RRD Export Schedules</strong>', '100%', $colors['header'], '3', 'center', 'rrdexport.php?tab=general&action=edit');
html_header_checkbox(array('Name', 'CF', 'Start', 'Last Execute', 'Interval', 'Enabled'));
$schedules = db_fetch_assoc('SELECT * FROM plugin_rrdexport_schedules ORDER BY name');
$i = 0;
if (sizeof($schedules) > 0) {
foreach ($schedules as $schedule) {
form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $schedule["id"]); $i++;
form_selectable_cell('<a class="linkEditMain" href="rrdexport.php?action=edit&id=' . $schedule['id'] . '">' . $schedule['name'] . '</a>', $schedule["id"]);
form_selectable_cell($schedule['cf_type'], $schedule["id"]);
form_selectable_cell(date("F j, Y, G:i", $schedule['stime']), $schedule["id"]);
if ($schedule['ltime'] == 0)
form_selectable_cell("Never", $schedule["id"]);
else
form_selectable_cell(date("F j, Y, G:i", $schedule['ltime']), $schedule["id"]);
form_selectable_cell($sc_intervals[$schedule['sc_interval']], $schedule["id"]);
form_selectable_cell($schedule['enabled'], $schedule["id"]);
form_checkbox_cell($schedule['name'], $schedule["id"]);
form_end_row();
}
}else{
print "<tr><td><em>No RRD Export Schedules</em></td></tr>\n";
}
html_end_box(false);
form_hidden_box('save_schedule_list', '1', '');
draw_actions_dropdown($schedule_actions);
print "</form>\n";
}