Fix querying Kismet log.
This commit is contained in:
parent
a46ed79d3d
commit
b448b41fa8
1 changed files with 49 additions and 16 deletions
|
@ -20,31 +20,64 @@ def convert_timestamp_to_epoch(ts_string):
|
||||||
|
|
||||||
def get_rf_metrics(cursor, bssid, channel, start_time, end_time):
|
def get_rf_metrics(cursor, bssid, channel, start_time, end_time):
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
SELECT COUNT(*) FROM devicelink
|
SELECT COUNT(*) FROM devices
|
||||||
WHERE type = 'Wi-Fi Client' AND mac = ? AND last_time BETWEEN ? AND ?
|
WHERE type = 'Wi-Fi Client'
|
||||||
""", (bssid.lower(), start_time, end_time))
|
AND last_time BETWEEN ? AND ?
|
||||||
|
AND LOWER(json_extract(device, '$.kismet.device.base.bssid')) = ?
|
||||||
|
""", (start_time, end_time, bssid.lower()))
|
||||||
clients_on_ap = cursor.fetchone()[0]
|
clients_on_ap = cursor.fetchone()[0]
|
||||||
|
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
SELECT COUNT(DISTINCT devicelink.remote_mac)
|
SELECT COUNT(*) FROM devices
|
||||||
FROM devicelink
|
WHERE type = 'Wi-Fi Client'
|
||||||
JOIN devices ON devicelink.mac = devices.base_mac
|
AND last_time BETWEEN ? AND ?
|
||||||
WHERE devicelink.type = 'Wi-Fi Client'
|
AND (
|
||||||
AND devices.channel = ?
|
json_extract(device, '$.kismet.device.base.channel') = ? OR
|
||||||
AND devicelink.last_time BETWEEN ? AND ?
|
json_type(json_extract(device, '$.kismet.device.base.freq_khz_map')) = 'object'
|
||||||
""", (channel, start_time, end_time))
|
)
|
||||||
|
AND json_extract(device, '$.kismet.device.base.packets.total') > 0
|
||||||
|
""", (start_time, end_time, channel))
|
||||||
clients_on_channel = cursor.fetchone()[0]
|
clients_on_channel = cursor.fetchone()[0]
|
||||||
|
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
SELECT COUNT(*) FROM devices
|
SELECT COUNT(*) FROM devices
|
||||||
WHERE type = 'Wi-Fi AP' AND channel = ?
|
WHERE type = 'Wi-Fi AP'
|
||||||
AND last_time BETWEEN ? AND ?
|
AND last_time BETWEEN ? AND ?
|
||||||
""", (channel, start_time, end_time))
|
AND (
|
||||||
|
json_extract(device, '$.kismet.device.base.channel') = ? OR
|
||||||
|
json_type(json_extract(device, '$.kismet.device.base.freq_khz_map')) = 'object'
|
||||||
|
)
|
||||||
|
AND strongest_signal < 0
|
||||||
|
""", (start_time, end_time, channel))
|
||||||
aps_on_channel = cursor.fetchone()[0]
|
aps_on_channel = cursor.fetchone()[0]
|
||||||
|
|
||||||
congestion_score = round(clients_on_channel / aps_on_channel, 2) if aps_on_channel else 0.0
|
cursor.execute("""
|
||||||
|
SELECT strongest_signal FROM devices
|
||||||
|
WHERE type = 'Wi-Fi AP'
|
||||||
|
AND last_time BETWEEN ? AND ?
|
||||||
|
AND (
|
||||||
|
json_extract(device, '$.kismet.device.base.channel') = ? OR
|
||||||
|
json_type(json_extract(device, '$.kismet.device.base.freq_khz_map')) = 'object'
|
||||||
|
)
|
||||||
|
AND strongest_signal < 0
|
||||||
|
""", (start_time, end_time, channel))
|
||||||
|
signals = cursor.fetchall()
|
||||||
|
avg_signal = sum([s[0] for s in signals]) / len(signals) if signals else None
|
||||||
|
strongest_signal = max([s[0] for s in signals]) if signals else None
|
||||||
|
|
||||||
return clients_on_ap, clients_on_channel, aps_on_channel, congestion_score
|
cursor.execute("""
|
||||||
|
SELECT COUNT(*) FROM devices
|
||||||
|
WHERE type = 'Wi-Fi Client'
|
||||||
|
AND last_time BETWEEN ? AND ?
|
||||||
|
AND json_extract(device, '$.kismet.device.base.channel') IS NULL
|
||||||
|
AND json_type(json_extract(device, '$.kismet.device.base.freq_khz_map')) != 'object'
|
||||||
|
AND json_extract(device, '$.kismet.device.base.packets.total') = 0
|
||||||
|
""", (start_time, end_time))
|
||||||
|
unlinked_devices = cursor.fetchone()[0]
|
||||||
|
|
||||||
|
congestion_score = round(clients_on_channel / aps_on_channel, 2) if aps_on_channel else None
|
||||||
|
|
||||||
|
return clients_on_ap, clients_on_channel, aps_on_channel, congestion_score, avg_signal, strongest_signal, unlinked_devices
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
|
@ -70,7 +103,7 @@ def main():
|
||||||
writer.writerow(row)
|
writer.writerow(row)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if ts is None:
|
if tstart is None or tend is None:
|
||||||
writer.writerow(row)
|
writer.writerow(row)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue