diff --git a/README.md b/README.md old mode 100644 new mode 100755 index aa64e54..621b523 --- a/README.md +++ b/README.md @@ -4,3 +4,10 @@ river_levels A munin plugin for monitoring a reformatted version of the Environment Agency's publicly available data about river levels in the UK. See also: http://data.gov.uk/dataset/river-levels-15min/feedback/view + +License +------- + +This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License + +http://creativecommons.org/licenses/by-sa/4.0/ \ No newline at end of file diff --git a/getstations.pl b/getstations.pl index 3efaf26..de9df3c 100755 --- a/getstations.pl +++ b/getstations.pl @@ -1,3 +1,8 @@ +#!/usr/bin/env perl +# (C) Matthew Slowe, 2014 +# This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License +# http://creativecommons.org/licenses/by-sa/4.0/ + use JSON::PP; $DEBUG = $ENV{DEBUG}; $CatchmentId = shift @ARGV; diff --git a/river_level_ b/river_level_ index 8008250..9157f70 100755 --- a/river_level_ +++ b/river_level_ @@ -1,22 +1,8 @@ #!/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= +# (C) Matthew Slowe, 2014 +# This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License +# http://creativecommons.org/licenses/by-sa/4.0/ CACHE=/tmp/river_level_.dat checkdata () { diff --git a/river_levels_ b/river_levels_ index 8008250..f53bf7b 100755 --- a/river_levels_ +++ b/river_levels_ @@ -1,49 +1,53 @@ #!/bin/sh # -# Wildcard-script to monitor network interfaces. To monitor an -# interface, link vlan_ to this file. E.g. +# (C) Matthew Slowe, 2014 # -# ln /usr/share/munin/node/plugins-contrib/vlan_ /etc/munin/node.d/vlan_eth0_1 +# This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License +# http://creativecommons.org/licenses/by-sa/4.0/ # -# ...will monitor eth0.1 +# Wildcard-script to monitor a river system's catchment area. To monitor a +# particular catchment aread, link river_levels_ to this file. E.g. +# +# ln /usr/share/munin/node/plugins-contrib/river_levels_ /etc/munin/node.d/river_levels_123 +# +# ...will monitor catchment area 123. # # Parameters: # -# config -# autoconf -# suggest +# config +# autoconf +# suggest # #%# family=manual #%# capabilities=autoconf suggest -# URLBASE= +# Expects a config file to specify which stations to include in the data check and name the catchment +# +# [river_levels_] +# env.urlbase http://path.to.service/path +# +# [river_levels_123] +# env.stations 23 24 25 26 +# env.catchmentname Great River +# +# The station list can be generated by using getstations.pl: + +# host$ perl getstations.pl 123 ) 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) +CATCHMENT=$(basename $0 | sed 's/^river_levels_//g' | cut -d_ -f 3) if [ "$1" = "autoconf" ]; then - echo "no" + echo "no" exit 0 fi @@ -52,17 +56,31 @@ if [ "$1" = "suggest" ]; then 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 + echo "graph_title River Levels for $catchmentname [$CATCHMENT]" + 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' + + checkdata + perl -e ' + use JSON::PP; + $CatchmentId = shift @ARGV; + $in = decode_json(<>) or die; + foreach $station (@{$in->{data}}) { + if ($station->{url} =~ /CatchmentId=$CatchmentId$/) { + $id = $station->{id}; + $river = $station->{river}; + $name = $station->{station}; + print "river_level_$id.label $name on $river ($id)\n"; + print "river_level_$id.info Current river level (metres)\n"; + } + } +' $CATCHMENT <$CACHE + exit 0 fi -curl -sS $URLBASE/$STATION | - perl -MJSON::PP -e '$d=decode_json(<>) or die; print "level.value $d->{data}->{current}->{level}\n";' - +for STATION in $stations ; do + curl -m 5 -sS $urlbase/$STATION | + perl -MJSON::PP -e '$id=shift(@ARGV); $d=decode_json(<>) or die; print "river_level_$id.value $d->{data}->{current}->{level}\n";' $STATION +done