From b5ded65fdab58c6fb82b543d2e4204dcb2a1c41a Mon Sep 17 00:00:00 2001 From: arf20 Date: Sun, 26 Oct 2025 02:45:53 +0200 Subject: fix event time parsing (ISO 8601) --- monitor.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'monitor.c') diff --git a/monitor.c b/monitor.c index e6165a3..2c81be5 100644 --- a/monitor.c +++ b/monitor.c @@ -93,7 +93,8 @@ incidents_push_ordered(const incident_t *incident) } static size_t -target_events_load(target_t *target, const char *logbuff) { +target_events_load(target_t *target, const char *logbuff) +{ char line[256]; size_t n = 0; @@ -123,11 +124,11 @@ target_events_load(target_t *target, const char *logbuff) { if (strcmp(name, target->name) != 0) continue; - struct tm event_time; - strptime(time, "%Y-%m-%d %H:%M:%S", &event_time); + struct tm event_time = { 0 }; + strptime(time, "%FT%T%z", &event_time); event_t event = { - mktime(&event_time), + mktime(&event_time) - timezone, strcmp(status, "up") == 0 ? STATUS_UP : STATUS_DOWN }; @@ -182,7 +183,8 @@ incidents_render() } int -monitor_init(const char *cfg_path, const char *log_path) { +monitor_init(const char *cfg_path, const char *log_path) +{ /* read monitor log */ FILE *logf = fopen(log_path, "r"); if (!logf) { @@ -209,6 +211,8 @@ monitor_init(const char *cfg_path, const char *log_path) { } printf("monitor targets:\n"); + + tzset(); /* initialize tz conversion */ char line[256]; while (fgets(line, sizeof(line), cfgf)) { @@ -277,6 +281,11 @@ target_uptime(const target_t *target) { static char buff[256]; + if (target->events_size == 0) { + snprintf(buff, 256, "-"); + return buff; + } + event_t last_event = target->events[target->events_size - 1]; if (last_event.status == STATUS_DOWN) { -- cgit v1.2.3