MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / update_ping_status

Method update_ping_status

db_manager.py:954–1009  ·  view source on GitHub ↗

Update ping tracking for a host. Args: mac: MAC address success: True if ping succeeded, False if failed This implements the ping failure tracking logic: - Success: Reset failed_ping_count to 0, update last_ping_success, stat

(self, mac: str, success: bool)

Source from the content-addressed store, hash-verified

952 cursor = conn.cursor()
953
954 if status:
955 cursor.execute("SELECT * FROM hosts WHERE status = ? ORDER BY ip", (status,))
956 else:
957 cursor.execute("SELECT * FROM hosts ORDER BY ip")
958
959 return [dict(row) for row in cursor.fetchall()]
960 except Exception as e:
961 logger.error(f"Failed to get all hosts: {e}")
962 return []
963
964 def update_ping_status(self, mac: str, success: bool):
965 """
966 Update ping tracking for a host.
967
968 Args:
969 mac: MAC address
970 success: True if ping succeeded, False if failed
971
972 This implements the ping failure tracking logic:
973 - Success: Reset failed_ping_count to 0, update last_ping_success, status='alive'
974 - Failure: Increment failed_ping_count, check if >= 30 → status='degraded'
975 """
976 try:
977 with self.get_connection() as conn:
978 cursor = conn.cursor()
979 now = datetime.now().isoformat()
980
981 if success:
982 # Ping succeeded - reset failure count and mark alive
983 cursor.execute("""
984 UPDATE hosts
985 SET failed_ping_count = 0,
986 last_ping_success = ?,
987 last_seen = ?,
988 status = 'alive',
989 updated_at = ?
990 WHERE mac = ?
991 """, (now, now, now, mac.lower().strip()))
992 logger.debug(f"Ping success: {mac} - status=alive")
993 else:
994 # Ping failed - increment failure count
995 cursor.execute("""
996 UPDATE hosts
997 SET failed_ping_count = failed_ping_count + 1,
998 updated_at = ?
999 WHERE mac = ?
1000 """, (now, mac.lower().strip()))
1001
1002 # Check if we've hit the degraded threshold (30 failed pings)
1003 cursor.execute("SELECT failed_ping_count FROM hosts WHERE mac = ?", (mac.lower().strip(),))
1004 row = cursor.fetchone()
1005
1006 if row and row[0] >= 30:
1007 cursor.execute("""
1008 UPDATE hosts
1009 SET status = 'degraded'
1010 WHERE mac = ?
1011 """, (mac.lower().strip(),))

Callers 7

db_manager.pyFile · 0.80
_upsert_passive_hostMethod · 0.80
_bg_scanFunction · 0.80
run_arp_scanMethod · 0.80
run_nmap_network_scanMethod · 0.80
update_netkbMethod · 0.80

Calls 8

get_connectionMethod · 0.95
cursorMethod · 0.80
debugMethod · 0.80
warningMethod · 0.80
commitMethod · 0.80
errorMethod · 0.80
executeMethod · 0.45
fetchoneMethod · 0.45

Tested by

no test coverage detected