diff --git a/plugins/other/humidity-sensor b/plugins/other/humidity-sensor new file mode 100755 index 00000000..3c96b8f7 --- /dev/null +++ b/plugins/other/humidity-sensor @@ -0,0 +1,72 @@ +#!/usr/bin/perl -w +# +# Copyright (C) Viktoras Pecia 2010(Based on 2006 Lars Strand "temperatures" code) +# +# Plugin to fetch humidity from weather.noaa.gov +# +# Parameters supported: +# +# config +# autoconf +# +# Magic markers: +#%# family=auto +#%# capabilities=autoconf + +use strict; +my @wcode = undef; +if (defined($ENV{wcode})) { + @wcode = split(' ', $ENV{wcode}); +} else { + @wcode = ("EYSA","EYKA","EYPA","EYVI"); +} +my $proxy = $ENV{proxy} || undef; # Example: "http://proxy.foo.bar:8080/" +my $ret = undef; +if (! eval "require LWP::UserAgent;") +{ + $ret = "LWP::UserAgent not found"; +} +if (defined $ARGV[0] and $ARGV[0] eq "autoconf") { + if (defined $ret) { + print "no ($ret)\n"; + exit 1; + } else { + print "yes\n"; + exit 0; + } +} +my $datasource = "http://weather.noaa.gov/pub/data/observations/metar/decoded/"; + +my $ua = LWP::UserAgent->new(timeout => 30); +$ua->agent('Munin'); +# Use proxy, if defined. +if (defined($proxy)) { + $ua->proxy(['http'], $proxy); +} +if (defined $ARGV[0] and $ARGV[0] eq "config") { + print "graph_title Humidity\n"; + print "graph_args --base 1000 -l 0\n"; + print "graph_category sensors\n"; + print "graph_info This graph shows humidity fetched from weather.nooa.gov.\n"; + print "graph_vlabel humidity in %\n"; + for my $station (@wcode) { + my $url = "$datasource$station.TXT"; + my $response = $ua->request(HTTP::Request->new('GET',$url)); + # New York City, Central Park, NY, United States (KNYC) 40-47-00N 073-58-00W 48M + if ($response->content =~ /^((.*?),.*\)).*\n/) { + print "$station.label $2\n"; + print "$station.info $1\n"; + } else { + print "$station.label $station\n"; + } + } +} +for my $station (@wcode) { + my $url = "$datasource$station.TXT"; + my $response = $ua->request(HTTP::Request->new('GET',$url)); + if ($response->content =~ /Relative Humidity:\s*(\d+)\%.*/) { + print "$station.value $1\n"; + } else { + print "$station.value U\n"; + } + } \ No newline at end of file