From: Sven Hoexter Date: Sun, 6 Nov 2022 15:43:44 +0000 (+0100) Subject: Munin Plugin to monitor the limits in the weblogpro direktvermarkter interface X-Git-Url: https://git.sven.stormbind.net/?a=commitdiff_plain;h=d68633c7d25e5c91a0dbce2d85ed98ad53c24781;p=sven%2Fscripts.git Munin Plugin to monitor the limits in the weblogpro direktvermarkter interface Based on the interface description at https://filer.meteocontrol.de/d/6ec9d0148a/files/?p=%2FTrading%20Interface%2FDeutsch%2FRK_PC_Direktvermarkterschnittstelle_de.pdf --- 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()