X-Git-Url: https://git.sven.stormbind.net/?p=sven%2Fscripts.git;a=blobdiff_plain;f=weblogpro%2Fmon_pc.py;fp=weblogpro%2Fmon_pc.py;h=f120c5c041de458ba49f7d81332b9b20156959dc;hp=0000000000000000000000000000000000000000;hb=d68633c7d25e5c91a0dbce2d85ed98ad53c24781;hpb=f440a8956d7f05c3c32f867d5373458943bcbffc diff --git a/weblogpro/mon_pc.py b/weblogpro/mon_pc.py new file mode 100755 index 0000000..f120c5c --- /dev/null +++ b/weblogpro/mon_pc.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 +""" +=head1 NAME + +mon_pc - Monitor meteocontrol weblog pro direktvermarkter interface limits + +=head1 CONFIGURATION + +Usage: place in /etc/munin/plugins/ or link it there + +Parameters understood: + + config (required) + +=head1 AUTHORS + +Copyright 2022 Sven Hoexter + +=head1 MAGIC MARKERS + + #%# family=manual + +=cut +""" + +import sys +import os +import xml.etree.ElementTree as ET +import requests + +#initialize configuration env vars and set defaults +host = os.environ.get('host', 'localhost') +port = os.environ.get('port', '8888') +req = os.environ.get( + 'req', + '/GetDmiValue.cgi?q=M_AC_P+PC_P_PERC_ABS+PC_P_PERC_GRIDOP+PC_P_PERC_DMI') + + +def fetchDmi(host, port, req): + # download DMI XML data + try: + r = requests.get('http://' + host + ':' + port + req) + except requests.exceptions.RequestException as e: + raise SystemExit(e) + + root = ET.fromstring(r.text) + for child in root: + print( + f"{child.attrib['name'].lower()}.value {int(float(child.attrib['value']))}" + ) + + +def main(): + if len(sys.argv) > 1: + if sys.argv[1] == "config": + print("graph_title Wirkleistungsbegrenzung") + print("graph_vlabel %") + print("pc_p_perc_dmi.label Begrenzung Direktvermarkter") + print("pc_p_perc_gridop.label Begrenzung Netzbetreiber") + print("pc_p_perc_abs.label Begrenzung Absolut") + print("graph_args --base 1000 -r -u 100 -l 0") + print("graph_scale no") + print("graph yes") + print("graph_category pv") + print("graph_info Statistics from the Dmi Interface.") + sys.exit() + + # no args + fetchDmi(host, port, req) + + +main()