NSLOOKUP v0.1.7
This commit is contained in:
@@ -140,5 +140,7 @@ fi
|
|||||||
# Activate the virtual python environment
|
# Activate the virtual python environment
|
||||||
source myenv/bin/activate
|
source myenv/bin/activate
|
||||||
|
|
||||||
|
echo "[INSTALL] 🟢 Starting app - navigate to your <server IP>:20211 (or custom port)"
|
||||||
|
|
||||||
# Start the PiAlert python script
|
# Start the PiAlert python script
|
||||||
python $INSTALL_DIR/pialert/pialert/
|
python $INSTALL_DIR/pialert/pialert/
|
||||||
|
|||||||
@@ -174,8 +174,10 @@ def main ():
|
|||||||
updateState("Process: Wait")
|
updateState("Process: Wait")
|
||||||
mylog('verbose', ['[MAIN] Process: Wait'])
|
mylog('verbose', ['[MAIN] Process: Wait'])
|
||||||
else:
|
else:
|
||||||
# do something
|
# do something
|
||||||
mylog('verbose', ['[MAIN] waiting to start next loop'])
|
# mylog('verbose', ['[MAIN] Waiting to start next loop'])
|
||||||
|
dummyVariable = 1
|
||||||
|
|
||||||
|
|
||||||
#loop
|
#loop
|
||||||
time.sleep(5) # wait for N seconds
|
time.sleep(5) # wait for N seconds
|
||||||
|
|||||||
@@ -289,7 +289,7 @@ def update_devices_names (db):
|
|||||||
foundNsLookup = 0
|
foundNsLookup = 0
|
||||||
foundPholus = 0
|
foundPholus = 0
|
||||||
|
|
||||||
# BUGFIX #97 - Updating name of Devices w/o IP
|
# Gen unknown devices
|
||||||
sql.execute ("SELECT * FROM Devices WHERE dev_Name IN ('(unknown)','', '(name not found)') AND dev_LastIP <> '-'")
|
sql.execute ("SELECT * FROM Devices WHERE dev_Name IN ('(unknown)','', '(name not found)') AND dev_LastIP <> '-'")
|
||||||
unknownDevices = sql.fetchall()
|
unknownDevices = sql.fetchall()
|
||||||
db.commitDB()
|
db.commitDB()
|
||||||
@@ -299,7 +299,7 @@ def update_devices_names (db):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Devices without name
|
# Devices without name
|
||||||
mylog('verbose', '[Update Device Name] Trying to resolve devices without name')
|
mylog('verbose', f'[Update Device Name] Trying to resolve devices without name. Unknown devices count: {len(unknownDevices)}')
|
||||||
|
|
||||||
# get names from Pholus scan
|
# get names from Pholus scan
|
||||||
sql.execute ('SELECT * FROM Pholus_Scan where "Record_Type"="Answer"')
|
sql.execute ('SELECT * FROM Pholus_Scan where "Record_Type"="Answer"')
|
||||||
@@ -309,6 +309,7 @@ def update_devices_names (db):
|
|||||||
# Number of entries from previous Pholus scans
|
# Number of entries from previous Pholus scans
|
||||||
mylog('verbose', ['[Update Device Name] Pholus entries from prev scans: ', len(pholusResults)])
|
mylog('verbose', ['[Update Device Name] Pholus entries from prev scans: ', len(pholusResults)])
|
||||||
|
|
||||||
|
|
||||||
for device in unknownDevices:
|
for device in unknownDevices:
|
||||||
newName = nameNotFound
|
newName = nameNotFound
|
||||||
|
|
||||||
@@ -328,6 +329,7 @@ def update_devices_names (db):
|
|||||||
|
|
||||||
# Resolve with Pholus
|
# Resolve with Pholus
|
||||||
if newName == nameNotFound:
|
if newName == nameNotFound:
|
||||||
|
|
||||||
# Try MAC matching
|
# Try MAC matching
|
||||||
newName = resolve_device_name_pholus (device['dev_MAC'], device['dev_LastIP'], pholusResults, nameNotFound, False)
|
newName = resolve_device_name_pholus (device['dev_MAC'], device['dev_LastIP'], pholusResults, nameNotFound, False)
|
||||||
# Try IP matching
|
# Try IP matching
|
||||||
@@ -338,8 +340,11 @@ def update_devices_names (db):
|
|||||||
if newName != nameNotFound:
|
if newName != nameNotFound:
|
||||||
foundPholus += 1
|
foundPholus += 1
|
||||||
|
|
||||||
# isf still not found update name so we can distinguish the devices where we tried already
|
# if still not found update name so we can distinguish the devices where we tried already
|
||||||
if newName == nameNotFound :
|
if newName == nameNotFound :
|
||||||
|
|
||||||
|
notFound += 1
|
||||||
|
|
||||||
# if dev_Name is the same as what we will change it to, take no action
|
# if dev_Name is the same as what we will change it to, take no action
|
||||||
# this mitigates a race condition which would overwrite a users edits that occured since the select earlier
|
# this mitigates a race condition which would overwrite a users edits that occured since the select earlier
|
||||||
if device['dev_Name'] != nameNotFound:
|
if device['dev_Name'] != nameNotFound:
|
||||||
@@ -349,8 +354,8 @@ def update_devices_names (db):
|
|||||||
recordsToUpdate.append ([newName, device['dev_MAC']])
|
recordsToUpdate.append ([newName, device['dev_MAC']])
|
||||||
|
|
||||||
# Print log
|
# Print log
|
||||||
mylog('verbose', ['[Update Device Name] Names Found (DiG/NSlookup/Pholus): ', len(recordsToUpdate), " (",foundDig,"/",foundNsLookup,"/",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)] )
|
mylog('verbose', ['[Update Device Name] Names Not Found : ', notFound] )
|
||||||
|
|
||||||
# update not found devices with (name not found)
|
# update not found devices with (name not found)
|
||||||
sql.executemany ("UPDATE Devices SET dev_Name = ? WHERE dev_MAC = ? ", recordsNotFound )
|
sql.executemany ("UPDATE Devices SET dev_Name = ? WHERE dev_MAC = ? ", recordsNotFound )
|
||||||
|
|||||||
@@ -370,20 +370,39 @@ def get_device_name_nslookup(db, pMAC, pIP):
|
|||||||
|
|
||||||
name = nameNotFound
|
name = nameNotFound
|
||||||
|
|
||||||
# get names from the NSLOOKUP plugin entries
|
# get names from the NSLOOKUP plugin entries vased on MAC
|
||||||
sql.execute(
|
sql.execute(
|
||||||
f"""
|
f"""
|
||||||
SELECT Watched_Value2 FROM Plugins_Objects
|
SELECT Watched_Value2 FROM Plugins_Objects
|
||||||
WHERE
|
WHERE
|
||||||
Plugin = 'NSLOOKUP' AND
|
Plugin = 'NSLOOKUP' AND
|
||||||
(Object_PrimaryID = '{pMAC}' OR Object_SecondaryID = '{pIP}')
|
Object_PrimaryID = '{pMAC}'
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
nslookupEntry = sql.fetchall()
|
nslookupEntry = sql.fetchall()
|
||||||
db.commitDB()
|
db.commitDB()
|
||||||
|
|
||||||
if len(nslookupEntry) != 0:
|
if len(nslookupEntry) != 0:
|
||||||
name = cleanDeviceName(nslookupEntry[0][0])
|
name = cleanDeviceName(nslookupEntry[0][0], False)
|
||||||
|
|
||||||
|
return name
|
||||||
|
|
||||||
|
# get names from the NSLOOKUP plugin entries based on IP
|
||||||
|
sql.execute(
|
||||||
|
f"""
|
||||||
|
SELECT Watched_Value2 FROM Plugins_Objects
|
||||||
|
WHERE
|
||||||
|
Plugin = 'NSLOOKUP' AND
|
||||||
|
Object_SecondaryID = '{pIP}'
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
nslookupEntry = sql.fetchall()
|
||||||
|
db.commitDB()
|
||||||
|
|
||||||
|
if len(nslookupEntry) != 0:
|
||||||
|
name = cleanDeviceName(nslookupEntry[0][0], True)
|
||||||
|
|
||||||
|
return name
|
||||||
|
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user