From 92e7698826fe77befeb1787aaa51e96492880e65 Mon Sep 17 00:00:00 2001 From: Ɓukasz Kostka Date: Sun, 5 Jan 2014 21:19:50 +0100 Subject: inc/collectd.inc.php: replace glob by php5 iterators --- inc/collectd.inc.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'inc/collectd.inc.php') diff --git a/inc/collectd.inc.php b/inc/collectd.inc.php index 7269e68..fa1cb85 100644 --- a/inc/collectd.inc.php +++ b/inc/collectd.inc.php @@ -19,6 +19,27 @@ function collectd_hosts() { return($dir); } + +# return files in directory. this will recurse into subdirs +# infinite loop may occur +function get_host_rrd_files($dir) { + + $files = array(); + + $objects = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($dir), + RecursiveIteratorIterator::SELF_FIRST); + + foreach($objects as $name => $object) { + if ( $object->getExtension() == 'rrd') { + $files[] = $object->getPathname(); + } + } + + return $files; +} + + # returns an array of plugins/pinstances/types/tinstances function collectd_plugindata($host, $plugin=NULL) { global $CONFIG; @@ -26,8 +47,8 @@ function collectd_plugindata($host, $plugin=NULL) { if (!is_dir($CONFIG['datadir'].'/'.$host)) return false; - chdir($CONFIG['datadir'].'/'.$host); - $files = glob("*/*.rrd"); + $hostdir = $CONFIG['datadir'].'/'.$host; + $files = get_host_rrd_files( $hostdir ); if (!$files) return false; -- cgit v1.1