fix: handling corrupted log lines (fixes #321)
This commit is contained in:
parent
eeee4bdd3c
commit
8c73e32853
@ -2,6 +2,7 @@ import hashlib
|
|||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
|
import logging
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from pwnagotchi.voice import Voice
|
from pwnagotchi.voice import Voice
|
||||||
@ -87,61 +88,65 @@ class LastSession(object):
|
|||||||
parts = line.split(']')
|
parts = line.split(']')
|
||||||
if len(parts) < 2:
|
if len(parts) < 2:
|
||||||
continue
|
continue
|
||||||
line_timestamp = parts[0].strip('[')
|
|
||||||
line = ']'.join(parts[1:])
|
|
||||||
stopped_at = self._parse_datetime(line_timestamp)
|
|
||||||
if started_at is None:
|
|
||||||
started_at = stopped_at
|
|
||||||
|
|
||||||
if LastSession.DEAUTH_TOKEN in line and line not in cache:
|
try:
|
||||||
self.deauthed += 1
|
line_timestamp = parts[0].strip('[')
|
||||||
cache[line] = 1
|
line = ']'.join(parts[1:])
|
||||||
|
stopped_at = self._parse_datetime(line_timestamp)
|
||||||
|
if started_at is None:
|
||||||
|
started_at = stopped_at
|
||||||
|
|
||||||
elif LastSession.ASSOC_TOKEN in line and line not in cache:
|
if LastSession.DEAUTH_TOKEN in line and line not in cache:
|
||||||
self.associated += 1
|
self.deauthed += 1
|
||||||
cache[line] = 1
|
cache[line] = 1
|
||||||
|
|
||||||
elif LastSession.HANDSHAKE_TOKEN in line and line not in cache:
|
elif LastSession.ASSOC_TOKEN in line and line not in cache:
|
||||||
self.handshakes += 1
|
self.associated += 1
|
||||||
cache[line] = 1
|
cache[line] = 1
|
||||||
|
|
||||||
elif LastSession.TRAINING_TOKEN in line:
|
elif LastSession.HANDSHAKE_TOKEN in line and line not in cache:
|
||||||
self.train_epochs += 1
|
self.handshakes += 1
|
||||||
|
cache[line] = 1
|
||||||
|
|
||||||
elif LastSession.EPOCH_TOKEN in line:
|
elif LastSession.TRAINING_TOKEN in line:
|
||||||
self.epochs += 1
|
self.train_epochs += 1
|
||||||
m = LastSession.EPOCH_PARSER.findall(line)
|
|
||||||
if m:
|
|
||||||
epoch_num, epoch_data = m[0]
|
|
||||||
m = LastSession.EPOCH_DATA_PARSER.findall(epoch_data)
|
|
||||||
for key, value in m:
|
|
||||||
if key == 'reward':
|
|
||||||
reward = float(value)
|
|
||||||
self.avg_reward += reward
|
|
||||||
if reward < self.min_reward:
|
|
||||||
self.min_reward = reward
|
|
||||||
|
|
||||||
elif reward > self.max_reward:
|
elif LastSession.EPOCH_TOKEN in line:
|
||||||
self.max_reward = reward
|
self.epochs += 1
|
||||||
|
m = LastSession.EPOCH_PARSER.findall(line)
|
||||||
|
if m:
|
||||||
|
epoch_num, epoch_data = m[0]
|
||||||
|
m = LastSession.EPOCH_DATA_PARSER.findall(epoch_data)
|
||||||
|
for key, value in m:
|
||||||
|
if key == 'reward':
|
||||||
|
reward = float(value)
|
||||||
|
self.avg_reward += reward
|
||||||
|
if reward < self.min_reward:
|
||||||
|
self.min_reward = reward
|
||||||
|
|
||||||
elif LastSession.PEER_TOKEN in line:
|
elif reward > self.max_reward:
|
||||||
m = self._peer_parser.findall(line)
|
self.max_reward = reward
|
||||||
if m:
|
|
||||||
name, pubkey, rssi, sid, pwnd_tot, uptime = m[0]
|
elif LastSession.PEER_TOKEN in line:
|
||||||
if pubkey not in cache:
|
m = self._peer_parser.findall(line)
|
||||||
self.last_peer = Peer({
|
if m:
|
||||||
'session_id': sid,
|
name, pubkey, rssi, sid, pwnd_tot, uptime = m[0]
|
||||||
'channel': 1,
|
if pubkey not in cache:
|
||||||
'rssi': int(rssi),
|
self.last_peer = Peer({
|
||||||
'identity': pubkey,
|
'session_id': sid,
|
||||||
'advertisement':{
|
'channel': 1,
|
||||||
'name': name,
|
'rssi': int(rssi),
|
||||||
'pwnd_tot': int(pwnd_tot)
|
'identity': pubkey,
|
||||||
}})
|
'advertisement':{
|
||||||
self.peers += 1
|
'name': name,
|
||||||
cache[pubkey] = self.last_peer
|
'pwnd_tot': int(pwnd_tot)
|
||||||
else:
|
}})
|
||||||
cache[pubkey].adv['pwnd_tot'] = pwnd_tot
|
self.peers += 1
|
||||||
|
cache[pubkey] = self.last_peer
|
||||||
|
else:
|
||||||
|
cache[pubkey].adv['pwnd_tot'] = pwnd_tot
|
||||||
|
except Exception as e:
|
||||||
|
logging.error("error parsing line '%s': %s" % (line, e))
|
||||||
|
|
||||||
if started_at is not None:
|
if started_at is not None:
|
||||||
self.duration = stopped_at - started_at
|
self.duration = stopped_at - started_at
|
||||||
|
Loading…
x
Reference in New Issue
Block a user