X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;f=loctrkd%2Fstorage.py;h=843991502772c69693e77d34c5eba6737ebb2681;hb=ed78cfbeae56fa31e844f2858b409f39464c93a0;hp=5ea3b2c823c15618ed2845e6633b384fd2f93289;hpb=ea3dc3f2096472d502d376e13050a59f97efd4a8;p=loctrkd.git diff --git a/loctrkd/storage.py b/loctrkd/storage.py index 5ea3b2c..8439915 100644 --- a/loctrkd/storage.py +++ b/loctrkd/storage.py @@ -7,13 +7,14 @@ from logging import getLogger import zmq from . import common -from .evstore import initdb, stow, stowloc +from .evstore import initdb, stow, stowloc, stowpmod from .zmsg import Bcast, Rept log = getLogger("loctrkd/storage") def runserver(conf: ConfigParser) -> None: + stowevents = conf.getboolean("storage", "events", fallback=False) dbname = conf.get("storage", "dbfn") log.info('Using Sqlite3 database "%s"', dbname) initdb(dbname) @@ -21,8 +22,7 @@ def runserver(conf: ConfigParser) -> None: zctx = zmq.Context() # type: ignore zraw = zctx.socket(zmq.SUB) # type: ignore zraw.connect(conf.get("collector", "publishurl")) - if conf.getboolean("storage", "events", fallback=False): - zraw.setsockopt(zmq.SUBSCRIBE, b"") + zraw.setsockopt(zmq.SUBSCRIBE, b"") zrep = zctx.socket(zmq.SUB) # type: ignore zrep.connect(conf.get("rectifier", "publishurl")) zrep.setsockopt(zmq.SUBSCRIBE, b"") @@ -41,23 +41,27 @@ def runserver(conf: ConfigParser) -> None: except zmq.Again: break log.debug( - "%s IMEI %s from %s at %s: %s", + "%s IMEI %s from %s at %s %s: %s", "I" if zmsg.is_incoming else "O", zmsg.imei, zmsg.peeraddr, + zmsg.pmod, datetime.fromtimestamp(zmsg.when).astimezone( tz=timezone.utc ), zmsg.packet.hex(), ) - stow( - is_incoming=zmsg.is_incoming, - peeraddr=str(zmsg.peeraddr), - when=zmsg.when, - imei=zmsg.imei, - proto=zmsg.proto, - packet=zmsg.packet, - ) + if zmsg.imei is not None and zmsg.pmod is not None: + stowpmod(zmsg.imei, zmsg.pmod) + if stowevents: + stow( + is_incoming=zmsg.is_incoming, + peeraddr=str(zmsg.peeraddr), + when=zmsg.when, + imei=zmsg.imei, + proto=zmsg.proto, + packet=zmsg.packet, + ) elif sk is zrep: while True: try: