From 7dc56ea31895f12acd418a29cfcd2e1eb9216130 Mon Sep 17 00:00:00 2001 From: Maksym Kulish Date: Mon, 7 Oct 2024 17:33:50 +0300 Subject: [PATCH] Fix timestamp parsing for gauge value --- scripts/send_test_alert.py | 3 +-- tests/__init__.py | 2 +- witnesschain_alertmanager_proxy.py | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/send_test_alert.py b/scripts/send_test_alert.py index 13de1bb..8d4178a 100644 --- a/scripts/send_test_alert.py +++ b/scripts/send_test_alert.py @@ -1,6 +1,5 @@ import argparse import copy -import time import requests @@ -10,7 +9,7 @@ parser.add_argument( "--watchtower-id", default="0x0e71247b49013664006D8472107f9e127695d9d7" ) -parser.add_argument("--timestamp", default=lambda: str(int(time.time()))) +parser.add_argument("--timestamp", default="Oct 7 14:26:18 2024") parser.add_argument("--file", default="emulator.py") parser.add_argument("--line", default="9393") parser.add_argument("--message", default="This is a test alert message") diff --git a/tests/__init__.py b/tests/__init__.py index 2711fab..babdaa7 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -38,7 +38,7 @@ def test_integration() -> None: % ( "0x0e71247b49013664006D8472107f9e127695d9d7", "200", - "1728038914", + "Oct 7 14:26:18 2024", "example.go", "500", "Test alert message", diff --git a/witnesschain_alertmanager_proxy.py b/witnesschain_alertmanager_proxy.py index a39166f..d2e6c43 100644 --- a/witnesschain_alertmanager_proxy.py +++ b/witnesschain_alertmanager_proxy.py @@ -246,10 +246,10 @@ def alert(proxy: ProxySettings, body: WitnessChainErrorLog, response: Response) body.text ), "Text received from WitnessChain Watchtower should not be empty" alert = proxy.incoming(body) - ts = int(alert.labels["timestamp"]) + ts = datetime.strptime(alert.labels["timestamp"], "%b %d %H:%M:%S %Y") witnesschain_alert.labels( alert.labels["file"], alert.labels["line"], alert.labels["watchtower_id"] - ).set(ts) + ).set(ts.timestamp()) rendered = proxy.render(alert) proxy.send_alert(rendered) response.status_code = 204