aboutsummaryrefslogtreecommitdiff
path: root/htmlreport/gen-html.php
blob: 61c94ec47ec7e52f26c8e71713eacbfee5cd47a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env php
<?php
$cfgfile = __DIR__ . '/config.php';
if (!file_exists($cfgfile)) {
    echo "Copy config.php.dist to config.php and adjust it\n";
    exit(1);
}
require $cfgfile;

if (!function_exists('rrd_lastupdate')) {
    echo "rrd PHP extension is missing\n";
    exit(2);
}

if (!is_array($filetemplate)) {
    $filetemplate = array_combine(
        array_keys($names),
	array_fill(0, count($names), $filetemplate)
    );
}

$data = array();
foreach ($names as $id => $name) {
    $data[$id]['name'] = $name;
    foreach (array('humidity', 'temperature') as $item) {
        $lu = rrd_lastupdate(
            str_replace(
                array('{item}', '{id}'),
                array($item, $id),
                $filetemplate[$id]
            )
        );
        if ($lu === false) {
            throw new Exception(rrd_error());
        }
                      
        $data[$id][$item] = reset($lu['data']);
    }
}

foreach (glob(__DIR__ . '/templates/*.php') as $tplfile) {
    $outfile = $outdir . basename($tplfile, '.php');
    ob_start();
    include $tplfile;
    $content = ob_get_contents();
    ob_end_clean();
    file_put_contents($outfile, $content);
}
?>