added ping uptime test

This commit is contained in:
2026-07-09 19:05:59 +02:00
parent 90df6ad45f
commit 19fec18cf7
7 changed files with 1138 additions and 1116 deletions

View File

@@ -24,6 +24,36 @@ def init_db(db_path=DB_PATH):
conn.commit()
conn.close()
def init_ping_db(db_path=DB_PATH):
conn = sqlite3.connect(db_path)
c = conn.cursor()
c.execute('''
CREATE TABLE IF NOT EXISTS ping_checks (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp REAL NOT NULL,
target_ip TEXT NOT NULL,
success BOOLEAN NOT NULL,
latency_ms REAL
)
''')
conn.commit()
try:
conn.execute("ALTER TABLE ping_checks ADD COLUMN is_gateway INTEGER DEFAULT 0")
conn.commit()
except sqlite3.OperationalError:
pass # column already exists
conn.close()
def insert_ping_result(target_ip: str, success: bool, latency_ms: float | None, is_gateway: bool = False, db_path=DB_PATH):
conn = sqlite3.connect(db_path)
c = conn.cursor()
c.execute(
"INSERT INTO ping_checks (timestamp, target_ip, success, latency_ms, is_gateway) VALUES (?, ?, ?, ?, ?)",
(time.time(), target_ip, success, latency_ms, int(is_gateway))
)
conn.commit()
conn.close()
def insert_result(data: dict|None, db_path=DB_PATH):
conn = sqlite3.connect(db_path)
c = conn.cursor()