This commit is contained in:
foo 2014-01-04 20:39:39 +00:00
parent 56f57223fb
commit 3365ae9c08
2 changed files with 80 additions and 0 deletions

12
getstations.pl Executable file
View File

@ -0,0 +1,12 @@
use JSON::PP;
$DEBUG = $ENV{DEBUG};
$CatchmentId = shift @ARGV;
print "Decoding...\n" if $DEBUG;
$in = decode_json(<>) or die;
foreach $station (@{$in->{data}}) {
if ($station->{url} =~ /CatchmentId=$CatchmentId$/) {
print "$station->{id}", $DEBUG ? ": $station->{station} on $station->{river}\n" : " ";
}
}
print "\n" unless $DEBUG;

68
river_levels_ Executable file
View File

@ -0,0 +1,68 @@
#!/bin/sh
#
# Wildcard-script to monitor network interfaces. To monitor an
# interface, link vlan_<interface> 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";'