Skip to content

Commit

Permalink
Weathermap fix for local rrdcached users and cron fix (#85)
Browse files Browse the repository at this point in the history
Reflect latest upstream changes in Weathermap
  • Loading branch information
fbouynot authored Jan 13, 2023
1 parent 697ac3c commit 4ce6ad1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lib/datasources/WeatherMapDataSource_rrd.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ function wmrrd_read_from_real_rrdtool($rrdfile,$cf,$start,$end,$dsnames, &$data,
// rrdcached Support: strip "./" from Data Source
if ($map->daemon)
{
$rrdfile = trim($rrdfile,"^./");
$rrdfile = preg_replace('/^\.\//', '', $rrdfile);
}

$args[] = "fetch";
Expand Down
64 changes: 36 additions & 28 deletions map-poller.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env php
<?php

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

if (is_dir($conf_dir))
{
if ($dh = opendir($conf_dir))
{
while (($file = readdir($dh)) !== false)
if (is_dir($conf_dir))
{
if ($dh = opendir($conf_dir))
{
while (($file = readdir($dh)) !== false)
{
if ("." != $file && ".." != $file && ".htaccess" != $file && "index.php" != $file)
{
{
$cmd = "php ./weathermap.php --config $conf_dir/$file --base-href $basehref";

if (!empty($config['rrdcached']))
{
$cmd = $cmd." --daemon ".$config['rrdcached']." --chdir ''";
}
else
{
$cmd = $cmd." --chdir ".$config['rrd_dir'];
}

$fp = popen($cmd, 'r');

while (!feof($fp))
{
$read = fgets($fp);
echo $read;
}
pclose($fp);
}
}
}
}

if (!empty($config['rrdcached']))
{
if (str_contains($config['rrdcached'], 'unix'))
{
$cmd = $cmd." --daemon ".$config['rrdcached'];
}
else
{
$cmd = $cmd." --daemon ".$config['rrdcached']." --chdir ''";
}
}
else
{
$cmd = $cmd." --chdir ".$config['rrd_dir'];
}

$fp = popen($cmd, 'r');

while (!feof($fp))
{
$read = fgets($fp);
echo $read;
}
pclose($fp);
}
}
}
}
?>
2 changes: 1 addition & 1 deletion weathermap.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@

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

}
Expand Down

0 comments on commit 4ce6ad1

Please sign in to comment.