aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/inc/rrdtool.class.php
blob: 283f70862e5c12b150d575fa92d4c29164b6b757 (plain)
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
<?php

class RRDTool {
	var $rrdtool = '/usr/bin/rrdtool';

	function __construct($rrdtool) {
		if (file_exists($rrdtool)) {
			$this->rrdtool = $rrdtool;
		} else {
			printf('<p class="warn">Error: RRDTool (<em>%s</em>) is not executable. Please install RRDTool it and configure <em>$CONFIG[\'rrdtool\'].</em></p>', $rrdtool);
			die();
		}
	}

	function rrd_info($rrdfile) {
		if (file_exists($rrdfile)) {
			$raw_info = shell_exec(
				escapeshellarg($this->rrdtool)
				. " info " .
				escapeshellarg($rrdfile)
			);
			$raw_array = explode("\n", $raw_info);
			$info_array = array();
			foreach ($raw_array as $key => $info) {
				if ($info != "") {
					$item_info = explode(" = ", $info);
					$item_info[1] = preg_replace('/"/', '', $item_info[1]);
					$info_array[$item_info[0]] = $item_info[1];
				}
			}
			return $info_array;
		} else {
			return false;
		}
	}
}