-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsetup.php
836 lines (698 loc) · 27.4 KB
/
setup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2024 The Cacti Group |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDtool-based Graphing Solution |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See |
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
function plugin_reportit_install() {
api_plugin_register_hook('reportit', 'top_header_tabs', 'reportit_show_tab', 'setup.php');
api_plugin_register_hook('reportit', 'top_graph_header_tabs', 'reportit_show_tab', 'setup.php');
api_plugin_register_hook('reportit', 'draw_navigation_text', 'reportit_draw_navigation_text', 'setup.php');
api_plugin_register_hook('reportit', 'config_arrays', 'reportit_config_arrays', 'setup.php');
api_plugin_register_hook('reportit', 'config_settings', 'reportit_config_settings', 'setup.php');
api_plugin_register_hook('reportit', 'poller_bottom', 'reportit_poller_bottom', 'setup.php');
api_plugin_register_hook('reportit', 'clog_regex_array', 'reportit_clog_regex_array', 'setup.php');
api_plugin_register_realm('reportit', 'view.php,charts.php', 'ReportIt - Report Viewing', 1);
api_plugin_register_realm('reportit', 'reportit.php,view.php', 'ReportIt - Create Reports', 1);
api_plugin_register_realm('reportit', 'templates.php', 'ReportIt - Manage Reports', 1);
$realm_array = array(
__('ReportIt - Report Viewing', 'reportit'),
__('ReportIt - Create Reports', 'reportit'),
__('ReportIt - Manage Reports', 'reportit')
);
reportit_system_setup();
}
function plugin_reportit_uninstall() {
db_execute('DROP TABLE IF EXISTS plugin_reportit_cache_measurands');
db_execute('DROP TABLE IF EXISTS plugin_reportit_cache_reports');
db_execute('DROP TABLE IF EXISTS plugin_reportit_cache_variables');
db_execute('DROP TABLE IF EXISTS plugin_reportit_data_items');
db_execute('DROP TABLE IF EXISTS plugin_reportit_data_source_items');
db_execute('DROP TABLE IF EXISTS plugin_reportit_measurands');
db_execute('DROP TABLE IF EXISTS plugin_reportit_presets');
db_execute('DROP TABLE IF EXISTS plugin_reportit_recipients');
db_execute('DROP TABLE IF EXISTS plugin_reportit_reports');
db_execute('DROP TABLE IF EXISTS plugin_reportit_rvars');
db_execute('DROP TABLE IF EXISTS plugin_reportit_templates');
db_execute('DROP TABLE IF EXISTS plugin_reportit_variables');
db_execute('DROP TABLE IF EXISTS plugin_reportit_data_template_groups');
return true;
}
function plugin_reportit_check_config() {
return reportit_check_upgrade();
}
function plugin_reportit_upgrade() {
reportit_check_upgrade();
return true;
}
function plugin_reportit_version() {
$info = parse_ini_file(CACTI_PATH_BASE . '/plugins/reportit/INFO', true);
return $info['info'];
}
function reportit_check_upgrade() {
$files = array('index.php', 'plugins.php', 'poller_reportit.php');
if (isset($_SERVER['PHP_SELF']) && !in_array(basename($_SERVER['PHP_SELF']), $files)) {
return;
}
$current = plugin_reportit_version();
$current = $current['version'];
$old = db_fetch_row("SELECT * FROM plugin_config WHERE directory='reportit'");
$tables = db_fetch_assoc("SHOW TABLE STATUS WHERE `Name` LIKE 'reportit%'");
if (cacti_sizeof($old) && $current == $old['version']){
/* ReportIt is up to date */
return true;
} elseif (cacti_sizeof($old) && $current != $old['version']) {
if ($old['status'] == 1 || $old['status'] == 4) {
/* re-register hooks */
//plugin_reportit_install();
/* perform data base upgrade */
require_once(CACTI_PATH_BASE . '/plugins/reportit/system/install.php');
require_once(CACTI_PATH_BASE . '/plugins/reportit/system/upgrade.php');
reportit_system_upgrade($old['version']);
/* re-register plugins hooks */
plugin_reportit_install();
}
$info = plugin_reportit_version();
$id = db_fetch_cell("SELECT id FROM plugin_config WHERE directory='reportit'");
db_execute_prepared('UPDATE plugin_config SET
name = ?, author = ?, webpage = ?, version = ?
WHERE id = ?',
array(
$info['longname'],
$info['author'],
$info['homepage'],
$info['version'],
$id
)
);
return true;
}
}
function reportit_upgrade_requirements() {
return true;
}
function reportit_draw_navigation_text ($nav) {
$nav['reportsit.php:'] = array(
'title' => __('Reports', 'reportit'),
'mapping' => 'index.php:',
'url' => 'reportsit.php',
'level' => '1');
$nav['reportsit.php:save'] = array(
'title' => __('(Edit)', 'reportit'),
'mapping' => 'index.php:',
'url' => 'templates.php',
'level' => '2');
$nav['reportsit.php:report_add'] = array(
'title' => __('Add', 'reportit'),
'mapping' => 'index.php:',
'url' => 'templates.php',
'level' => '2');
$nav['reportsit.php:report_edit'] = array(
'title' => __('(Edit)', 'reportit'),
'mapping' => 'index.php:',
'url' => 'templates.php',
'level' => '2');
$nav['reportsit.php:actions'] = array(
'title' => __('Actions', 'reportit'),
'mapping' => 'index.php:',
'url' => 'templates.php',
'level' => '2');
$nav['rrdlist.php:'] = array(
'title' => __('Data Items', 'reportit'),
'mapping' => 'index.php:,reportsit.php:',
'url' => 'templates.php',
'level' => '2');
$nav['rrdlist.php:save'] = array(
'title' => __('(Edit)', 'reportit'),
'mapping' => 'index.php:,reportsit.php:,rrdlist.php:',
'url' => '',
'level' => '3');
$nav['rrdlist.php:rrdlist_edit'] = array(
'title' => __('(Edit)', 'reportit'),
'mapping' => 'index.php:,reportsit.php:,rrdlist.php:',
'url' => '',
'level' => '3');
$nav['rrdlist.php:actions'] = array(
'title' => __('Actions', 'reportit'),
'mapping' => 'index.php:,reportsit.php:,rrdlist.php:',
'url' => '',
'level' => '3');
$nav['items.php:'] = array(
'title' => __('Add', 'reportit'),
'mapping' => 'index.php:,reportsit.php:,rrdlist.php:',
'url' => 'templates.php',
'level' => '3');
$nav['items.php:save'] = array(
'title' => __('(Edit)', 'reportit'),
'mapping' => 'index.php:,reportsit.php:,rrdlist.php:',
'url' => '',
'level' => '4');
$nav['templates.php:'] = array(
'title' => __('Report Templates', 'reportit'),
'mapping' => 'index.php:',
'url' => 'templates.php',
'level' => '1');
$nav['templates.php:save'] = array(
'title' => __('(Edit)', 'reportit'),
'mapping' => 'index.php:,templates.php:',
'url' => '',
'level' => '2');
$nav['templates.php:template_edit'] = array(
'title' => __('(Edit)', 'reportit'),
'mapping' => 'index.php:,templates.php:',
'url' => '',
'level' => '2');
$nav['templates.php:template_new'] = array(
'title' => __('Add', 'reportit'),
'mapping' => 'index.php:,templates.php:',
'url' => '',
'level' => '2');
$nav['templates.php:template_import_wizard'] = array(
'title' => __('Import', 'reportit'),
'mapping' => 'index.php:,templates.php:',
'url' => '',
'level' => '2');
$nav['templates.php:template_upload_wizard'] = array(
'title' => __('Import', 'reportit'),
'mapping' => 'index.php:,templates.php:',
'url' => '',
'level' => '2');
$nav['templates.php:template_import'] = array(
'title' => __('Export', 'reportit'),
'mapping' => 'index.php:,templates.php:',
'url' => '',
'level' => '2');
$nav['templates.php:template_export'] = array(
'title' => __('Export', 'reportit'),
'mapping' => 'index.php:,templates.php:',
'url' => '',
'level' => '2');
$nav['templates.php:template_export_wizard'] = array(
'title' => __('Export', 'reportit'),
'mapping' => 'index.php:,templates.php:',
'url' => '',
'level' => '2');
$nav['templates.php:actions'] = array(
'title' => __('Actions', 'reportit'),
'mapping' => 'index.php:,templates.php:',
'url' => '',
'level' => '2');
$nav['measurands.php:'] = array(
'title' => __('Metrics', 'reportit'),
'mapping' => 'index.php:,templates.php:',
'url' => 'templates.php',
'level' => '2');
$nav['measurands.php:save'] = array(
'title' => __('(Edit)', 'reportit'),
'mapping' => 'index.php:,templates.php:,measurands.php:',
'url' => '',
'level' => '3');
$nav['measurands.php:measurand_edit'] = array(
'title' => __('(Edit)', 'reportit'),
'mapping' => 'index.php:,templates.php:,measurands.php:',
'url' => '',
'level' => '3');
$nav['measurands.php:actions'] = array(
'title' => __('Actions', 'reportit'),
'mapping' => 'index.php:,templates.php:,measurands.php:',
'url' => '',
'level' => '3');
$nav['variables.php:'] = array(
'title' => __('Variables', 'reportit'),
'mapping' => 'index.php:,templates.php:',
'url' => 'templates.php',
'level' => '2');
$nav['variables.php:save'] = array(
'title' => __('(Edit)', 'reportit'),
'mapping' => 'index.php:,templates.php:,variables.php:',
'url' => '',
'level' => '3');
$nav['variables.php:variable_edit'] = array(
'title' => __('(Edit)', 'reportit'),
'mapping' => 'index.php:,templates.php:,variables.php:',
'url' => '',
'level' => '3');
$nav['variables.php:actions'] = array(
'title' => __('Actions', 'reportit'),
'mapping' => 'index.php:,templates.php:,variables.php:',
'url' => '',
'level' => '3');
$nav['run.php:calculation'] = array(
'title' => __('Report Calculation', 'reportit'),
'mapping' => 'index.php:,reportsit.php:',
'url' => '',
'level' => '2');
$nav['view.php:'] = array(
'title' => __('Public Reports', 'reportit'),
'mapping' => 'index.php:',
'url' => 'view.php',
'level' => '1');
$nav['view.php:show_report'] = array(
'title' => __('Show Report', 'reportit'),
'mapping' => 'index.php:,view.php:',
'url' => '',
'level' => '2');
$nav['view.php:export'] = array(
'title' => __('Export Report', 'reportit'),
'mapping' => 'index.php:,view.php:',
'url' => '',
'level' => '2');
$nav['view.php:show_graphs'] = array(
'title' => __('Show Report', 'reportit'),
'mapping' => 'index.php:,view.php:',
'url' => '',
'level' => '2');
$nav['charts.php:'] = array(
'title' => __('Public Report Charts', 'reportit'),
'mapping' => 'index.php:',
'url' => 'graph.php',
'level' => '1');
$nav['charts.php:bar'] = array(
'title' => __('Bar Chart', 'reportit'),
'mapping' => 'index.php:,graph.php:',
'url' => '',
'level' => '2');
$nav['charts.php:pie'] = array(
'title' => __('Pie Chart', 'reportit'),
'mapping' => 'index.php:,graph.php:',
'url' => '',
'level' => '2');
return $nav;
}
function reportit_config_arrays() {
global $user_auth_realms, $user_auth_realm_filenames, $menu, $messages;
reportit_define_constants();
if (function_exists('auth_augment_roles')) {
auth_augment_roles(__('Normal User'), array('view.php,charts.php'));
auth_augment_roles(__('General Administration'), array('reportsit.php'));
auth_augment_roles(__('System Administration'), array('templates.php', 'measurands.php', 'variables.php'));
}
/* show additional menu entries if plugin is enabled */
if (api_plugin_is_enabled('reportit')) {
$menu[__('Management')]['plugins/reportit/reportit.php'] = __('ReportIt Reports', 'reportit');
$menu[__('Templates')]['plugins/reportit/templates.php'] = __('ReportIt', 'reportit');
$temp = array(
'reportit_templates__1' => array(
'message' => __('No data source item selected', 'reportit'),
'type' => 'error'
),
'reportit_templates__2' => array(
'message' => __('Unselected data source items are still in use', 'reportit'),
'type' => 'error'
),
'reportit_templates__3' => array(
'message' => __('Unable to unlock this template without defined measurands', 'reportit'),
'type' => 'error'
),
);
$messages += $temp;
}
}
function reportit_config_settings() {
global $tabs, $tabs_graphs, $settings, $settings_user, $item_rows;
/* presets */
$datetime = array(__('local', 'reportit'), __('global', 'reportit'));
$csv_column_separator = array(',', ';', 'Tab', 'Blank');
$csv_decimal_separator = array(',', '.');
$operator = array(
__('Power User (Report Owner)', 'reportit'),
__('Super User (Report Admin)', 'reportit')
);
/* setup ReportIt's global configuration area */
$tabs['reports'] = __('Reports', 'reportit');
$temp = array(
'reportit_header1' => array(
'friendly_name' => __('General', 'reportit'),
'method' => 'spacer',
'collapsible' => 'true'
),
'reportit_met' => array(
'friendly_name' => __('Maximum Execution Time (in seconds)', 'reportit'),
'description' => __('Optional: Maximum execution time of one calculation.', 'reportit'),
'method' => 'textbox',
'max_length' => '4',
'default' => '300',
),
'reportit_maxrrdchg' => array(
'friendly_name' => __('Maximum Record Count Change', 'reportit'),
'description' => __('Optional (Auto-Generate RRD List): Do not change RRD List of any Report if Record Count Change is greater than this Number This is to avoid unwanted and disastrous changes on RRD Lists', 'reportit'),
'method' => 'textbox',
'max_length' => '4',
'default' => '100',
),
'reportit_use_tmz' => array(
'friendly_name' => __('Time Zones', 'reportit'),
'description' => __('Enable/Disable the use of time zones for Data Item\'s configuration and report calculation. In the former case server time has to be set up to GMT/UTC!', 'reportit'),
'method' => 'checkbox',
'default' => '',
),
'reportit_show_tmz' => array(
'friendly_name' => __('Show Local Time Zone', 'reportit'),
'description' => __('Enable/Disable to display server\'s timezone on the headlines.', 'reportit'),
'method' => 'checkbox',
'default' => 'on',
),
'reportit_operator' => array(
'friendly_name' => __('Allow Scheduling by Operators', 'reportit'),
'description' => __('Enable/Disable Operator\'s ability to Schedule Reports. When Disabled, only Administrators may change scheduling.', 'reportit'),
'method' => 'checkbox',
'default' => '',
),
'reportit_use_IEC' => array(
'friendly_name' => __('SI-Prefixes', 'reportit'),
'description' => __('Enable/Disable the use of correct SI-Prefixes for binary multiples under the terms of <a href=\'http://www.ieee.org\'>IEEE 1541</a> and <a href=\'http://www.iec.ch/zone/si/si_bytes.htm\'>IEC 60027-2</a>.', 'reportit'),
'method' => 'checkbox',
'default' => 'on',
),
'reportit_header5' => array(
'friendly_name' => __('Auto E-Mailing', 'reportit'),
'method' => 'spacer',
'collapsible' => 'true'
),
'reportit_email' => array(
'friendly_name' => __('Enable', 'reportit'),
'description' => __('If enabled scheduled reports can be emailed automatically to a list of recipients.<br> This feature requires a configured version of the \'Settings Plugin\'.', 'reportit'),
'method' => 'checkbox',
'default' => '',
)
);
if (isset($settings['reports']) && cacti_sizeof($settings['reports'])) {
$settings['reports'] = array_merge($settings['reports'], $temp);
} else {
$settings['reports'] = $temp;
unset($temp);
}
$user_temp = array(
'reportit_view_filter' => array(
'friendly_name' => __('Separate Report View Filter', 'reportit'),
'description' => __('Enable/disable the use of an individual filter per report.', 'reportit'),
'method' => 'checkbox',
'default' => 'on',
),
'reportit_max_rows' => array(
'friendly_name' => __('Rows Per Page', 'reportit'),
'description' => __('The number of rows to display on a single page.', 'reportit'),
'method' => 'drop_array',
'array' => $item_rows,
'default' => '25',
),
'reportit_csv_header' => array(
'friendly_name' => __('Report Export Settings', 'reportit'),
'method' => 'spacer',
'collapsible' => 'true'
),
'reportit_csv_column_s' => array(
'friendly_name' => __('CSV Column Separator', 'reportit'),
'description' => __('The column separator to be used for CSV exports.', 'reportit'),
'method' => 'drop_array',
'array' => $csv_column_separator,
'default' => 0,
),
'reportit_csv_decimal_s' => array(
'friendly_name' => __('CSV Decimal Separator', 'reportit'),
'description' => __('The symbol indicating the end of the integer part and the beginning of the fractional part.', 'reportit'),
'method' => 'drop_array',
'array' => $csv_decimal_separator,
'default' => 0,
),
);
if (isset($settings_user['reportit']) && cacti_sizeof($settings_user['reportit'])) {
$settings_user['reportit'] = array_merge($settings_user['reportit'], $user_temp);
} else {
$settings_user['reportit'] = $user_temp;
}
$tabs_graphs['reportit'] = __('Report General Settings', 'reportit');
/**
* default user settings will be placed into settings table as system
* defaults.
*/
if (isset($settings['reports']) && cacti_sizeof($settings['reports'])) {
$settings['reports'] = array_merge($settings['reports'], $user_temp);
} else {
$settings['reports'] = $user_temp;
}
unset($user_temp);
foreach ($settings['reports'] as $key => $value ){
if (array_key_exists('default', $value) ){
if (!db_setting_exists($key)) {
// set_config_option($key, $value['default']);
}
}
}
}
function db_setting_exists($setting) {
$results = db_fetch_row_prepared('SELECT * FROM settings WHERE name = ?', array($setting));
if (cacti_sizeof($results)) {
return true;
} else {
return false;
}
}
function reportit_show_tab() {
reportit_check_upgrade();
if (api_user_realm_auth('view.php')) {
print '<a href="' . CACTI_PATH_URL . 'plugins/reportit/view.php"><img src="' . CACTI_PATH_URL . 'plugins/reportit/images/tab_reportit_' . (get_current_page() == 'view.php' ? 'down' : 'up'). '.png" alt="' . __('ReportIt', 'reportit') . '"></a>';
}
}
function reportit_system_setup() {
require_once(CACTI_PATH_BASE . '/plugins/reportit/system/install.php');
reportit_system_install();
}
function reportit_define($constant, $value) {
if (!defined($constant)) {
@define($constant, $value);
}
}
function reportit_define_constants(){
/* realm IDs which have been defined dynamically by PIA 2.x */
$view = db_fetch_cell("SELECT id
FROM plugin_realms
WHERE plugin='reportit'
AND file LIKE '%view.php%'");
$create = db_fetch_cell("SELECT id
FROM plugin_realms
WHERE plugin='reportit'
AND file LIKE '%reportit.php%'");
$administrate = db_fetch_cell("SELECT id
FROM plugin_realms
WHERE plugin='reportit'
AND file LIKE '%templates.php%'");
reportit_define('REPORTIT_USER_VIEWER', 100+$view);
reportit_define('REPORTIT_USER_OWNER', 100+$create);
reportit_define('REPORTIT_USER_ADMIN', 100+$administrate);
/* define ReportIt's base paths */
reportit_define('REPORTIT_BASE_PATH', CACTI_PATH_BASE . '/plugins/reportit');
reportit_define('CACTI_BASE_PATH', CACTI_PATH_BASE);
reportit_define('CACTI_INCLUDE_PATH', CACTI_BASE_PATH . '/include/');
/* path where PCLZIP will save temporary files */
reportit_define('REPORTIT_TMP_FD', REPORTIT_BASE_PATH . '/tmp/');
/* path where archives will be saved per default */
reportit_define('REPORTIT_ARC_FD', REPORTIT_BASE_PATH . '/archive/');
/* path where exports will be saved per default */
reportit_define('REPORTIT_EXP_FD', REPORTIT_BASE_PATH . '/exports/');
}
function reportit_poller_bottom() {
require_once(CACTI_PATH_LIBRARY . '/api_scheduler.php');
require_once(CACTI_PATH_LIBRARY . '/reports.php');
$str = '';
$ids = '';
$cnt = 0;
$start = microtime(true);
$lifecycle = read_config_option('reportit_arc_lifecycle', true);
$logging_level = read_config_option('log_verbosity', true);
/* user did not save plugin settings, variable $lifecycle doesn't exist */
if (intval($lifecycle) <= 0) {
$lifecycle = 300;
}
/* mark running reports which have run too long as failed */
$met = read_config_option('reportit_met');
$met = intval($met);
if ($met < 1) {
$met = 300;
}
/* fetch all tables whose life cycle has been expired */
$tables = db_fetch_assoc("SHOW TABLE STATUS
WHERE `Name` LIKE 'plugin_reportit_tmp_%'
AND (UNIX_TIMESTAMP(`Update_time`) + $lifecycle) <= UNIX_TIMESTAMP()");
if (cacti_count($tables)) {
foreach($tables as $table) {
/* take care that we really do NOT delete others tables */
if (strpos($table['Name'], 'plugin_reportit_tmp_') !== false) {
$str .= $table['Name'] . ', ';
$ids .= ",'" . str_replace('plugin_reportit_tmp_', '', $table['Name']) . "'";
$cnt++;
}
}
if ($cnt > 0) {
$ids = substr($ids, 1);
$str = substr($str, 0, -2);
if (db_execute("DROP TABLE IF EXISTS $str") == 1) {
db_execute("DELETE FROM plugin_reportit_cache_reports WHERE `cache_id` IN ($ids)");
db_execute("DELETE FROM plugin_reportit_cache_variables WHERE `cache_id` IN ($ids)");
db_execute("DELETE FROM plugin_reportit_cache_measurands WHERE `cache_id` IN ($ids)");
if ($cnt >= 5) {
db_execute('OPTIMIZE TABLE `plugin_reportit_cache_reports`');
db_execute('OPTIMIZE TABLE `plugin_reportit_cache_variables`');
db_execute('OPTIMIZE TABLE `plugin_reportit_cache_measurands`');
}
} else {
if ($logging_level != 'POLLER_VERBOSITY_LOW') {
cacti_log('WARNING: Unable to clean up report cache', false, 'REPORTIT');
}
}
}
}
$lastrun = read_config_option('reportit_lastrun');
$now = time();
$scheduled = 0;
if (empty($lastrun)) {
set_config_option('reportit_lastrun', $now);
exit(0);
}
set_config_option('reportit_lastrun', $now);
$php_binary = read_config_option('path_php_binary');
$queued = array();
$reports = db_fetch_assoc('SELECT * FROM plugin_reportit_reports WHERE enabled = "on"');
reports_log('Cacti ReportIt Reports reports found: ' . cacti_sizeof($reports), true, 'REPORTS', POLLER_VERBOSITY_MEDIUM);
if (cacti_sizeof($reports)) {
foreach($reports as $report) {
if (api_scheduler_is_time_to_start($report, 'plugin_reportit_reports')) {
reports_log('Reports processing report: ' . $report['name'], true, 'REPORTS', POLLER_VERBOSITY_MEDIUM);
$queued[] = reportit_schedule_report($report);
}
}
}
if (cacti_sizeof($queued)) {
exec_background($php_binary, CACTI_PATH_BASE . '/plugins/reportit/poller_reportit.php --scheduled');
}
$end = microtime(true);
/* only log when things happen */
if ($cnt > 0 || $scheduled > 0) {
$stats = sprintf('REPORTIT STATS: Time:%0.2f CacheLifetime:%s CachePurged:%s DispatchedReports:%s', $end - $start, $lifecycle, $cnt, $scheduled);
cacti_log($stats, false, 'SYSTEM');
}
}
function reportit_schedule_report(&$report) {
require_once(CACTI_PATH_BASE . '/plugins/reportit/lib/funct_runtime.php');
$command = read_config_option('path_php_binary');
$command .= ' ' . CACTI_PATH_BASE . '/plugins/reportit/poller_reportit.php';
$id = $report['id'];
$name = $report['name'];
$notify = $report['notify_list'];
$from = array();
if (isset($report['from_email']) && $report['from_email'] != '') {
$from_email = $report['from_email'];
} else {
$from_email = read_config_option('settings_from_email');
}
if (isset($report['from_name']) && $report['from_name'] != '') {
$from_name = $report['from_name'];
} else {
$from_name = read_config_option('settings_from_name');
}
if ($from_email != '' && $from_name != '') {
$from['email'] = $from_email;
$from['name'] = $from_name;
}
$to_emails = db_fetch_assoc_prepared('SELECT email, name
FROM plugin_reportit_recipients
WHERE report_id = ?',
array($report['id']));
if ($report['email'] != '') {
$emails = explode(',', $report['email']);
$emails = array_map('trim', $emails);
$to_emails += $emails;
}
if ($report['bcc'] != '') {
$bcc_emails = explode(',', $report['bcc']);
$bcc_emails = array_map('trim', $bcc_emails);
} else {
$bcc_emails = array();
}
if (isset($report['reply_to'])) {
$reply_to = $report['reply_to'];
} else {
$reply_to = '';
}
$notification = array();
if (cacti_sizeof($to_emails) || cacti_sizeof($bcc_emails)) {
$notification['email']['to_email'] = $to_emails;
$notification['email']['bcc_email'] = $bcc_emails;
$notification['email']['reply_to'] = $reply_to;
$notification['email']['from'] = $from;
}
if ($notify > 0) {
$notification['notification_list']['id'] = $notify;
$notification['notification_list']['reply_to'] = $reply_to;
$notification['notification_list']['from'] = $from;
}
return reports_queue($name, 1, 'reportit', $id, $command, $notification);
}
function reportit_clog_regex_array($regex_array) {
$regex_array[] = array('name' => 'RIReport', 'regex' => '( RIReport\[)([, \d]+)(\])', 'func' => 'reportit_clog_regex_report');
$regex_array[] = array('name' => 'RIDataItem', 'regex' => '( RIDataItem\[)([, \d]+)(\])', 'func' => 'reportit_clog_regex_dataitem');
return $regex_array;
}
function reportit_clog_regex_report($matches) {
$result = $matches[0];
$report_ids = explode(',', str_replace(' ', '', $matches[2]));
if (cacti_sizeof($report_ids)) {
$result = '';
$reports = db_fetch_assoc_prepared('SELECT id, name
FROM plugin_reportit_reports
WHERE id in (?)',
array(implode(',',$report_ids)));
$reportDescriptions = array();
if (cacti_sizeof($reports)) {
foreach ($reports as $report) {
$reportDescriptions[$report['id']] = html_escape($report['name']);
}
}
foreach ($report_ids as $report_id) {
$result .= $matches[1] . '<a href=\'' . html_escape(CACTI_PATH_URL . 'plugins/reportit/reportit.php?action=report_edit&id=' . $report_id) . '\'>' . (isset($reportDescriptions[$report_id]) ? $reportDescriptions[$report_id]:$report_id) . '</a>' . $matches[3];
}
}
return $result;
}
function reportit_clog_regex_dataitem($matches) {
$result = $matches[0];
$dataitem_ids = explode(',',str_replace(" ","",$matches[2]));
if (cacti_sizeof($dataitem_ids)) {
$result = '';
$dataitems = db_fetch_assoc_prepared('SELECT a.id, a.report_id, b.name_cache as description
FROM plugin_reportit_data_items AS a
LEFT JOIN data_template_data AS b
ON b.local_data_id = a.id
WHERE a.id in (?)',
array(implode(',',$dataitem_ids)));
$dataitemDescriptions = array();
$dataitemReports = array();
if (cacti_sizeof($dataitems)) {
foreach ($dataitems as $dataitem) {
$dataitemReports[$dataitem['id']] = $dataitem['report_id'];
$dataitemDescriptions[$dataitem['id']] = html_escape($dataitem['description']);
}
}
foreach ($dataitem_ids as $dataitem_id) {
$result .= $matches[1] . '<a href=\'' . html_escape(CACTI_PATH_URL . 'plugins/reportit/rrdlist.php?action=rrdlist_edit&id=' . $dataitem_id) . '\'>' . (isset($dataitemDescriptions[$dataitem_id]) ? $dataitemDescriptions[$dataitem_id]:$dataitem_id) . '</a>' . $matches[3];
}
}
return $result;
}