summaryrefslogtreecommitdiff
path: root/src/openwrt_logger.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/openwrt_logger.py')
-rwxr-xr-xsrc/openwrt_logger.py21
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)