#!/bin/sh # # (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/ # # 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 # #%# family=manual # 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; foreach $station (@{$in->{data}}) { if ($station->{url} =~ /CatchmentId=$CatchmentId$/) { $id = $station->{id}; $river = $station->{watercourse}; $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 for STATION in $stations ; do curl -m 5 -sS $urlbase/$STATION | perl -MJSON::PP -e '$id=shift(@ARGV); $d=decode_json(<>) or die "error decoding station $id"; print "river_level_$id.value ", $d->{data}->{current}->{level} || "U", "\n";' $STATION done