From 56f57223fbf9fa5a3961e73e8e4f9917bf53d491 Mon Sep 17 00:00:00 2001 From: foo Date: Sat, 4 Jan 2014 19:21:37 +0000 Subject: [PATCH] working for one station --- river_level_ | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 river_level_ diff --git a/river_level_ b/river_level_ new file mode 100755 index 0000000..8008250 --- /dev/null +++ b/river_level_ @@ -0,0 +1,68 @@ +#!/bin/sh +# +# Wildcard-script to monitor network interfaces. To monitor an +# interface, link vlan_ to this file. E.g. +# +# ln /usr/share/munin/node/plugins-contrib/vlan_ /etc/munin/node.d/vlan_eth0_1 +# +# ...will monitor eth0.1 +# +# Parameters: +# +# config +# autoconf +# suggest +# +#%# family=manual +#%# capabilities=autoconf suggest + +# URLBASE= + +CACHE=/tmp/river_level_.dat +checkdata () { + if test `find "$CACHE" -mtime +1` + then + curl -o $CACHE -Ss $URLBASE || exit 1 + fi +} + + +getstationname () { + checkdata + NAME=$( perl -MJSON::PP -e ' + open $fh, "/tmp/river_level_.dat" or die $!; + $data_arr = decode_json(<$fh>) or die $!; + my %data; + foreach (@{$data_arr->{data}}) { + $data{$_->{id}} = $_; + } + foreach (@ARGV) { print $data{$_}->{river}, " at ", $data{$_}->{station}, "\n"; } + ' $* ) +} + +STATION=$(basename $0 | sed 's/^river_level_//g' | cut -d_ -f 3) + +if [ "$1" = "autoconf" ]; then + echo "no" + exit 0 +fi + +if [ "$1" = "suggest" ]; then + exit 0 +fi + +if [ "$1" = "config" ]; then + getstationname $STATION + echo "graph_title River Level for $NAME [$STATION]" + echo 'graph_args --base 1000 -l 0 ' + echo 'graph_vlabel station level (metres)' + echo 'graph_category rivers' + echo 'graph_info This graph shows river levels' + echo "level.label $NAME" + echo 'level.info Current river level (metres)' + exit 0 +fi + +curl -sS $URLBASE/$STATION | + perl -MJSON::PP -e '$d=decode_json(<>) or die; print "level.value $d->{data}->{current}->{level}\n";' +