Update core scanner, parser, SSH client, and UI

This commit is contained in:
2026-05-05 20:07:24 +00:00
parent 40d4679a59
commit d32ca80a22
6 changed files with 313 additions and 79 deletions
+15 -5
View File
@@ -25,9 +25,17 @@ def init_db():
hostname TEXT,
mgmt_ip TEXT,
description TEXT,
firmware TEXT DEFAULT '',
vendor TEXT DEFAULT '',
last_seen TEXT
)
""")
# Migrate existing DBs that predate firmware/vendor columns
for col, default in [('firmware', ''), ('vendor', '')]:
try:
c.execute(f"ALTER TABLE switches ADD COLUMN {col} TEXT DEFAULT '{default}'")
except Exception:
pass # Column already exists
c.execute("""
CREATE TABLE IF NOT EXISTS links (
@@ -70,18 +78,20 @@ def init_db():
conn.close()
def upsert_switch(chassis_id, hostname, mgmt_ip, description):
def upsert_switch(chassis_id, hostname, mgmt_ip, description, firmware='', vendor=''):
conn = get_conn()
conn.execute("""
INSERT INTO switches (chassis_id, hostname, mgmt_ip, description, last_seen)
VALUES (?, ?, ?, ?, datetime('now'))
INSERT INTO switches (chassis_id, hostname, mgmt_ip, description, firmware, vendor, last_seen)
VALUES (?, ?, ?, ?, ?, ?, datetime('now'))
ON CONFLICT(chassis_id) DO UPDATE SET
hostname = excluded.hostname,
mgmt_ip = CASE WHEN excluded.mgmt_ip != '' AND excluded.mgmt_ip NOT LIKE '%.%.%.%' = 0
mgmt_ip = CASE WHEN excluded.mgmt_ip != '' AND excluded.mgmt_ip LIKE '%.%.%.%'
THEN excluded.mgmt_ip ELSE mgmt_ip END,
description = CASE WHEN excluded.description != '' THEN excluded.description ELSE description END,
firmware = CASE WHEN excluded.firmware != '' THEN excluded.firmware ELSE firmware END,
vendor = CASE WHEN excluded.vendor != '' THEN excluded.vendor ELSE vendor END,
last_seen = excluded.last_seen
""", (chassis_id, hostname, mgmt_ip, description))
""", (chassis_id, hostname, mgmt_ip, description, firmware, vendor))
conn.commit()
conn.close()