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/front/plugins")
sys.path.append('/home/pi/pialert/pialert') 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 logger import mylog
from dhcp_leases import DhcpLeases from dhcp_leases import DhcpLeases
@@ -76,16 +76,20 @@ def get_entries(path, plugin_objects):
leases = DhcpLeases(path) leases = DhcpLeases(path)
leasesList = leases.get() leasesList = leases.get()
for lease in leasesList: for lease in leasesList:
plugin_objects.add_object(
primaryId = handleEmpty(lease.ethernet), # filter out irrelevant entries (e.g. from OPNsense dhcp.leases files)
secondaryId = handleEmpty(lease.ip), if is_mac(lease.ethernet):
watched1 = handleEmpty(lease.active),
watched2 = handleEmpty(lease.hostname), plugin_objects.add_object(
watched3 = handleEmpty(lease.hardware), primaryId = handleEmpty(lease.ethernet),
watched4 = handleEmpty(lease.binding_state), secondaryId = handleEmpty(lease.ip),
extra = handleEmpty(path), watched1 = handleEmpty(lease.active),
foreignKey = handleEmpty(lease.ethernet) watched2 = handleEmpty(lease.hostname),
) watched3 = handleEmpty(lease.hardware),
watched4 = handleEmpty(lease.binding_state),
extra = handleEmpty(path),
foreignKey = handleEmpty(lease.ethernet)
)
return plugin_objects return plugin_objects
if __name__ == '__main__': if __name__ == '__main__':

View File

@@ -45,6 +45,11 @@ def handleEmpty(input):
input = re.sub(r'[^\x00-\x7F]+', ' ', input) input = re.sub(r'[^\x00-\x7F]+', ' ', input)
return 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): def decodeBase64(inputParamBase64):