From aa454ff4b3d4d5be9d5cc9dff4b4246c6e655f3e Mon Sep 17 00:00:00 2001 From: Pim van den Berg Date: Wed, 4 Nov 2009 21:05:37 +0100 Subject: remove path_format from plugins The relative path to an rrd file can be generated based on host, plugin, plugin instance, type and type instance. In this case path_format is not needed anymore. This commit includes code based on the collectd_identifier function from php-collection by Bruno Prémont. --- type/Default.class.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'type') diff --git a/type/Default.class.php b/type/Default.class.php index 8a5dd72..f40d12d 100644 --- a/type/Default.class.php +++ b/type/Default.class.php @@ -46,14 +46,26 @@ class Type_Default { return $c[r].$c[g].$c[b]; } + function identifier($host, $plugin, $pinst, $type, $tinst) { + $identifier = sprintf('%s/%s%s%s/%s%s%s', $host, + $plugin, strlen($pinst) ? '-' : '', $pinst, + $type, strlen($tinst) ? '-' : '', $tinst); + + if (is_file($this->datadir.'/'.$identifier.'.rrd')) + return $identifier; + else + return FALSE; + } + function get_filename($tinstance=NULL) { if (!is_array($this->args['tinstance']) && $tinstance == NULL) $tinstance = $this->args['tinstance']; - - $search = array('{host}', '{plugin}', '{pinstance}', '{type}', '{tinstance}'); - $replace = array($this->args['host'], $this->args['plugin'], $this->args['pinstance'], $this->args['type'], $tinstance); - $f = $this->datadir . '/' . str_replace($search, $replace, $this->path_format); - return $f; + + $identifier = $this->identifier($this->args['host'], + $this->args['plugin'], $this->args['pinstance'], + $this->args['type'], $tinstance); + + return $this->datadir.'/'.$identifier.'.rrd'; } function rrd_graph($debug=false) { -- cgit v1.1