From 9dd3a0a2d1a39c7162020d0c52daa2dd45a8a4af Mon Sep 17 00:00:00 2001 From: Jokob-sk Date: Mon, 11 Dec 2023 11:12:08 +1100 Subject: [PATCH] =?UTF-8?q?skip=20invalid=20dhcp.leases=20entries=20#516?= =?UTF-8?q?=F0=9F=A9=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/plugins/dhcp_leases/script.py | 26 +++++++++++++++----------- front/plugins/plugin_helper.py | 5 +++++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/front/plugins/dhcp_leases/script.py b/front/plugins/dhcp_leases/script.py index 599c73ad..a5ab4410 100755 --- a/front/plugins/dhcp_leases/script.py +++ b/front/plugins/dhcp_leases/script.py @@ -11,7 +11,7 @@ import chardet sys.path.append("/home/pi/pialert/front/plugins") sys.path.append('/home/pi/pialert/pialert') -from plugin_helper import Plugin_Object, Plugin_Objects, handleEmpty +from plugin_helper import Plugin_Object, Plugin_Objects, handleEmpty, is_mac from logger import mylog from dhcp_leases import DhcpLeases @@ -76,16 +76,20 @@ def get_entries(path, plugin_objects): leases = DhcpLeases(path) leasesList = leases.get() for lease in leasesList: - plugin_objects.add_object( - primaryId = handleEmpty(lease.ethernet), - secondaryId = handleEmpty(lease.ip), - watched1 = handleEmpty(lease.active), - watched2 = handleEmpty(lease.hostname), - watched3 = handleEmpty(lease.hardware), - watched4 = handleEmpty(lease.binding_state), - extra = handleEmpty(path), - foreignKey = handleEmpty(lease.ethernet) - ) + + # filter out irrelevant entries (e.g. from OPNsense dhcp.leases files) + if is_mac(lease.ethernet): + + plugin_objects.add_object( + primaryId = handleEmpty(lease.ethernet), + secondaryId = handleEmpty(lease.ip), + watched1 = handleEmpty(lease.active), + watched2 = handleEmpty(lease.hostname), + watched3 = handleEmpty(lease.hardware), + watched4 = handleEmpty(lease.binding_state), + extra = handleEmpty(path), + foreignKey = handleEmpty(lease.ethernet) + ) return plugin_objects if __name__ == '__main__': diff --git a/front/plugins/plugin_helper.py b/front/plugins/plugin_helper.py index 9c3abf06..2d7d2205 100755 --- a/front/plugins/plugin_helper.py +++ b/front/plugins/plugin_helper.py @@ -45,6 +45,11 @@ def handleEmpty(input): input = re.sub(r'[^\x00-\x7F]+', ' ', input) return input +# ------------------------------------------------------------------- +# Check if a valid MAC address +def is_mac(input): + return re.match("[0-9a-f]{2}([-:]?)[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$", input.lower()) + # ------------------------------------------------------------------- def decodeBase64(inputParamBase64):