diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2023-05-18 05:12:35 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2023-05-18 05:12:35 +0300 |
commit | 2960f9f09a9991e342a676999e498b08affa4dff (patch) | |
tree | 3198fed18a400588bb38dd1e523b0e50ba07917b /src/openwrt_logger.py | |
parent | c0111bf4d3dd91f54d27346970e4c6e0a1ce357e (diff) |
openwrt: home side changes
Diffstat (limited to 'src/openwrt_logger.py')
-rwxr-xr-x | src/openwrt_logger.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/openwrt_logger.py b/src/openwrt_logger.py index 098c049..0c5df28 100755 --- a/src/openwrt_logger.py +++ b/src/openwrt_logger.py @@ -2,16 +2,15 @@ import os from datetime import datetime +from typing import Tuple, List +from argparse import ArgumentParser from home.config import config from home.database import SimpleState from home.api import WebAPIClient -from typing import Tuple, List - -log_file = '/var/log/openwrt.log' f""" This script is supposed to be run by cron every 5 minutes or so. -It looks for new lines in {log_file} and sends them to remote server. +It looks for new lines in log file and sends them to remote server. OpenWRT must have remote logging enabled (UDP; IP of host this script is launched on; port 514) @@ -41,16 +40,22 @@ def parse_line(line: str) -> Tuple[int, str]: if __name__ == '__main__': - config.load('openwrt_logger') + parser = ArgumentParser() + parser.add_argument('--file', type=str, required=True, + help='openwrt log file') + parser.add_argument('--access-point', type=int, required=True, + help='access point number') + + arg = config.load('openwrt_logger', parser=parser) state = SimpleState(file=config['simple_state']['file'], default={'seek': 0, 'size': 0}) - fsize = os.path.getsize(log_file) + fsize = os.path.getsize(arg.file) if fsize < state['size']: state['seek'] = 0 - with open(log_file, 'r') as f: + with open(arg.file, 'r') as f: if state['seek']: # jump to the latest read position f.seek(state['seek']) @@ -75,4 +80,4 @@ if __name__ == '__main__': lines.append((0, line)) api = WebAPIClient() - api.log_openwrt(lines) + api.log_openwrt(lines, arg.access_point) |