rivers/getstations.pl

29 lines
1.0 KiB
Perl
Raw Normal View History

2014-01-05 10:54:46 +00:00
#!/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/
2014-01-04 20:39:39 +00:00
use JSON::PP;
$DEBUG = $ENV{DEBUG};
2014-02-01 13:20:18 +00:00
my @todo = @ARGV;
@ARGV = ();
2014-01-04 20:39:39 +00:00
2014-02-01 13:20:18 +00:00
$script = $ENV{script} || "/path/to/river_levels_";
$urlbase = $ENV{urlbase} || "http://path.to/service";
print STDERR "Decoding...\n" if $DEBUG;
2014-01-04 20:39:39 +00:00
$in = decode_json(<>) or die;
2014-01-07 10:43:18 +00:00
2014-02-01 13:20:18 +00:00
foreach $CatchmentId (@todo) {
$catchment = "Name";
print STDERR "ln -s $script /etc/munin/plugins/river_levels_$CatchmentId\n";
print "[river_levels_$CatchmentId]\nenv.urlbase $urlbase\nenv.stations " unless $DEBUG;
foreach $station (@{$in->{data}}) {
if ($station->{url} =~ /CatchmentId=$CatchmentId$/) {
2014-03-09 13:37:56 +00:00
print "$station->{id}", $DEBUG ? ": $station->{station} on $station->{watercourse}\n" : " " unless $station->{watercourse} eq "Tide";
2014-02-01 13:20:18 +00:00
$catchment = $station->{watercourse} unless $station->{watercourse} eq "Tide";
}
2014-01-04 20:39:39 +00:00
}
2014-02-01 13:20:18 +00:00
print "\nenv.catchmentname $catchment\n\n" unless $DEBUG;
2014-01-04 20:39:39 +00:00
}