]> git.sven.stormbind.net Git - sven/scripts.git/blob - weblogpro/mon_pc.py
Munin Plugin to monitor the limits in the weblogpro direktvermarkter interface
[sven/scripts.git] / weblogpro / mon_pc.py
1 #!/usr/bin/env python3
2 """
3 =head1 NAME
4
5 mon_pc - Monitor meteocontrol weblog pro direktvermarkter interface limits
6
7 =head1 CONFIGURATION
8
9 Usage: place in /etc/munin/plugins/ or link it there
10
11 Parameters understood:
12
13  config   (required)
14
15 =head1 AUTHORS
16
17 Copyright 2022 Sven Hoexter <sven@stormbind.net>
18
19 =head1 MAGIC MARKERS
20
21  #%# family=manual
22
23 =cut
24 """
25
26 import sys
27 import os
28 import xml.etree.ElementTree as ET
29 import requests
30
31 #initialize configuration env vars and set defaults
32 host = os.environ.get('host', 'localhost')
33 port = os.environ.get('port', '8888')
34 req = os.environ.get(
35     'req',
36     '/GetDmiValue.cgi?q=M_AC_P+PC_P_PERC_ABS+PC_P_PERC_GRIDOP+PC_P_PERC_DMI')
37
38
39 def fetchDmi(host, port, req):
40     # download DMI XML data
41     try:
42         r = requests.get('http://' + host + ':' + port + req)
43     except requests.exceptions.RequestException as e:
44         raise SystemExit(e)
45
46     root = ET.fromstring(r.text)
47     for child in root:
48         print(
49             f"{child.attrib['name'].lower()}.value {int(float(child.attrib['value']))}"
50         )
51
52
53 def main():
54     if len(sys.argv) > 1:
55         if sys.argv[1] == "config":
56             print("graph_title Wirkleistungsbegrenzung")
57             print("graph_vlabel %")
58             print("pc_p_perc_dmi.label Begrenzung Direktvermarkter")
59             print("pc_p_perc_gridop.label Begrenzung Netzbetreiber")
60             print("pc_p_perc_abs.label Begrenzung Absolut")
61             print("graph_args --base 1000 -r -u 100 -l 0")
62             print("graph_scale no")
63             print("graph yes")
64             print("graph_category pv")
65             print("graph_info Statistics from the Dmi Interface.")
66             sys.exit()
67
68     # no args
69     fetchDmi(host, port, req)
70
71
72 main()