|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Generates a filename based on the hostname (or IP) and some extra items |
|
5
|
|
|
* |
|
6
|
|
|
* @param array $device Device array |
|
7
|
|
|
* @param array|string $extra Components of RRD filename - will be separated with "-", or a pre-formed rrdname |
|
8
|
|
|
* @param string $extension File extension (default is .rrd) |
|
9
|
|
|
* @return string the name of the rrd file for $host's $extra component |
|
10
|
|
|
*/ |
|
11
|
|
|
function rrd_name($device, $extra, $extension = '.rrd') |
|
|
|
|
|
|
12
|
|
|
{ |
|
13
|
|
|
$filename = safename(is_array($extra) ? implode("-", $extra) : $extra); |
|
14
|
|
|
return implode("/", array(Settings::get('rrd_dir'), $device->hostname, $filename.$extension)); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Escapes strings for RRDtool |
|
19
|
|
|
* |
|
20
|
|
|
* @param string $string the string to escape |
|
21
|
|
|
* @param integer $length if passed, string will be padded and trimmed to exactly this length (after rrdtool unescapes it) |
|
22
|
|
|
* @return string |
|
23
|
|
|
*/ |
|
24
|
|
|
function rrdtool_escape($string, $length = null) |
|
|
|
|
|
|
25
|
|
|
{ |
|
26
|
|
|
$result = shorten_interface_type($string); |
|
27
|
|
|
$result = str_replace("'", '', $result); # remove quotes |
|
|
|
|
|
|
28
|
|
|
$result = str_replace('%', '%%', $result); # double percent signs |
|
|
|
|
|
|
29
|
|
|
if (is_numeric($length) && strlen($string) > $length) { |
|
30
|
|
|
$extra = substr_count($string, ':', 0, $length); |
|
31
|
|
|
$result = substr(str_pad($result, $length), 0, ($length + $extra)); |
|
32
|
|
|
if ($extra > 0) { |
|
33
|
|
|
$result = substr($result, 0, (-1 * $extra)); |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
$result = str_replace(':', '\:', $result); # escape colons |
|
|
|
|
|
|
38
|
|
|
return $result.' '; |
|
39
|
|
|
} // rrdtool_escape |
|
40
|
|
|
|
|
41
|
|
|
function build_rrdtool($arg) |
|
|
|
|
|
|
42
|
|
|
{ |
|
43
|
|
|
$rrdtool = Settings::get('rrdtool'); |
|
44
|
|
|
$rrdcached = Settings::get('rrdcached'); |
|
45
|
|
|
$rrdcached_dir = Settings::get('rrdcached_dir'); |
|
46
|
|
|
$rrd_dir = Settings::get('rrd_dir'); |
|
47
|
|
|
$rrd_daemon = ''; |
|
48
|
|
|
if (isset($rrdcached)) { |
|
49
|
|
|
if (isset($rrdcached_dir) && $rrdcached_dir !== false) { |
|
50
|
|
|
$arg = str_replace($rrd_dir.'/', './'.$rrdcached_dir.'/', $arg); |
|
51
|
|
|
$arg = str_replace($rrd_dir, './'.$rrdcached_dir.'/', $arg); |
|
52
|
|
|
} |
|
53
|
|
|
$rrd_daemon = " --daemon $rrdcached "; |
|
54
|
|
|
} |
|
55
|
|
|
return $rrdtool . ' ' . $rrd_daemon . $arg; |
|
56
|
|
|
} |
Learn more about camelCase.