Repository navigation
Expand file tree
/
Copy pathflowview_process.php
More file actions
158 lines (126 loc) · 4.16 KB
/
Copy pathflowview_process.php
File metadata and controls
158 lines (126 loc) · 4.16 KB
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
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2020 The Cacti Group |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDTool-based Graphing Solution |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See |
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
chdir(dirname(__FILE__) . '/../../');
include('./include/cli_check.php');
include_once('./plugins/flowview/functions.php');
ini_set('max_execution_time', 0);
ini_set('memory_limit', '-1');
$debug = false;
$shortopts = 'VvHh';
$longopts = array(
'debug',
'version',
'help',
);
$options = getopt($shortopts, $longopts);
foreach($options as $arg => $value) {
switch($arg) {
case 'debug':
$debug = true;
break;
case 'version':
display_version();
exit(0);
break;
case 'help':
display_help();
exit(0);
break;
default:
print "ERROR: Invalid options" . PHP_EOL;
exit(1);
break;
}
}
$templates = array();
$t = time();
$r = intval($t / 60) * 60;
$start = microtime(true);
$last = read_config_option('flowview_last_change');
if (empty($last)) {
$last = time() - read_config_option('poller_interval');
set_config_option('flowview_last_change', $last);
} else {
set_config_option('flowview_last_change', time());
}
$schedules = db_fetch_assoc("SELECT *
FROM plugin_flowview_schedules
WHERE enabled = 'on'
AND ($t - sendinterval > lastsent)");
if (count($schedules)) {
foreach ($schedules as $s) {
db_execute_prepared("UPDATE plugin_flowview_schedules
SET lastsent = ?
WHERE id = ?",
array($r, $s['id']));
plugin_flowview_run_schedule($s['id']);
}
}
$total = db_fetch_cell('SELECT COUNT(*)
FROM plugin_flowview_devices');
$listeners = db_fetch_assoc('SELECT *
FROM plugin_flowview_devices
WHERE cmethod = 1');
$tables = get_tables_range($last);
$records = 0;
foreach($tables as $table) {
$records += db_fetch_cell_prepared("SELECT COUNT(*)
FROM $table
WHERE end_time >= ?",
array(date('Y-m-d H:i:s', $last)));
}
$end = microtime(true);
$cacti_stats = sprintf(
'time:%01.4f ' .
'listeners:%s ' .
'legacy:%s ' .
'newrecs:%s ' .
'schedules:%s',
round($end-$start,2),
sizeof($total),
sizeof($listeners),
$records,
sizeof($schedules)
);
set_config_option('flowview_stats', $cacti_stats);
/* log to the logfile */
cacti_log('FLOWVIEW STATS: ' . $cacti_stats , TRUE, 'SYSTEM');
function debug($string) {
global $debug;
if ($debug) {
print 'DEBUG: ' . trim($string) . PHP_EOL;
}
}
function display_version() {
$version = get_cacti_cli_version();
print "Cacti Flow Poller, Version $version, " . COPYRIGHT_YEARS . PHP_EOL;
}
function display_help() {
display_version();
print PHP_EOL . "usage: flowview_process.php [--debug]" . PHP_EOL . PHP_EOL;
print "Cacti poller processes reports and imports latest legacy data into" . PHP_EOL;
print "the Cacti database." . PHP_EOL . PHP_EOL;
print "Options:" . PHP_EOL;
print " --debug Provide some debug output during collection." . PHP_EOL . PHP_EOL;
}