diff options
author | Ćukasz Kostka | 2014-01-05 21:19:50 +0100 |
---|---|---|
committer | Pim van den Berg | 2014-03-22 14:03:07 +0100 |
commit | 92e7698826fe77befeb1787aaa51e96492880e65 (patch) | |
tree | 3d6f7eb89a176912cd7c5804ae7bb1ebd5b60835 /inc/collectd.inc.php | |
parent | mod_rewrite final cleanup (diff) | |
download | apt-panopticon_cgp-92e7698826fe77befeb1787aaa51e96492880e65.zip apt-panopticon_cgp-92e7698826fe77befeb1787aaa51e96492880e65.tar.gz apt-panopticon_cgp-92e7698826fe77befeb1787aaa51e96492880e65.tar.bz2 apt-panopticon_cgp-92e7698826fe77befeb1787aaa51e96492880e65.tar.xz |
inc/collectd.inc.php: replace glob by php5 iterators
Diffstat (limited to '')
-rw-r--r-- | inc/collectd.inc.php | 25 |
1 files changed, 23 insertions, 2 deletions
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() { | |||
19 | return($dir); | 19 | return($dir); |
20 | } | 20 | } |
21 | 21 | ||
22 | |||
23 | # return files in directory. this will recurse into subdirs | ||
24 | # infinite loop may occur | ||
25 | function get_host_rrd_files($dir) { | ||
26 | |||
27 | $files = array(); | ||
28 | |||
29 | $objects = new RecursiveIteratorIterator( | ||
30 | new RecursiveDirectoryIterator($dir), | ||
31 | RecursiveIteratorIterator::SELF_FIRST); | ||
32 | |||
33 | foreach($objects as $name => $object) { | ||
34 | if ( $object->getExtension() == 'rrd') { | ||
35 | $files[] = $object->getPathname(); | ||
36 | } | ||
37 | } | ||
38 | |||
39 | return $files; | ||
40 | } | ||
41 | |||
42 | |||
22 | # returns an array of plugins/pinstances/types/tinstances | 43 | # returns an array of plugins/pinstances/types/tinstances |
23 | function collectd_plugindata($host, $plugin=NULL) { | 44 | function collectd_plugindata($host, $plugin=NULL) { |
24 | global $CONFIG; | 45 | global $CONFIG; |
@@ -26,8 +47,8 @@ function collectd_plugindata($host, $plugin=NULL) { | |||
26 | if (!is_dir($CONFIG['datadir'].'/'.$host)) | 47 | if (!is_dir($CONFIG['datadir'].'/'.$host)) |
27 | return false; | 48 | return false; |
28 | 49 | ||
29 | chdir($CONFIG['datadir'].'/'.$host); | 50 | $hostdir = $CONFIG['datadir'].'/'.$host; |
30 | $files = glob("*/*.rrd"); | 51 | $files = get_host_rrd_files( $hostdir ); |
31 | if (!$files) | 52 | if (!$files) |
32 | return false; | 53 | return false; |
33 | 54 | ||