diff options
Diffstat (limited to 'graph.php')
-rw-r--r-- | graph.php | 85 |
1 files changed, 77 insertions, 8 deletions
@@ -2,8 +2,10 @@ | |||
2 | 2 | ||
3 | require_once 'conf/common.inc.php'; | 3 | require_once 'conf/common.inc.php'; |
4 | require_once 'inc/functions.inc.php'; | 4 | require_once 'inc/functions.inc.php'; |
5 | require_once 'inc/collectd.inc.php'; | ||
5 | 6 | ||
6 | $plugin = validate_get(GET('p'), 'plugin'); | 7 | $plugin = validate_get(GET('p'), 'plugin'); |
8 | $type = validate_get(GET('t'), 'type'); | ||
7 | $width = empty($_GET['x']) ? $CONFIG['width'] : $_GET['x']; | 9 | $width = empty($_GET['x']) ? $CONFIG['width'] : $_GET['x']; |
8 | $height = empty($_GET['y']) ? $CONFIG['height'] : $_GET['y']; | 10 | $height = empty($_GET['y']) ? $CONFIG['height'] : $_GET['y']; |
9 | 11 | ||
@@ -12,18 +14,85 @@ if (validate_get(GET('h'), 'host') === NULL) { | |||
12 | error_image(); | 14 | error_image(); |
13 | } | 15 | } |
14 | 16 | ||
15 | if (!file_exists($CONFIG['webdir'].'/plugin/'.$plugin.'.php')) { | ||
16 | error_log(sprintf('CGP Error: plugin "%s" is not available', $plugin)); | ||
17 | error_image(); | ||
18 | } | ||
19 | |||
20 | if ($width > $CONFIG['max-width'] || $height > $CONFIG['max-height']) { | 17 | if ($width > $CONFIG['max-width'] || $height > $CONFIG['max-height']) { |
21 | error_log('Resquested image is too large. Please configure max-width and max-height.'); | 18 | error_log('Resquested image is too large. Please configure max-width and max-height.'); |
22 | error_image(); | 19 | error_image(); |
23 | } | 20 | } |
24 | 21 | ||
25 | # load plugin | 22 | $typesdb = parse_typesdb_file($CONFIG['typesdb']); |
26 | include $CONFIG['webdir'].'/plugin/'.$plugin.'.php'; | 23 | |
24 | if ($plugin == 'aggregation') { | ||
25 | $pi = explode("-", GET('pi')); | ||
26 | $plugin = $_GET['p'] = $pi[0]; | ||
27 | } | ||
28 | |||
29 | # plugin json | ||
30 | if (file_exists('plugin/'.$plugin.'.json')) { | ||
31 | $json = file_get_contents('plugin/'.$plugin.'.json'); | ||
32 | $plugin_json = json_decode($json, true); | ||
33 | |||
34 | if (is_null($plugin_json)) | ||
35 | error_log('CGP Error: invalid json in plugin/'.$plugin.'.json'); | ||
36 | } | ||
37 | |||
38 | switch ($plugin_json[$type]['type']) { | ||
39 | case 'stacked': | ||
40 | require_once 'type/GenericStacked.class.php'; | ||
41 | $obj = new Type_GenericStacked($CONFIG, $_GET); | ||
42 | break; | ||
43 | case 'io': | ||
44 | require_once 'type/GenericIO.class.php'; | ||
45 | $obj = new Type_GenericIO($CONFIG, $_GET); | ||
46 | break; | ||
47 | case 'uptime': | ||
48 | require_once 'type/Uptime.class.php'; | ||
49 | $obj = new Type_Uptime($CONFIG, $_GET); | ||
50 | break; | ||
51 | default: | ||
52 | require_once 'type/Default.class.php'; | ||
53 | $obj = new Type_Default($CONFIG, $_GET); | ||
54 | break; | ||
55 | } | ||
56 | |||
57 | if (isset($typesdb[$type])) { | ||
58 | $obj->data_sources = array(); | ||
59 | foreach ($typesdb[$type] as $ds => $property) { | ||
60 | $obj->data_sources[] = $ds; | ||
61 | } | ||
62 | } | ||
63 | |||
64 | if (isset($plugin_json[$type]['legend'])) { | ||
65 | $obj->order = array(); | ||
66 | foreach ($plugin_json[$type]['legend'] as $rrd => $property) { | ||
67 | $obj->order[] = $rrd; | ||
68 | $obj->legend[$rrd] = isset($property['name']) ? $property['name'] : $rrd; | ||
69 | if (isset($property['color'])) | ||
70 | $obj->colors[$rrd] = $property['color']; | ||
71 | } | ||
72 | } | ||
73 | |||
74 | if (isset($plugin_json[$type]['title'])) { | ||
75 | $obj->rrd_title = $plugin_json[$type]['title']; | ||
76 | $obj->rrd_title = str_replace('{{PI}}', GET('pi'), $obj->rrd_title); | ||
77 | $obj->rrd_title = str_replace('{{TI}}', GET('ti'), $obj->rrd_title); | ||
78 | } | ||
79 | |||
80 | if (isset($plugin_json[$type]['vertical'])) { | ||
81 | $obj->rrd_vertical = $plugin_json[$type]['vertical']; | ||
82 | $obj->rrd_vertical = str_replace('{{ND}}', ucfirst($CONFIG['network_datasize']), $obj->rrd_vertical); | ||
83 | } | ||
84 | |||
85 | if (isset($plugin_json[$type]['rrdtool_opts'])) { | ||
86 | $obj->rrdtool_opts = $plugin_json[$type]['rrdtool_opts']; | ||
87 | } | ||
88 | |||
89 | if (isset($plugin_json[$type]['datasize']) and $plugin_json[$type]['datasize']) | ||
90 | $obj->scale = $CONFIG['network_datasize'] == 'bits' ? 8 : 1; | ||
91 | |||
92 | if (isset($plugin_json[$type]['scale'])) | ||
93 | $obj->scale = $plugin_json[$type]['scale']; | ||
27 | 94 | ||
95 | if (isset($plugin_json[$type]['legend_format'])) | ||
96 | $obj->rrd_format = $plugin_json[$type]['legend_format']; | ||
28 | 97 | ||
29 | ?> | 98 | $obj->rrd_graph(); |