From 7b4b43463a819f310827490b01dc07dbcd651685 Mon Sep 17 00:00:00 2001 From: Jokob-sk Date: Tue, 30 Jan 2024 22:19:59 +1100 Subject: [PATCH] NSLOOKUP v0.1.5 --- .github/workflows/update_sponsors_table.yml | 2 +- pialert/device.py | 12 +++++++-- pialert/helper.py | 27 +++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/.github/workflows/update_sponsors_table.yml b/.github/workflows/update_sponsors_table.yml index 9aadff41..fac4c067 100755 --- a/.github/workflows/update_sponsors_table.yml +++ b/.github/workflows/update_sponsors_table.yml @@ -2,7 +2,7 @@ name: đŸ¤–Automation - Update Sponsors Table on: schedule: - - cron: '47 20 * * *' # Set your preferred schedule (UTC) + - cron: '30 11 * * *' # Set your preferred schedule (UTC) jobs: update-table: diff --git a/pialert/device.py b/pialert/device.py index 0f02b344..f656be57 100755 --- a/pialert/device.py +++ b/pialert/device.py @@ -3,7 +3,7 @@ import subprocess import conf import re -from helper import timeNowTZ, get_setting, get_setting_value,resolve_device_name_dig, resolve_device_name_pholus, check_IP_format +from helper import timeNowTZ, get_setting, get_setting_value,resolve_device_name_dig, resolve_device_name_pholus, get_device_name_nslookup, check_IP_format from logger import mylog, print_log from const import vendorsPath @@ -286,6 +286,7 @@ def update_devices_names (db): notFound = 0 foundDig = 0 + foundNsLookup = 0 foundPholus = 0 # BUGFIX #97 - Updating name of Devices w/o IP @@ -318,6 +319,13 @@ def update_devices_names (db): if newName != nameNotFound: foundDig += 1 + # Resolve device name with NSLOOKUP plugin data + if newName == nameNotFound: + newName = get_device_name_nslookup(db, device['dev_MAC'], device['dev_LastIP']) + + if newName != nameNotFound: + foundNsLookup += 1 + # Resolve with Pholus if newName == nameNotFound: # Try MAC matching @@ -341,7 +349,7 @@ def update_devices_names (db): recordsToUpdate.append ([newName, device['dev_MAC']]) # Print log - mylog('verbose', ['[Update Device Name] Names Found (DiG/Pholus): ', len(recordsToUpdate), " (",foundDig,"/",foundPholus ,")"] ) + mylog('verbose', ['[Update Device Name] Names Found (DiG/NSlookup/Pholus): ', len(recordsToUpdate), " (",foundDig,"/",foundNsLookup,"/",foundPholus ,")"] ) mylog('verbose', ['[Update Device Name] Names Not Found : ', len(recordsNotFound)] ) # update not found devices with (name not found) diff --git a/pialert/helper.py b/pialert/helper.py index 3336688f..8ca286a4 100755 --- a/pialert/helper.py +++ b/pialert/helper.py @@ -361,6 +361,33 @@ def check_IP_format (pIP): +#------------------------------------------------------------------------------- +def get_device_name_nslookup(db, pMAC, pIP): + + nameNotFound = "(name not found)" + + sql = db.sql + + name = nameNotFound + + # get names from the NSLOOKUP plugin entries + sql.execute( + f""" + SELECT Watched_Value2 FROM Plugins_Objects + WHERE + Plugin = 'NSLOOKUP' AND + (Object_PrimaryID = '{pMAC}' OR Object_SecondaryID = '{pIP}') + """ + ) + nslookupEntry = sql.fetchall() + db.commitDB() + + if len(nslookupEntry) != 0: + name = nslookupEntry[0][0] + + return name + + #------------------------------------------------------------------------------- def resolve_device_name_dig (pMAC, pIP):