skip invalid dhcp.leases entries #516🩹

This commit is contained in:
Jokob-sk
2023-12-11 11:12:08 +11:00
parent 20f847c6d8
commit 9dd3a0a2d1
2 changed files with 20 additions and 11 deletions

View File

@@ -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__':

View File

@@ -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):