1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

feat(weather_hum_): Add a humidity plugin for US NOAA weather

This adds a plugin for relative humidity, based on the weather_press_ and
weather_temp_ plugins. It's basically a copy of these two plugins with only
minor adjustments.
This commit is contained in:
HaseHarald 2023-04-15 17:01:37 +02:00
parent d8b4732c4a
commit 0e4dd7d1fb

42
plugins/weather/weather_hum_ Executable file
View file

@ -0,0 +1,42 @@
#!/usr/bin/env python3
"""
munin US NOAA weather plugin (http://tgftp.nws.noaa.gov)
Draws relative humidity in %.
Copy/link file as 'weather_humidity_CODE', like: weather_humidity_LOWW for Austria, Vienna.
Get the code by going to http://tgftp.nws.noaa.gov, selecting your
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
from urllib.request import urlopen
import re
url = 'https://tgftp.nws.noaa.gov/data/observations/metar/decoded/%s.TXT'
re_hum = re.compile(r'Relative Humidity:\s*(\d+)%')
code = sys.argv[0][(sys.argv[0].rfind('_') + 1):]
if not code:
sys.exit(1)
elif len(sys.argv) == 2 and sys.argv[1] == "autoconf":
print("yes")
elif len(sys.argv) == 2 and sys.argv[1] == "config":
print('graph_title Relative humidity at code %s' % code)
print('graph_vlabel humidity in %')
print('graph_category sensors')
print('humidity.label Humidity')
print('graph_args --base 1000 -l 0')
else:
u = urlopen(url % code)
txt = str(u.read())
u.close()
hum = re_hum.findall(txt)[0]
print('humidity.value %s' % hum)