mirror of
https://github.com/bashclub/check-opnsense.git
synced 2024-12-26 00:30:12 +01:00
Update to v0.99.2
This commit is contained in:
parent
02b45f9b19
commit
c77fab530c
@ -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.96"
|
__VERSION__ = "0.99.2"
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
@ -146,6 +146,8 @@ class checkmk_handler(StreamRequestHandler):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
class checkmk_checker(object):
|
class checkmk_checker(object):
|
||||||
|
_available_sysctl_list = []
|
||||||
|
_available_sysctl_temperature_list = []
|
||||||
_certificate_timestamp = 0
|
_certificate_timestamp = 0
|
||||||
_check_cache = {}
|
_check_cache = {}
|
||||||
_datastore_mutex = threading.RLock()
|
_datastore_mutex = threading.RLock()
|
||||||
@ -447,15 +449,21 @@ class checkmk_checker(object):
|
|||||||
_interface_dict["systime"] = _now
|
_interface_dict["systime"] = _now
|
||||||
for _key, _val in re.findall("^\s*(\w+)[:\s=]+(.*?)$",_data,re.MULTILINE):
|
for _key, _val in re.findall("^\s*(\w+)[:\s=]+(.*?)$",_data,re.MULTILINE):
|
||||||
if _key == "description":
|
if _key == "description":
|
||||||
_interface_dict["interface_name"] = _val.strip().replace(" ","_")
|
_interface_dict["interface_name"] = re.sub("_\((lan|wan|opt\d)\)","",_val.strip().replace(" ","_"))
|
||||||
if _key == "groups":
|
if _key == "groups":
|
||||||
_interface_dict["groups"] = _val.strip().split()
|
_interface_dict["groups"] = _val.strip().split()
|
||||||
if _key == "ether":
|
if _key == "ether":
|
||||||
_interface_dict["phys_address"] = _val.strip()
|
_interface_dict["phys_address"] = _val.strip()
|
||||||
if _key == "status" and _val.strip() == "active":
|
if _key == "status" and _val.strip() == "active":
|
||||||
_interface_dict["up"] = "true"
|
_interface_dict["up"] = "true"
|
||||||
|
if _interface.startswith("wg") and _interface_dict.get("flags",0) & 0x01:
|
||||||
|
_interface_dict["up"] = "true"
|
||||||
if _key == "flags":
|
if _key == "flags":
|
||||||
_interface_dict["flags"] = int(re.findall("^[a-f\d]+",_val)[0],16)
|
_interface_dict["flags"] = int(re.findall("^[a-f\d]+",_val)[0],16)
|
||||||
|
## hack pppoe no status active or pppd pid
|
||||||
|
if _interface.lower().startswith("pppoe") and _interface_dict["flags"] & 0x10 and _interface_dict["flags"] & 0x1:
|
||||||
|
_interface_dict["up"] = "true"
|
||||||
|
## http://web.mit.edu/freebsd/head/sys/net/if.h
|
||||||
## 0x1 UP
|
## 0x1 UP
|
||||||
## 0x2 BROADCAST
|
## 0x2 BROADCAST
|
||||||
## 0x8 LOOPBACK
|
## 0x8 LOOPBACK
|
||||||
@ -512,7 +520,7 @@ class checkmk_checker(object):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if _interface_dict["flags"] & 0x2 or _interface_dict["flags"] & 0x10: ## nur broadcast oder ptp
|
if _interface_dict["flags"] & 0x2 or _interface_dict["flags"] & 0x10 or _interface_dict["flags"] & 0x80: ## nur broadcast oder ptp
|
||||||
self._all_interfaces[_interface] = _interface_dict
|
self._all_interfaces[_interface] = _interface_dict
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
@ -790,7 +798,7 @@ class checkmk_checker(object):
|
|||||||
_client = {
|
_client = {
|
||||||
"server" : _server.get("name"),
|
"server" : _server.get("name"),
|
||||||
"common_name" : _client_raw[0],
|
"common_name" : _client_raw[0],
|
||||||
"remote_ip" : _client_raw[1].split(":")[0],
|
"remote_ip" : _client_raw[1].rsplit(":",1)[0], ## ipv6
|
||||||
"vpn_ip" : _client_raw[2],
|
"vpn_ip" : _client_raw[2],
|
||||||
"vpn_ipv6" : _client_raw[3],
|
"vpn_ipv6" : _client_raw[3],
|
||||||
"bytes_received" : int(_client_raw[4]),
|
"bytes_received" : int(_client_raw[4]),
|
||||||
@ -810,6 +818,8 @@ class checkmk_checker(object):
|
|||||||
|
|
||||||
for _client in _monitored_clients.values():
|
for _client in _monitored_clients.values():
|
||||||
_current_conn = _client.get("current",[])
|
_current_conn = _client.get("current",[])
|
||||||
|
if _client.get("disable") == 1:
|
||||||
|
continue
|
||||||
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["description"] = _client["description"].strip(" \r\n")
|
||||||
@ -928,7 +938,7 @@ class checkmk_checker(object):
|
|||||||
if not _client:
|
if not _client:
|
||||||
continue
|
continue
|
||||||
_client["interface"] = _values[0].strip()
|
_client["interface"] = _values[0].strip()
|
||||||
_client["endpoint"] = _values[3].strip().split(":")[0]
|
_client["endpoint"] = _values[3].strip().rsplit(":",1)[0]
|
||||||
_client["last_handshake"] = int(_values[5].strip())
|
_client["last_handshake"] = int(_values[5].strip())
|
||||||
_client["bytes_received"], _client["bytes_sent"] = self._get_traffic("wireguard","",int(_values[6].strip()),int(_values[7].strip()))
|
_client["bytes_received"], _client["bytes_sent"] = self._get_traffic("wireguard","",int(_values[6].strip()),int(_values[7].strip()))
|
||||||
_client["status"] = 2 if _now - _client["last_handshake"] > 300 else 0 ## 5min timeout
|
_client["status"] = 2 if _now - _client["last_handshake"] > 300 else 0 ## 5min timeout
|
||||||
@ -1099,6 +1109,39 @@ class checkmk_checker(object):
|
|||||||
_ret.append("processes {0}".format(_sum))
|
_ret.append("processes {0}".format(_sum))
|
||||||
return _ret
|
return _ret
|
||||||
|
|
||||||
|
def check_temperature(self):
|
||||||
|
_ret = ["<<<lnx_thermal:sep(124)>>>"]
|
||||||
|
_out = self._run_prog("sysctl dev.cpu",timeout=10)
|
||||||
|
_cpus = dict([_v.split(": ") for _v in _out.split("\n") if len(_v.split(": ")) == 2])
|
||||||
|
_cpu_temperatures = list(map(
|
||||||
|
lambda x: float(x[1].replace("C","")),
|
||||||
|
filter(
|
||||||
|
lambda x: x[0].endswith("temperature"),
|
||||||
|
_cpus.items()
|
||||||
|
)
|
||||||
|
))
|
||||||
|
if _cpu_temperatures:
|
||||||
|
_cpu_temperature = int(max(_cpu_temperatures) * 1000)
|
||||||
|
_ret.append(f"CPU|enabled|unknown|{_cpu_temperature}")
|
||||||
|
|
||||||
|
_count = 0
|
||||||
|
for _tempsensor in self._available_sysctl_temperature_list:
|
||||||
|
_out = self._run_prog(f"sysctl -n {_tempsensor}",timeout=10)
|
||||||
|
if _out:
|
||||||
|
try:
|
||||||
|
_zone_temp = int(float(_out.replace("C","")) * 1000)
|
||||||
|
except ValueError:
|
||||||
|
_zone_temp = None
|
||||||
|
if _zone_temp:
|
||||||
|
if _tempsensor.find(".pchtherm.") > -1:
|
||||||
|
_ret.append(f"thermal_zone{_count}|enabled|unknown|{_zone_temp}|111000|critical|108000|passive")
|
||||||
|
else:
|
||||||
|
_ret.append(f"thermal_zone{_count}|enabled|unknown|{_zone_temp}")
|
||||||
|
_count += 1
|
||||||
|
if len(_ret) < 2:
|
||||||
|
return []
|
||||||
|
return _ret
|
||||||
|
|
||||||
def check_mem(self):
|
def check_mem(self):
|
||||||
_ret = ["<<<statgrab_mem>>>"]
|
_ret = ["<<<statgrab_mem>>>"]
|
||||||
_pagesize = int(self._run_prog("sysctl -n hw.pagesize"))
|
_pagesize = int(self._run_prog("sysctl -n hw.pagesize"))
|
||||||
@ -1273,6 +1316,8 @@ class checkmk_server(TCPServer,checkmk_checker):
|
|||||||
self.pidfile = pidfile
|
self.pidfile = pidfile
|
||||||
self.onlyfrom = onlyfrom.split(",") if onlyfrom else None
|
self.onlyfrom = onlyfrom.split(",") if onlyfrom else None
|
||||||
self.skipcheck = skipcheck.split(",") if skipcheck else []
|
self.skipcheck = skipcheck.split(",") if skipcheck else []
|
||||||
|
self._available_sysctl_list = self._run_prog("sysctl -aN").split()
|
||||||
|
self._available_sysctl_temperature_list = list(filter(lambda x: x.lower().find("temperature") > -1 and x.lower().find("cpu") == -1,self._available_sysctl_list))
|
||||||
self.encryptionkey = encryptionkey
|
self.encryptionkey = encryptionkey
|
||||||
self._mutex = threading.Lock()
|
self._mutex = threading.Lock()
|
||||||
self.user = pwd.getpwnam(user)
|
self.user = pwd.getpwnam(user)
|
||||||
|
Loading…
Reference in New Issue
Block a user