From c86550940769517fa28efef1130c8363faba6333 Mon Sep 17 00:00:00 2001 From: Starkstromkonsument Date: Thu, 22 Apr 2021 16:27:53 +0200 Subject: [PATCH] net-mgmt/zabbix-proxy: add logfile and logformat to WebUI (#1937) --- net-mgmt/zabbix4-proxy/Makefile | 3 +- net-mgmt/zabbix4-proxy/pkg-descr | 4 ++ .../models/OPNsense/Zabbixproxy/ACL/ACL.xml | 2 + .../models/OPNsense/Zabbixproxy/Menu/Menu.xml | 5 +- .../systemhealth/logformats/zabbix_proxy.py | 56 +++++++++++++++++++ net-mgmt/zabbix5-proxy/pkg-descr | 1 + .../models/OPNsense/Zabbixproxy/ACL/ACL.xml | 2 + .../models/OPNsense/Zabbixproxy/Menu/Menu.xml | 5 +- .../systemhealth/logformats/zabbix_proxy.py | 56 +++++++++++++++++++ 9 files changed, 130 insertions(+), 4 deletions(-) create mode 100644 net-mgmt/zabbix4-proxy/src/opnsense/scripts/systemhealth/logformats/zabbix_proxy.py create mode 100644 net-mgmt/zabbix5-proxy/src/opnsense/scripts/systemhealth/logformats/zabbix_proxy.py diff --git a/net-mgmt/zabbix4-proxy/Makefile b/net-mgmt/zabbix4-proxy/Makefile index d9ece0f6f..97c8cc9b6 100644 --- a/net-mgmt/zabbix4-proxy/Makefile +++ b/net-mgmt/zabbix4-proxy/Makefile @@ -1,6 +1,5 @@ PLUGIN_NAME= zabbix4-proxy -PLUGIN_VERSION= 1.2 -PLUGIN_REVISION= 1 +PLUGIN_VERSION= 1.3 PLUGIN_COMMENT= Zabbix Proxy enables decentralized monitoring PLUGIN_DEPENDS= zabbix4-proxy PLUGIN_CONFLICTS= zabbix5-proxy diff --git a/net-mgmt/zabbix4-proxy/pkg-descr b/net-mgmt/zabbix4-proxy/pkg-descr index d60b33add..32d9a8c1a 100644 --- a/net-mgmt/zabbix4-proxy/pkg-descr +++ b/net-mgmt/zabbix4-proxy/pkg-descr @@ -12,6 +12,10 @@ WWW: http://www.zabbix.com/ Plugin Changelog ---------------- +1.3 + +* Add logfile to WebUI (Starkstromkonsument ) + 1.2 * Allow adding multiple listen addresses diff --git a/net-mgmt/zabbix4-proxy/src/opnsense/mvc/app/models/OPNsense/Zabbixproxy/ACL/ACL.xml b/net-mgmt/zabbix4-proxy/src/opnsense/mvc/app/models/OPNsense/Zabbixproxy/ACL/ACL.xml index 6166a2c68..77a65e879 100644 --- a/net-mgmt/zabbix4-proxy/src/opnsense/mvc/app/models/OPNsense/Zabbixproxy/ACL/ACL.xml +++ b/net-mgmt/zabbix4-proxy/src/opnsense/mvc/app/models/OPNsense/Zabbixproxy/ACL/ACL.xml @@ -4,6 +4,8 @@ ui/zabbixproxy/* api/zabbixproxy/* + ui/diagnostics/log/core/zabbix_proxy/* + api/diagnostics/log/core/zabbix_proxy/* diff --git a/net-mgmt/zabbix4-proxy/src/opnsense/mvc/app/models/OPNsense/Zabbixproxy/Menu/Menu.xml b/net-mgmt/zabbix4-proxy/src/opnsense/mvc/app/models/OPNsense/Zabbixproxy/Menu/Menu.xml index 7b5301743..1b0ed8a10 100644 --- a/net-mgmt/zabbix4-proxy/src/opnsense/mvc/app/models/OPNsense/Zabbixproxy/Menu/Menu.xml +++ b/net-mgmt/zabbix4-proxy/src/opnsense/mvc/app/models/OPNsense/Zabbixproxy/Menu/Menu.xml @@ -1,5 +1,8 @@ - + + + + diff --git a/net-mgmt/zabbix4-proxy/src/opnsense/scripts/systemhealth/logformats/zabbix_proxy.py b/net-mgmt/zabbix4-proxy/src/opnsense/scripts/systemhealth/logformats/zabbix_proxy.py new file mode 100644 index 000000000..cc691a2ee --- /dev/null +++ b/net-mgmt/zabbix4-proxy/src/opnsense/scripts/systemhealth/logformats/zabbix_proxy.py @@ -0,0 +1,56 @@ +""" + Copyright (c) 2020 Ad Schellevis + Copyright (C) 2020 Starkstromkonsument + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +""" +import re +import datetime +from . import BaseLogFormat +zabbix_timeformat = r'(\d*):(\d{4}\d{2}\d{2}:\d{2}\d{2}\d{2})\.\d{3}\s(.*)' + + +class ZabbixLogFormat(BaseLogFormat): + def __init__(self, filename): + super(ZabbixLogFormat, self).__init__(filename) + self._priority = 100 + + def match(self, line): + return self._filename.find('zabbix_proxy') > -1 and re.match(zabbix_timeformat, line) is not None + + @staticmethod + def timestamp(line): + tmp = re.match(zabbix_timeformat, line) + grp = tmp.group(2) + return datetime.datetime.strptime(grp, "%Y%m%d:%H%M%S").isoformat() + + @staticmethod + def process_name(line): + tmp = re.match(zabbix_timeformat, line) + return tmp.group(1) + + @staticmethod + def line(line): + tmp = re.match(zabbix_timeformat, line) + return tmp.group(3) + diff --git a/net-mgmt/zabbix5-proxy/pkg-descr b/net-mgmt/zabbix5-proxy/pkg-descr index 64c6f3d22..58238b6d6 100644 --- a/net-mgmt/zabbix5-proxy/pkg-descr +++ b/net-mgmt/zabbix5-proxy/pkg-descr @@ -21,6 +21,7 @@ Plugin Changelog 1.3 * Switch to zabbix5-proxy +* Add logfile to WebUI (Starkstromkonsument ) 1.2 diff --git a/net-mgmt/zabbix5-proxy/src/opnsense/mvc/app/models/OPNsense/Zabbixproxy/ACL/ACL.xml b/net-mgmt/zabbix5-proxy/src/opnsense/mvc/app/models/OPNsense/Zabbixproxy/ACL/ACL.xml index 6166a2c68..9b1dd7b5b 100644 --- a/net-mgmt/zabbix5-proxy/src/opnsense/mvc/app/models/OPNsense/Zabbixproxy/ACL/ACL.xml +++ b/net-mgmt/zabbix5-proxy/src/opnsense/mvc/app/models/OPNsense/Zabbixproxy/ACL/ACL.xml @@ -4,6 +4,8 @@ ui/zabbixproxy/* api/zabbixproxy/* + ui/diagnostics/log/zabbix/zabbix_proxy/* + api/diagnostics/log/zabbix/zabbix_proxy/* diff --git a/net-mgmt/zabbix5-proxy/src/opnsense/mvc/app/models/OPNsense/Zabbixproxy/Menu/Menu.xml b/net-mgmt/zabbix5-proxy/src/opnsense/mvc/app/models/OPNsense/Zabbixproxy/Menu/Menu.xml index 7b5301743..c4813378c 100644 --- a/net-mgmt/zabbix5-proxy/src/opnsense/mvc/app/models/OPNsense/Zabbixproxy/Menu/Menu.xml +++ b/net-mgmt/zabbix5-proxy/src/opnsense/mvc/app/models/OPNsense/Zabbixproxy/Menu/Menu.xml @@ -1,5 +1,8 @@ - + + + + diff --git a/net-mgmt/zabbix5-proxy/src/opnsense/scripts/systemhealth/logformats/zabbix_proxy.py b/net-mgmt/zabbix5-proxy/src/opnsense/scripts/systemhealth/logformats/zabbix_proxy.py new file mode 100644 index 000000000..cc691a2ee --- /dev/null +++ b/net-mgmt/zabbix5-proxy/src/opnsense/scripts/systemhealth/logformats/zabbix_proxy.py @@ -0,0 +1,56 @@ +""" + Copyright (c) 2020 Ad Schellevis + Copyright (C) 2020 Starkstromkonsument + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +""" +import re +import datetime +from . import BaseLogFormat +zabbix_timeformat = r'(\d*):(\d{4}\d{2}\d{2}:\d{2}\d{2}\d{2})\.\d{3}\s(.*)' + + +class ZabbixLogFormat(BaseLogFormat): + def __init__(self, filename): + super(ZabbixLogFormat, self).__init__(filename) + self._priority = 100 + + def match(self, line): + return self._filename.find('zabbix_proxy') > -1 and re.match(zabbix_timeformat, line) is not None + + @staticmethod + def timestamp(line): + tmp = re.match(zabbix_timeformat, line) + grp = tmp.group(2) + return datetime.datetime.strptime(grp, "%Y%m%d:%H%M%S").isoformat() + + @staticmethod + def process_name(line): + tmp = re.match(zabbix_timeformat, line) + return tmp.group(1) + + @staticmethod + def line(line): + tmp = re.match(zabbix_timeformat, line) + return tmp.group(3) +