summaryrefslogtreecommitdiff
path: root/src/openwrt_log_analyzer.py
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2023-09-27 00:54:57 +0300
committerEvgeny Zinoviev <me@ch1p.io>2023-09-27 00:54:57 +0300
commitd3a295872c49defb55fc8e4e43e55550991e0927 (patch)
treeb9dca15454f9027d5a9dad0d4443a20de04dbc5d /src/openwrt_log_analyzer.py
parentb7cbc2571c1870b4582ead45277d0aa7f961bec8 (diff)
parentbdbb296697f55f4c3a07af43c9aaf7a9ea86f3d0 (diff)
Merge branch 'master' of ch1p.io:homekit
Diffstat (limited to 'src/openwrt_log_analyzer.py')
-rwxr-xr-xsrc/openwrt_log_analyzer.py72
1 files changed, 0 insertions, 72 deletions
diff --git a/src/openwrt_log_analyzer.py b/src/openwrt_log_analyzer.py
deleted file mode 100755
index d31c3bf..0000000
--- a/src/openwrt_log_analyzer.py
+++ /dev/null
@@ -1,72 +0,0 @@
-#!/usr/bin/env python3
-import home.telegram as telegram
-
-from home.config import config
-from home.database import BotsDatabase, SimpleState
-
-"""
-config.toml example:
-
-[simple_state]
-file = "/home/user/.config/openwrt_log_analyzer/state.txt"
-
-[mysql]
-host = "localhost"
-database = ".."
-user = ".."
-password = ".."
-
-[devices]
-Device1 = "00:00:00:00:00:00"
-Device2 = "01:01:01:01:01:01"
-
-[telegram]
-chat_id = ".."
-token = ".."
-parse_mode = "HTML"
-
-[openwrt_log_analyzer]
-limit = 10
-"""
-
-
-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
-
- max_id = 0
- for log in data:
- if log.id > max_id:
- max_id = log.id
-
- text = '\n'.join(map(lambda s: str(s), data))
- 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['openwrt_log_analyzer']['aps']:
- state_file = config['simple_state']['file']
- state_file = state_file.replace('.txt', f'-{ap}.txt')
-
- 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, ap=ap)
- if last_id > max_last_id:
- max_last_id = last_id
-
- if max_last_id:
- state['last_id'] = max_last_id