Skip to content

Commit 3831b20

Browse files
committed
Weathermap fix for local rrdcaches users and cron fix
See : librenms-plugins#85
1 parent ed35369 commit 3831b20

File tree

3 files changed

+38
-30
lines changed

3 files changed

+38
-30
lines changed

lib/datasources/WeatherMapDataSource_rrd.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ function wmrrd_read_from_real_rrdtool($rrdfile,$cf,$start,$end,$dsnames, &$data,
209209
// rrdcached Support: strip "./" from Data Source
210210
if ($map->daemon)
211211
{
212-
$rrdfile = trim($rrdfile,"^./");
212+
$rrdfile = preg_replace('/^\.\//', '', $rrdfile);
213213
}
214214

215215
$args[] = "fetch";

map-poller.php

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env php
12
<?php
23

34
// Copyright (C) 2013 Neil Lathwood neil@lathwood.co.uk
@@ -54,35 +55,42 @@
5455
// Change to directory that map-poller is in.
5556
chdir(__DIR__);
5657

57-
if (is_dir($conf_dir))
58-
{
59-
if ($dh = opendir($conf_dir))
60-
{
61-
while (($file = readdir($dh)) !== false)
58+
if (is_dir($conf_dir))
59+
{
60+
if ($dh = opendir($conf_dir))
61+
{
62+
while (($file = readdir($dh)) !== false)
6263
{
6364
if ("." != $file && ".." != $file && ".htaccess" != $file && "index.php" != $file)
64-
{
65+
{
6566
$cmd = "php ./weathermap.php --config $conf_dir/$file --base-href $basehref";
66-
67-
if (!empty($config['rrdcached']))
68-
{
69-
$cmd = $cmd." --daemon ".$config['rrdcached']." --chdir ''";
70-
}
71-
else
72-
{
73-
$cmd = $cmd." --chdir ".$config['rrd_dir'];
74-
}
75-
76-
$fp = popen($cmd, 'r');
77-
78-
while (!feof($fp))
79-
{
80-
$read = fgets($fp);
81-
echo $read;
82-
}
83-
pclose($fp);
84-
}
85-
}
86-
}
87-
}
67+
68+
if (!empty($config['rrdcached']))
69+
{
70+
if (str_contains($config['rrdcached'], 'unix'))
71+
{
72+
$cmd = $cmd." --daemon ".$config['rrdcached'];
73+
}
74+
else
75+
{
76+
$cmd = $cmd." --daemon ".$config['rrdcached']." --chdir ''";
77+
}
78+
}
79+
else
80+
{
81+
$cmd = $cmd." --chdir ".$config['rrd_dir'];
82+
}
83+
84+
$fp = popen($cmd, 'r');
85+
86+
while (!feof($fp))
87+
{
88+
$read = fgets($fp);
89+
echo $read;
90+
}
91+
pclose($fp);
92+
}
93+
}
94+
}
95+
}
8896
?>

weathermap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@
278278

279279
// Added the rrd_default_path if cannot be found
280280
if($rrdbase == '') {
281-
$rrdbase = isset($chdir) != '' ? $chdir : $rrd_default_path1;
281+
$rrdbase = isset($chdir) ? $chdir : $rrd_default_path1;
282282
$map->add_hint('rrd_default_path', $rrdbase);
283283

284284
}

0 commit comments

Comments
 (0)