From fe344d01d0b70fe30ba3930af83a87a2cbed8925 Mon Sep 17 00:00:00 2001 From: Dao-hui Chen Date: Wed, 11 Jun 2014 11:43:26 +0800 Subject: Add support for multiple types db --- inc/collectd.inc.php | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'inc') diff --git a/inc/collectd.inc.php b/inc/collectd.inc.php index 695d79c..bbed611 100644 --- a/inc/collectd.inc.php +++ b/inc/collectd.inc.php @@ -168,25 +168,32 @@ function plugin_sort($data) { return $data; } -function parse_typesdb_file($file = '/usr/share/collectd/types.db') { - if (!file_exists($file)) - $file = 'inc/types.db'; +function parse_typesdb_file($file = array('/usr/share/collectd/types.db')) { + if (!is_array($file)) + $file = array($file); + if (!file_exists($file[0])) + $file[0] = 'inc/types.db'; $types = array(); - foreach (file($file) as $type) { - if(!preg_match('/^(?P[\w_]+)\s+(?P.*)/', $type, $matches)) + foreach ($file as $single_file) + { + if (!file_exists($single_file)) continue; - $dataset = $matches['dataset']; - $datasources = explode(', ', $matches['datasources']); - - foreach ($datasources as $ds) { - if (!preg_match('/^(?P\w+):(?P[\w]+):(?P[\-\dU\.]+):(?P[\dU\.]+)/', $ds, $matches)) - error_log(sprintf('CGP Error: DS "%s" from dataset "%s" did not match', $ds, $dataset)); - $types[$dataset][$matches['dsname']] = array( - 'dstype' => $matches['dstype'], - 'min' => $matches['min'], - 'max' => $matches['max'], - ); + foreach (file($single_file) as $type) { + if(!preg_match('/^(?P[\w_]+)\s+(?P.*)/', $type, $matches)) + continue; + $dataset = $matches['dataset']; + $datasources = explode(', ', $matches['datasources']); + + foreach ($datasources as $ds) { + if (!preg_match('/^(?P\w+):(?P[\w]+):(?P[\-\dU\.]+):(?P[\dU\.]+)/', $ds, $matches)) + error_log(sprintf('CGP Error: DS "%s" from dataset "%s" did not match', $ds, $dataset)); + $types[$dataset][$matches['dsname']] = array( + 'dstype' => $matches['dstype'], + 'min' => $matches['min'], + 'max' => $matches['max'], + ); + } } } return $types; -- cgit v1.1