From 7f6f080beae5ca9c0c116e7c41e6d7a1257b8dac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Fra=C3=9F?= Date: Mon, 28 Apr 2025 19:51:03 +0000 Subject: [PATCH] [mod] target.interval -> target.reminders [mod] settings.poll_delay -> settings.interval [mod] ical_feed:timezone --- source/conf.ts | 33 +++++++++++++++++++++++++++------ source/main.ts | 19 ++++++++++--------- source/sources/ical_feed.ts | 18 +++++++++++++++--- source/targets/telegram_bot.ts | 10 ++++++++-- source/types.ts | 3 ++- 5 files changed, 62 insertions(+), 21 deletions(-) diff --git a/source/conf.ts b/source/conf.ts index 92277a0..7506b0b 100644 --- a/source/conf.ts +++ b/source/conf.ts @@ -93,13 +93,13 @@ namespace _munin.conf /** * in hours */ - interval : Array; + reminders : Array; } } ) >; settings : { - poll_delay : float; + interval : float; }; labels : { head : string; @@ -154,9 +154,30 @@ namespace _munin.conf } } ), - "targets": conf_v1.targets, + "targets": conf_v1.targets.map( + target => { + switch (target.kind) { + case "telegram_bot": { + return { + "kind": "telegram_bot", + "data": { + "bot_token": target.data.bot_token, + "chat_id": target.data.chat_id, + "reminders": target.data.interval, + }, + }; + break; + } + default: { + // return target; + throw (new Error("unhandled target kind: " + target.kind)); + break; + } + } + } + ), "settings": { - "poll_delay": conf_v1.frequency, + "interval": conf_v1.frequency, }, "labels": conf_v1.labels, }; @@ -360,7 +381,7 @@ namespace _munin.conf "nullable": false, "type": "integer", }, - "interval": { + "reminders": { "nullable": false, "type": "array", "items": { @@ -415,7 +436,7 @@ namespace _munin.conf "nullable": false, "type": "object", "properties": { - "poll_delay": { + "interval": { "nullable": false, "type": "number", "default": 1.0 diff --git a/source/main.ts b/source/main.ts index 1daa642..51800cd 100644 --- a/source/main.ts +++ b/source/main.ts @@ -49,14 +49,14 @@ namespace _munin } } ); - for (const hours of target.interval) { + for (const hours of target.reminders) { const window_from : lib_plankton.pit.type_pit = lib_plankton.pit.shift_hour( now, hours + 0 ); const window_to : lib_plankton.pit.type_pit = lib_plankton.pit.shift_hour( now, - hours + (conf.settings.poll_delay / 2) + hours + conf.settings.interval ); for (const event of events) { const event_begin : lib_plankton.pit.type_pit = lib_plankton.pit.from_datetime(event.begin); @@ -64,9 +64,10 @@ namespace _munin "munin.run.check_dueness", { "details": { - "event_begin": lib_plankton.pit.datetime_format(lib_plankton.pit.to_datetime(event_begin)), - "window_from": lib_plankton.pit.datetime_format(lib_plankton.pit.to_datetime(window_from)), - "window_to": lib_plankton.pit.datetime_format(lib_plankton.pit.to_datetime(window_to)), + // "now": lib_plankton.pit.to_date_object(now).toISOString(), + "event_begin": lib_plankton.pit.to_date_object(event_begin).toISOString(), + "window_from": lib_plankton.pit.to_date_object(window_from).toISOString(), + "window_to": lib_plankton.pit.to_date_object(window_to).toISOString(), } } ); @@ -84,7 +85,7 @@ namespace _munin { "details": { "event": event, - "target": target, + "target": target.show(), } } ); @@ -128,7 +129,7 @@ namespace _munin ); while (true) { await run_iteration(conf, sources, targets, {"dry_run": dry_run}); - await lib_plankton.call.sleep(conf.settings.poll_delay * 60 * 60); + await lib_plankton.call.sleep(conf.settings.interval * 60 * 60); } } @@ -157,7 +158,7 @@ namespace _munin "indicators_short": ["c"], "type": lib_plankton.args.enum_type.string, "mode": lib_plankton.args.enum_mode.replace, - "default": "conf.json", + "default": "munin.json", "info": "path to configuration file", "name": "conf-path", }), @@ -243,7 +244,7 @@ namespace _munin "threshold": args.verbosity, } }, - } + }, ] ], } diff --git a/source/sources/ical_feed.ts b/source/sources/ical_feed.ts index cb11ca1..d63c20b 100644 --- a/source/sources/ical_feed.ts +++ b/source/sources/ical_feed.ts @@ -25,7 +25,7 @@ namespace _munin.sources.ical_feed "path": url.path, "version": "HTTP/2", "method": lib_plankton.http.enum_method.get, - "query": url.query, + "query": ("?" + url.query), "headers": {}, "body": null, }; @@ -64,13 +64,25 @@ namespace _munin.sources.ical_feed ) .map( vevent => { + /** + * @todo würg! + */ + const timezone_shift : int = lib_plankton.pit.timezone_shift_ce( + lib_plankton.pit.from_datetime( + { + "timezone_shift": 0, + "date": vevent.dtstart.value.date, + "time": vevent.dtstart.value.time, + } + ) + ); const begin : lib_plankton.pit.type_datetime = { - "timezone_shift": 0, + "timezone_shift": timezone_shift, "date": vevent.dtstart.value.date, "time": vevent.dtstart.value.time, }; const end : lib_plankton.pit.type_datetime = { - "timezone_shift": 0, + "timezone_shift": timezone_shift, "date": vevent.dtend.value.date, "time": vevent.dtend.value.time, }; diff --git a/source/targets/telegram_bot.ts b/source/targets/telegram_bot.ts index 17a194c..15d03b8 100644 --- a/source/targets/telegram_bot.ts +++ b/source/targets/telegram_bot.ts @@ -26,7 +26,7 @@ namespace _munin.targets.telegram_bot export type type_parameters = { bot_token : string; chat_id : int; - interval : Array; + reminders : Array; }; @@ -78,7 +78,13 @@ namespace _munin.targets.telegram_bot ) : _munin.type_target { return { - "interval": parameters.interval, + "reminders": parameters.reminders, + "show": () => lib_plankton.string.coin( + "telegram:{{chat_id}}", + { + "chat_id": parameters.chat_id.toFixed(0), + } + ), "send": (labels, event) => send(parameters, labels, event), }; } diff --git a/source/types.ts b/source/types.ts index b698d64..fa0c4b0 100644 --- a/source/types.ts +++ b/source/types.ts @@ -36,7 +36,8 @@ namespace _munin /** */ export type type_target = { - interval : Array; + reminders : Array; + show : (() => string); send : ( ( labels : type_labels,