Update opnsense_checkmk_agent.py

This commit is contained in:
Thorsten Spille 2022-01-20 10:32:26 +01:00 committed by GitHub
parent ef78dda27d
commit fab74967d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,7 +22,7 @@
## copy to /usr/local/etc/rc.syshook.d/start/99-checkmk_agent and chmod +x ## copy to /usr/local/etc/rc.syshook.d/start/99-checkmk_agent and chmod +x
## ##
__VERSION__ = "0.61" __VERSION__ = "0.62"
import sys import sys
import os import os
@ -83,6 +83,7 @@ class checkmk_checker(object):
_certificate_timestamp = 0 _certificate_timestamp = 0
def do_checks(self): def do_checks(self):
self._getosinfo() self._getosinfo()
_errors = []
_lines = ["<<<check_mk>>>"] _lines = ["<<<check_mk>>>"]
_lines.append("AgentOS: {os}".format(**self._info)) _lines.append("AgentOS: {os}".format(**self._info))
_lines.append(f"Version: {__VERSION__}") _lines.append(f"Version: {__VERSION__}")
@ -91,16 +92,18 @@ class checkmk_checker(object):
if _check.startswith("check_"): if _check.startswith("check_"):
try: try:
_lines += getattr(self,_check)() _lines += getattr(self,_check)()
except: except Expetion as e:
pass _errors.append(str(e))
_lines.append("<<<local:sep(0)>>>") _lines.append("<<<local:sep(0)>>>")
for _check in dir(self): for _check in dir(self):
if _check.startswith("checklocal_"): if _check.startswith("checklocal_"):
try: try:
_lines += getattr(self,_check)() _lines += getattr(self,_check)()
except: except Exeption as e:
pass _errors.append(str(e))
_lines.append("") _lines.append("")
sys.stderr.write("\n".join(_errors))
sys.stderr.flush()
return "\n".join(_lines) return "\n".join(_lines)
def _getosinfo(self): def _getosinfo(self):
@ -188,13 +191,13 @@ class checkmk_checker(object):
_ifs.update( _ifs.update(
dict( dict(
map( map(
lambda x: ("wg{}".format(x.get("instance")),x.get("name")), lambda x: ("wg{}".format(x.get("instance")),"Wireguard_{}".format(x.get("name").strip().replace(" ","_"))),
_wgserver _wgserver
) )
) )
) )
except: except:
raise pass
return _ifs return _ifs
def checklocal_firmware(self): def checklocal_firmware(self):
@ -313,7 +316,7 @@ class checkmk_checker(object):
if type(_vpnserver) == dict: if type(_vpnserver) == dict:
_vpnserver = [_vpnserver] _vpnserver = [_vpnserver]
for _server in _vpnserver: for _server in _vpnserver:
_server["name"] = _server.get("description") if _server.get("description") else "OpenVPN_{protocoll}_{local_port}".format(**_server) _server["name"] = _server.get("description") if _server.get("description").strip() else "OpenVPN_{protocoll}_{local_port}".format(**_server)
_caref = _server.get("caref") _caref = _server.get("caref")
if not _server.get("maxclients"): if not _server.get("maxclients"):
_max_clients = ipaddress.IPv4Network(_server.get("tunnel_network")).num_addresses -2 _max_clients = ipaddress.IPv4Network(_server.get("tunnel_network")).num_addresses -2
@ -375,6 +378,7 @@ class checkmk_checker(object):
_current_conn = _client.get("current",[]) _current_conn = _client.get("current",[])
if not _client.get("description"): if not _client.get("description"):
_client["description"] = _client.get("common_name") _client["description"] = _client.get("common_name")
_client["description"] = _client["description"].strip(" \r\n")
_client["expiredays"] = 0 _client["expiredays"] = 0
_client["expiredate"] = "no certificate found" _client["expiredate"] = "no certificate found"
_client["status"] = 0 _client["status"] = 0