mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
attempt to fix issue #6 as well as db.read_one()
This commit is contained in:
@@ -300,7 +300,7 @@ def main ():
|
|||||||
else:
|
else:
|
||||||
# do something
|
# do something
|
||||||
conf.cycle = ""
|
conf.cycle = ""
|
||||||
mylog('verbose', ['[MAIN] waiting to start next loop'])
|
mylog('verbose', ['[MAIN] waiting to start next loop'])
|
||||||
|
|
||||||
#loop
|
#loop
|
||||||
time.sleep(5) # wait for N seconds
|
time.sleep(5) # wait for N seconds
|
||||||
|
|||||||
@@ -31,7 +31,10 @@ sql_devices_all = """select dev_MAC, dev_Name, dev_DeviceType, dev_Vendor, dev_G
|
|||||||
dev_PresentLastScan, dev_LastNotification, dev_NewDevice,
|
dev_PresentLastScan, dev_LastNotification, dev_NewDevice,
|
||||||
dev_Network_Node_MAC_ADDR, dev_Network_Node_port,
|
dev_Network_Node_MAC_ADDR, dev_Network_Node_port,
|
||||||
dev_Icon from Devices"""
|
dev_Icon from Devices"""
|
||||||
sql_devices_stats = "SELECT Online_Devices as online, Down_Devices as down, All_Devices as 'all', Archived_Devices as archived, (select count(*) from Devices a where dev_NewDevice = 1 ) as new, (select count(*) from Devices a where dev_Name = '(unknown)' or dev_Name = '(name not found)' ) as unknown from Online_History order by Scan_Date desc limit 1"
|
sql_devices_stats = """SELECT Online_Devices as online, Down_Devices as down, All_Devices as 'all', Archived_Devices as archived,
|
||||||
|
(select count(*) from Devices a where dev_NewDevice = 1 ) as new,
|
||||||
|
(select count(*) from Devices a where dev_Name = '(unknown)' or dev_Name = '(name not found)' ) as unknown
|
||||||
|
from Online_History order by Scan_Date desc limit 1"""
|
||||||
sql_nmap_scan_all = "SELECT * FROM Nmap_Scan"
|
sql_nmap_scan_all = "SELECT * FROM Nmap_Scan"
|
||||||
sql_pholus_scan_all = "SELECT * FROM Pholus_Scan"
|
sql_pholus_scan_all = "SELECT * FROM Pholus_Scan"
|
||||||
sql_events_pending_alert = "SELECT * FROM Events where eve_PendingAlertEmail is not 0"
|
sql_events_pending_alert = "SELECT * FROM Events where eve_PendingAlertEmail is not 0"
|
||||||
|
|||||||
@@ -33,11 +33,15 @@ class DB():
|
|||||||
|
|
||||||
mylog('none', '[Database] Opening DB' )
|
mylog('none', '[Database] Opening DB' )
|
||||||
# Open DB and Cursor
|
# Open DB and Cursor
|
||||||
self.sql_connection = sqlite3.connect (fullDbPath, isolation_level=None)
|
try:
|
||||||
self.sql_connection.execute('pragma journal_mode=wal') #
|
self.sql_connection = sqlite3.connect (fullDbPath, isolation_level=None)
|
||||||
self.sql_connection.text_factory = str
|
self.sql_connection.execute('pragma journal_mode=wal') #
|
||||||
self.sql_connection.row_factory = sqlite3.Row
|
self.sql_connection.text_factory = str
|
||||||
self.sql = self.sql_connection.cursor()
|
self.sql_connection.row_factory = sqlite3.Row
|
||||||
|
self.sql = self.sql_connection.cursor()
|
||||||
|
except sqlite3.Error as e:
|
||||||
|
mylog('none',[ '[Database] - Open DB Error: ', e])
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
def commitDB (self):
|
def commitDB (self):
|
||||||
@@ -421,9 +425,13 @@ class DB():
|
|||||||
|
|
||||||
mylog('debug',[ '[Database] - Read One: ', query, " params: ", args])
|
mylog('debug',[ '[Database] - Read One: ', query, " params: ", args])
|
||||||
rows = self.read(query, *args)
|
rows = self.read(query, *args)
|
||||||
|
if len(rows) == 1:
|
||||||
|
return rows[0]
|
||||||
|
|
||||||
if len(rows) > 1:
|
if len(rows) > 1:
|
||||||
mylog('none',[ '[Database] - Warning!: query returns multiple rows, only first row is passed on!', query, " params: ", args])
|
mylog('none',[ '[Database] - Warning!: query returns multiple rows, only first row is passed on!', query, " params: ", args])
|
||||||
return rows[0]
|
return rows[0]
|
||||||
|
# empty result set
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@@ -439,18 +447,24 @@ def get_all_devices(db):
|
|||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
def insertOnlineHistory(db, cycle):
|
def insertOnlineHistory(db):
|
||||||
sql = db.sql #TO-DO
|
sql = db.sql #TO-DO
|
||||||
startTime = timeNow()
|
startTime = timeNow()
|
||||||
# Add to History
|
# Add to History
|
||||||
|
|
||||||
|
# only run this if the scans have run
|
||||||
|
scanCount = db.read_one("SELECT count(*) FROM CurrentScan")
|
||||||
|
if scanCount[0] == 0 :
|
||||||
|
mylog('debug',[ '[insertOnlineHistory] - nothing to do, currentScan empty'])
|
||||||
|
return 0
|
||||||
|
|
||||||
History_All = db.read("SELECT * FROM Devices")
|
History_All = db.read("SELECT * FROM Devices")
|
||||||
History_All_Devices = len(History_All)
|
History_All_Devices = len(History_All)
|
||||||
|
|
||||||
History_Archived = db.read("SELECT * FROM Devices WHERE dev_Archived = 1")
|
History_Archived = db.read("SELECT * FROM Devices WHERE dev_Archived = 1")
|
||||||
History_Archived_Devices = len(History_Archived)
|
History_Archived_Devices = len(History_Archived)
|
||||||
|
|
||||||
History_Online = db.read("SELECT * FROM CurrentScan WHERE cur_ScanCycle = ? ", cycle)
|
History_Online = db.read("SELECT * FROM CurrentScan")
|
||||||
History_Online_Devices = len(History_Online)
|
History_Online_Devices = len(History_Online)
|
||||||
History_Offline_Devices = History_All_Devices - History_Archived_Devices - History_Online_Devices
|
History_Offline_Devices = History_All_Devices - History_Archived_Devices - History_Online_Devices
|
||||||
|
|
||||||
|
|||||||
@@ -36,8 +36,6 @@ def scan_network (db):
|
|||||||
|
|
||||||
db.commitDB()
|
db.commitDB()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# arp-scan command
|
# arp-scan command
|
||||||
conf.arpscan_devices = []
|
conf.arpscan_devices = []
|
||||||
if conf.ENABLE_ARPSCAN:
|
if conf.ENABLE_ARPSCAN:
|
||||||
@@ -117,7 +115,7 @@ def process_scan (db, arpscan_devices = conf.arpscan_devices ):
|
|||||||
|
|
||||||
# Sessions snapshot
|
# Sessions snapshot
|
||||||
mylog('verbose','[Process Scan] Inserting scan results into Online_History')
|
mylog('verbose','[Process Scan] Inserting scan results into Online_History')
|
||||||
insertOnlineHistory(db,conf.cycle)
|
insertOnlineHistory(db)
|
||||||
|
|
||||||
# Skip repeated notifications
|
# Skip repeated notifications
|
||||||
mylog('verbose','[Process Scan] Skipping repeated notifications')
|
mylog('verbose','[Process Scan] Skipping repeated notifications')
|
||||||
|
|||||||
Reference in New Issue
Block a user