added copyright and license
This commit is contained in:
parent
f698f9c807
commit
47e3a9980c
7
README.md
Normal file → Executable file
7
README.md
Normal file → Executable file
@ -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/
|
@ -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;
|
||||
|
20
river_level_
20
river_level_
@ -1,22 +1,8 @@
|
||||
#!/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=
|
||||
# (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 () {
|
||||
|
@ -1,49 +1,53 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Wildcard-script to monitor network interfaces. To monitor an
|
||||
# interface, link vlan_<interface> 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_<id> 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 </tmp/river_level_.dat
|
||||
# 23 24 25 26
|
||||
|
||||
|
||||
CACHE=/tmp/river_level_.dat
|
||||
checkdata () {
|
||||
if test `find "$CACHE" -mtime +1`
|
||||
then
|
||||
curl -o $CACHE -Ss $URLBASE || exit 1
|
||||
fi
|
||||
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)
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user