2012-04-11 12:08:02 +02:00
|
|
|
#!/usr/bin/env python
|
2009-05-25 22:56:50 +02:00
|
|
|
"""
|
2016-08-29 19:23:25 +02:00
|
|
|
munin US NOAA weather plugin (http://tgftp.nws.noaa.gov)
|
2009-05-25 22:56:50 +02:00
|
|
|
|
|
|
|
Draws temperature/dew point in C.
|
|
|
|
Copy/link file as 'weather_temp_CODE', like: weather_temp_LOWW for Austria, Vienna.
|
|
|
|
|
2016-08-29 19:23:25 +02:00
|
|
|
Get the code by going to http://tgftp.nws.noaa.gov, selecting your
|
2009-05-25 22:56:50 +02:00
|
|
|
location, and copying the code from the address bar of your browser; should
|
|
|
|
be something like CODE.html.
|
|
|
|
|
|
|
|
Linux users might need to adjust the shebang.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import urllib
|
|
|
|
import re
|
|
|
|
|
2016-08-29 19:23:25 +02:00
|
|
|
url = 'http://tgftp.nws.noaa.gov/data/observations/metar/decoded/%s.TXT'
|
2009-05-25 22:56:50 +02:00
|
|
|
|
|
|
|
re_C = re.compile('Temperature:.*\((-?\d+\.?\d?) C\)')
|
|
|
|
re_DewC = re.compile('Dew.*\((-?\d+\.?\d?) C\)')
|
|
|
|
|
|
|
|
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":
|
|
|
|
|
|
|
|
print 'graph_title Temperature and Dew Point at code %s' % code
|
|
|
|
print 'graph_vlabel Temperature and Dew Point in C'
|
2017-02-24 17:30:35 +01:00
|
|
|
print 'graph_category sensors'
|
2009-05-25 22:56:50 +02:00
|
|
|
|
|
|
|
print 'temperature.label Temperature'
|
|
|
|
print 'dewpoint.label Dew Point'
|
|
|
|
|
|
|
|
print 'graph_args --base 1000 -l 0'
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
u = urllib.urlopen(url % code)
|
|
|
|
txt = u.read()
|
|
|
|
u.close()
|
|
|
|
|
|
|
|
C = re_C.findall(txt)[0]
|
|
|
|
DewC = re_DewC.findall(txt)[0]
|
|
|
|
|
|
|
|
print 'temperature.value %s' % C
|
|
|
|
print 'dewpoint.value %s' % DewC
|
|
|
|
|