From f34377a8251436b0bc44d439155e84dad39db30d Mon Sep 17 00:00:00 2001 From: Thorsten Spille Date: Wed, 2 Feb 2022 13:49:35 +0100 Subject: [PATCH] Update opnsense_checkmk_agent.py --- opnsense_checkmk_agent.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/opnsense_checkmk_agent.py b/opnsense_checkmk_agent.py index 6846855..a20e5c3 100644 --- a/opnsense_checkmk_agent.py +++ b/opnsense_checkmk_agent.py @@ -22,7 +22,7 @@ ## copy to /usr/local/etc/rc.syshook.d/start/99-checkmk_agent and chmod +x ## -__VERSION__ = "0.69" +__VERSION__ = "0.71" import sys import os @@ -543,7 +543,7 @@ class checkmk_checker(object): def checklocal_ipsec(self): _ret = [] _json_data = subprocess.check_output("/usr/local/opnsense/scripts/ipsec/list_status.py",encoding="utf-8") - if len(_json_data) < 10: + if len(_json_data.strip()) < 20: return [] for _con in json.loads(_json_data).values(): _childsas = None @@ -711,13 +711,34 @@ class checkmk_checker(object): _ret += self._run_prog("df -kTP -t ufs").split("\n")[1:] return _ret + def check_kernel(self): + _ret = ["<<>>"] + _out = self._run_prog("sysctl -a") + _kernel = dict([_v.split(": ") for _v in _out.split("\n") if len(_v.split(": ")) == 2]) + _ret.append("{0:.0f}".format(time.time())) + _ret.append("cpu {0} {1} {2} {4} {3}".format(*(_kernel.get("kern.cp_time","").split(" ")))) + _ret.append("ctxt {0}".format(_kernel.get("vm.stats.sys.v_swtch"))) + _sum = sum(map(lambda x: int(x[1]),(filter(lambda x: x[0] in ("vm.stats.vm.v_forks","vm.stats.vm.v_vforks","vm.stats.vm.v_rforks","vm.stats.vm.v_kthreads"),_kernel.items())))) + _ret.append("processes {0}".format(_sum)) + return _ret + + def check_zpool(self): + _ret = ["<<>>"] + try: + for _line in self._run_prog("zpool status -x").split("\n"): + if _line.find("errors: No known data errors") == -1: + _ret.append(_line) + except: + return [] + return _ret + def check_zfs(self): _ret = ["<<>>"] _ret.append(self._run_prog("zfs get -t filesystem,volume -Hp name,quota,used,avail,mountpoint,type")) _ret.append("[df]") _ret.append(self._run_prog("df -kP -t zfs")) _ret.append("<<>>") - _ret.append(self._run_prog("sysctl -q kstat.zfs.misc.arcstats").replace("kstat.zfs.misc.arcstats.","").strip()) + _ret.append(self._run_prog("sysctl -q kstat.zfs.misc.arcstats").replace("kstat.zfs.misc.arcstats.","").replace(": "," = ").strip()) return _ret def check_mounts(self):