def process_raw_event(self, raw_event): raw_event_d = None try: raw_event_d = json.loads(raw_event) serial_number = get_serial_number_from_raw_event(raw_event_d) if not serial_number: return user_agent, ip_address = get_user_agent_and_ip_address_from_raw_event(raw_event_d) event_data = parse_santa_log_message(raw_event_d["message"]) except Exception: logger.exception("Could not process santa_log raw event") if raw_event_d: save_dead_letter(raw_event_d, "santa log preprocessing error") else: if event_data: yield from SantaLogEvent.build_from_machine_request_payloads( serial_number, user_agent, ip_address, [event_data], get_created_at=lambda d: d.pop("timestamp") ) else: # probably a log rotation line logger.info("Empty santa log event data.")
def test_santa_log_fail_hard(self): with self.assertRaises(ValueError, msg="Could not find timestamp"): parse_santa_log_message(": action=D")
def test_santa_log_rubbish_data(self): self.assertEqual(parse_santa_log_message(42 * "\x00\x0a" + LOG1), RES1)
def test_santa_log_3(self): self.assertEqual(parse_santa_log_message(LOG3), RES3)
def test_santa_log_2(self): self.assertEqual(parse_santa_log_message(LOG2), RES2)
def test_santa_log_1(self): self.assertEqual(parse_santa_log_message(LOG1), RES1)