mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-21 18:41:03 +00:00
Move weather plugins where they belong.
This commit is contained in:
parent
80956e267e
commit
3bb2c5e2aa
3 changed files with 0 additions and 0 deletions
|
@ -1,95 +0,0 @@
|
|||
#!/usr/bin/perl -w
|
||||
#
|
||||
# Copyright (C) 2006 Lars Strand
|
||||
#
|
||||
# Plugin to fetch temperature from weather.noaa.gov
|
||||
#
|
||||
# Parameters supported:
|
||||
#
|
||||
# config
|
||||
# autoconf
|
||||
#
|
||||
# Magic markers:
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf
|
||||
|
||||
use strict;
|
||||
|
||||
my $usehum = $ENV{humidity} || undef; # set to "yes" to enable humidity
|
||||
my $wcode = $ENV{wcode} || "ENGM"; # Find areacode here http://weather.noaa.gov/
|
||||
my $unit = $ENV{unit} || "C"; # "C" = Celsius, "F" = Fahrenheit
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
# Extract weather-code from filename. Example: weather_CODE
|
||||
if ($0 =~ /^(?:|.*\/)temperature_([^_]+)$/) {
|
||||
$wcode = $1;
|
||||
}
|
||||
|
||||
|
||||
my $datasource = "http://weather.noaa.gov/pub/data/observations/metar/decoded/$wcode.TXT";
|
||||
|
||||
my $ua = LWP::UserAgent->new(timeout => 30);
|
||||
$ua->agent('Munin');
|
||||
|
||||
# Use proxy, if defined.
|
||||
if (defined $proxy) {
|
||||
$ua->proxy(['http'], $proxy);
|
||||
}
|
||||
|
||||
my $response = $ua->request(HTTP::Request->new('GET',$datasource));
|
||||
|
||||
if (defined $ARGV[0] and $ARGV[0] eq "config") {
|
||||
|
||||
if ($response->content =~ /^((.*?),.*\)).*\n/) {
|
||||
print "graph_title Temperature at $2\n";
|
||||
} else {
|
||||
print "graph_title Temperature at locationcode $wcode\n";
|
||||
}
|
||||
|
||||
if ($unit =~ /F/) {
|
||||
print "graph_vlabel temp in F\n";
|
||||
} else {
|
||||
print "graph_vlabel temp in C\n";
|
||||
}
|
||||
|
||||
print "graph_args --base 1000 -l 0\n";
|
||||
print "graph_category sensors\n";
|
||||
print "graph_info Temperatures at $1 (fetched from weather.nooa.gov).\n";
|
||||
print "temperature.label temperature\n";
|
||||
if (defined $usehum) {
|
||||
print "humidity.label humidity\n";
|
||||
print "humidity.info Humidity in %.\n";
|
||||
}
|
||||
exit 0;
|
||||
}
|
||||
|
||||
if ($response->content =~ /Temperature:\s*(.*)\s+F\s*\(\s*(.*)\s+C/) {
|
||||
if ($unit =~ /F/) {
|
||||
print "temperature.value $1\n";
|
||||
} else {
|
||||
print "temperature.value $2\n";
|
||||
}
|
||||
} else {
|
||||
print "temperature.value U\n";
|
||||
}
|
||||
|
||||
if (defined $usehum) {
|
||||
if ($response->content =~ /Relative Humidity:\s*(\d+)\%.*/) {
|
||||
print "humidity.value $1\n";
|
||||
}
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
#!/usr/bin/perl -w
|
||||
#
|
||||
# Copyright (C) 2006 Lars Strand
|
||||
#
|
||||
# Plugin to fetch temperature from weather.noaa.gov
|
||||
#
|
||||
# Parameters supported:
|
||||
#
|
||||
# config
|
||||
# autoconf
|
||||
#
|
||||
# Magic markers:
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf
|
||||
|
||||
use strict;
|
||||
|
||||
# Find areacodes here http://weather.noaa.gov/
|
||||
my @wcode = undef;
|
||||
|
||||
if (defined($ENV{wcode})) {
|
||||
@wcode = split(' ', $ENV{wcode});
|
||||
} else {
|
||||
@wcode = ("ENGM", "ENBR", "ENVA", "ENTC");
|
||||
}
|
||||
|
||||
my $unit = $ENV{unit} || "C"; # "C" = Celsius, "F" = Fahrenheit
|
||||
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 Outside temperature\n";
|
||||
print "graph_args --base 1000 -l 0\n";
|
||||
print "graph_category sensors\n";
|
||||
print "graph_info This graph shows temperatures fetched from weather.nooa.gov.\n";
|
||||
|
||||
if ($unit =~ /F/) {
|
||||
print "graph_vlabel temp in F\n";
|
||||
} else {
|
||||
print "graph_vlabel temp in C\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";
|
||||
}
|
||||
}
|
||||
exit 0;
|
||||
}
|
||||
|
||||
for my $station (@wcode) {
|
||||
my $url = "$datasource$station.TXT";
|
||||
my $response = $ua->request(HTTP::Request->new('GET',$url));
|
||||
|
||||
if ($response->content =~ /Temperature:\s*(.*)\s+F\s*\(\s*(.*)\s+C/) {
|
||||
if ($unit =~ /F/) {
|
||||
print "$station.value $1\n";
|
||||
} else {
|
||||
print "$station.value $2\n";
|
||||
}
|
||||
} else {
|
||||
print "$station.value U\n";
|
||||
}
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import urllib
|
||||
|
||||
url = 'http://www.weather.com/weather/today/%s'
|
||||
|
||||
re_tmp = re.compile('realTemp: "(\d+)"')
|
||||
re_hum = re.compile('relativeHumidity: "(\d+)"')
|
||||
re_loc = re.compile('locName: "([\w ]+)"')
|
||||
|
||||
#code = sys.argv[0][(sys.argv[0].rfind('_') + 1):]
|
||||
code = os.environ.get('code', sys.argv[0][(sys.argv[0].rfind('_') + 1):])
|
||||
|
||||
if code == None: sys.exit(1)
|
||||
|
||||
if len(sys.argv) == 2 and sys.argv[1] == "autoconf":
|
||||
print "yes"
|
||||
elif len(sys.argv) == 2 and sys.argv[1] == "config":
|
||||
u = urllib.urlopen(url % code)
|
||||
txt = u.read()
|
||||
u.close()
|
||||
|
||||
LOC_list = re_loc.findall(txt)
|
||||
|
||||
if len(LOC_list):
|
||||
LOC = LOC_list[0]
|
||||
else:
|
||||
LOC = "Unknown"
|
||||
|
||||
print 'graph_title Weather in %s' % LOC
|
||||
print 'graph_vlabel Temperature and Humidity'
|
||||
print 'graph_category sensors'
|
||||
|
||||
print 'temperature.label Temperature'
|
||||
print 'humidity.label Humidity'
|
||||
|
||||
print 'graph_args --base 1000 -l 0'
|
||||
else:
|
||||
u = urllib.urlopen(url % code)
|
||||
txt = u.read()
|
||||
u.close()
|
||||
|
||||
TMP_F_list = re_tmp.findall(txt)
|
||||
HUM_list = re_hum.findall(txt)
|
||||
|
||||
if len(HUM_list):
|
||||
HUM = HUM_list[0]
|
||||
else:
|
||||
sys.exit(1)
|
||||
|
||||
if len(TMP_F_list):
|
||||
TMP_F = TMP_F_list[0]
|
||||
TMP_C = (int(TMP_F) - 32) * 5/9
|
||||
else:
|
||||
sys.exit(1)
|
||||
|
||||
print 'temperature.value %s' % TMP_C
|
||||
print 'humidity.value %s' % HUM
|
Loading…
Add table
Add a link
Reference in a new issue