From 0cc75d7d1de48f2bebee6bd6de6fd22128a0bb17 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Sat, 13 Jun 2015 16:13:12 +1000 Subject: [PATCH] Separate convenience function for RRD filename generation; tidy formatting --- includes/functions.php | 18 ++++++++++++++++-- includes/polling/functions.inc.php | 4 ++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index bcde5c598..d3846c980 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -1251,7 +1251,8 @@ function ip_exists($ip) { /* * convenience function - please use this instead of 'if ($debug) { echo ...; }' */ -function d_echo($text) { +function d_echo($text) +{ global $debug; if ($debug) { echo "$text\n"; @@ -1261,9 +1262,22 @@ function d_echo($text) { /* * convenience function - please use this instead of 'if ($debug) { print_r ...; }' */ -function d_print_r($var) { +function d_print_r($var) +{ global $debug; if ($debug) { print_r($var); } } + +/* + * @return the name of the rrd file for $host's $extra component + * @param host Host name + * @param extra Components of RRD filename - will be separated with "-" + */ +function rrdname($host, $extra) +{ + global $config; + return implode("/", array($config['rrd_dir'], $host, safename(implode("-", $extra)).".rrd")); +} + diff --git a/includes/polling/functions.inc.php b/includes/polling/functions.inc.php index 77e7d7825..006dbaf7f 100644 --- a/includes/polling/functions.inc.php +++ b/includes/polling/functions.inc.php @@ -349,7 +349,7 @@ function poll_mib_def($device, $mib_name_table, $mib_subdir, $mib_oids, $mib_gra /* * Please use this instead of creating & updating RRD files manually. * @param device Device object - only 'hostname' is used at present - * @param name Array of name objects - filename will be constructed using this with a "-" delimiter + * @param name Array of rrdname components * @param def Array of data definitions * @param val Array of value definitions * @@ -357,7 +357,7 @@ function poll_mib_def($device, $mib_name_table, $mib_subdir, $mib_oids, $mib_gra function rrd_create_update($device, $name, $def, $val, $step = 300) { global $config; - $rrd = implode("/", array($config['rrd_dir'], $device['hostname'], safename(implode("-", $name)).".rrd")); + $rrd = rrd_name($device['hostname'], $name); if (!is_file($rrd) && $def != null) { // add the --step and the rra definitions to the array