added ping uptime test
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user