diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2023-05-18 05:28:36 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2023-05-18 05:28:36 +0300 |
commit | 5d739c3e9d73e13ad836df904a88debacce31db0 (patch) | |
tree | de8592200a2cf8a8f8913b37cc84919c8b04b79d /src/openwrt_log_analyzer.py | |
parent | 2960f9f09a9991e342a676999e498b08affa4dff (diff) |
openwrt: server side
Diffstat (limited to 'src/openwrt_log_analyzer.py')
-rwxr-xr-x | src/openwrt_log_analyzer.py | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/openwrt_log_analyzer.py b/src/openwrt_log_analyzer.py index bdfeb6c..a55aaf8 100755 --- a/src/openwrt_log_analyzer.py +++ b/src/openwrt_log_analyzer.py @@ -30,11 +30,14 @@ limit = 10 """ -def main(mac: str, title: str) -> int: +def main(mac: str, + title: str, + ap: int) -> int: db = BotsDatabase() data = db.get_openwrt_logs(filter_text=mac, min_id=state['last_id'], + access_point=ap, limit=config['openwrt_log_analyzer']['limit']) if not data: return 0 @@ -45,22 +48,25 @@ def main(mac: str, title: str) -> int: max_id = log.id text = '\n'.join(map(lambda s: str(s), data)) - telegram.send_message(f'<b>{title}</b>\n\n' + text) + telegram.send_message(f'<b>{title} (AP #{ap})</b>\n\n' + text) return max_id if __name__ == '__main__': config.load('openwrt_log_analyzer') + for ap in config['aps']: + state_file = config['simple_state']['file'] + state_file = state_file.replace('.txt', f'-{ap}.txt') - state = SimpleState(file=config['simple_state']['file'], - default={'last_id': 0}) + state = SimpleState(file=state_file, + default={'last_id': 0}) - max_last_id = 0 - for name, mac in config['devices'].items(): - last_id = main(mac, title=name) - if last_id > max_last_id: - max_last_id = last_id + max_last_id = 0 + for name, mac in config['devices'].items(): + last_id = main(mac, title=name, ap=ap) + if last_id > max_last_id: + max_last_id = last_id - if max_last_id: - state['last_id'] = max_last_id + if max_last_id: + state['last_id'] = max_last_id |