From ab640760a99f8c6f3d98c3c52441d7772150ac23 Mon Sep 17 00:00:00 2001 From: Kevin Trocolli Date: Wed, 1 Nov 2023 00:53:04 -0400 Subject: [PATCH] allnet: add event logging to download report --- core/allnet.py | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/core/allnet.py b/core/allnet.py index b0e1c78..d661107 100644 --- a/core/allnet.py +++ b/core/allnet.py @@ -315,6 +315,7 @@ class AllnetServlet: def handle_dlorder_report(self, request: Request, match: Dict) -> bytes: req_raw = request.content.getvalue() + client_ip = Utils.get_ip_addr(request) try: req_dict: Dict = json.loads(req_raw) except Exception as e: @@ -332,11 +333,18 @@ class AllnetServlet: self.logger.warning(f"Failed to parse DL Report: Invalid format - contains neither appimage nor optimage") return "NG" - dl_report_data = DLReport(dl_data, dl_data_type) + rep = DLReport(dl_data, dl_data_type) - if not dl_report_data.validate(): - self.logger.warning(f"Failed to parse DL Report: Invalid format - {dl_report_data.err}") + if not rep.validate(): + self.logger.warning(f"Failed to parse DL Report: Invalid format - {rep.err}") return "NG" + + msg = f"{rep.serial} @ {client_ip} reported download state {rep.rf_state} for {rep.gd} v{rep.dav}"\ + f" ordered at {datetime.utcfromtimestamp(rep.ot).isoformat()} UTC:"\ + f" {rep.tdsc}/{rep.tsc} segemnts downloaded for working files {rep.wfl} with {rep.dfl} complete." + + self.data.base.log_event("allnet", "DL_ORDER", logging.INFO, msg, dl_data) + self.logger.info(msg) return "OK" @@ -753,14 +761,6 @@ class DLReport: self.err = "serial not provided" return False - if self.dfl is None: - self.err = "dfl not provided" - return False - - if self.wfl is None: - self.err = "wfl not provided" - return False - if self.tsc is None: self.err = "tsc not provided" return False @@ -769,18 +769,6 @@ class DLReport: self.err = "tdsc not provided" return False - if self.at is None: - self.err = "at not provided" - return False - - if self.ot is None: - self.err = "ot not provided" - return False - - if self.rt is None: - self.err = "rt not provided" - return False - if self.as_ is None: self.err = "as not provided" return False