aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2011-10-31 20:33:05 +0100
committerChristian Weiske <cweiske@cweiske.de>2011-10-31 20:33:05 +0100
commit133a6dff495236e2d3a4eb70081ddb1448765625 (patch)
treecabc0df642f5432b10129448a727c4fbd4193f4d
parentdfdadfc0ee73f552273966135963be036c5d4223 (diff)
downloadusb-wde1-tools-133a6dff495236e2d3a4eb70081ddb1448765625.tar.gz
usb-wde1-tools-133a6dff495236e2d3a4eb70081ddb1448765625.zip
(html) file generator
-rw-r--r--htmlreport/.gitignore2
-rw-r--r--htmlreport/config.php.dist22
-rw-r--r--htmlreport/gen-html.php36
-rw-r--r--htmlreport/templates/plain.txt.php21
4 files changed, 81 insertions, 0 deletions
diff --git a/htmlreport/.gitignore b/htmlreport/.gitignore
new file mode 100644
index 0000000..2ea1723
--- /dev/null
+++ b/htmlreport/.gitignore
@@ -0,0 +1,2 @@
+config.php
+testdata
diff --git a/htmlreport/config.php.dist b/htmlreport/config.php.dist
new file mode 100644
index 0000000..0720e33
--- /dev/null
+++ b/htmlreport/config.php.dist
@@ -0,0 +1,22 @@
+<?php
+/**
+ * path to the .rrd files.
+ * {item} will be replaced with humidity/temperature,
+ * {id} with the sensor number
+ */
+$filetemplate = '/var/lib/munin/home.cweiske.de/haus-usb_wde1_{item}-sensor{id}-g.rrd';
+$outdir = '/tmp/';
+
+/**
+ * Array of sensor number to sensor title associations
+ */
+$names = array(
+ 0 => 'Schlafzimmer',
+ 1 => 'Wohnzimmer',
+ 2 => 'Buero',
+ 3 => 'Aussen',
+ 4 => 'Bad',
+ 5 => 'Kinderzimmer',
+ 6 => 'Kueche',
+);
+?> \ No newline at end of file
diff --git a/htmlreport/gen-html.php b/htmlreport/gen-html.php
new file mode 100644
index 0000000..f495622
--- /dev/null
+++ b/htmlreport/gen-html.php
@@ -0,0 +1,36 @@
+<?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;
+
+$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
+ )
+ );
+ 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);
+}
+?> \ No newline at end of file
diff --git a/htmlreport/templates/plain.txt.php b/htmlreport/templates/plain.txt.php
new file mode 100644
index 0000000..0881184
--- /dev/null
+++ b/htmlreport/templates/plain.txt.php
@@ -0,0 +1,21 @@
+Zimmer Temperatur Luftfeuchte
+-------------------------------------------
+<?php
+plain_line($data[3]);
+echo "\n";
+plain_line($data[1]);
+plain_line($data[5]);
+plain_line($data[2]);
+echo "\n";
+plain_line($data[6]);
+plain_line($data[0]);
+plain_line($data[4]);
+
+
+function plain_line($datum) {
+ echo str_pad($datum['name'], 18, ' ');
+ echo ' ' . str_pad($datum['temperature'] . '°C', 13, ' ');
+ echo ' ' . $datum['humidity'] . '%';
+ echo "\n";
+}
+?>