[mod] target.interval -> target.reminders [mod] settings.poll_delay -> settings.interval [mod] ical_feed:timezone

This commit is contained in:
Christian Fraß 2025-04-28 19:51:03 +00:00
parent ac1daf8a68
commit 7f6f080bea
5 changed files with 62 additions and 21 deletions

View file

@ -93,13 +93,13 @@ namespace _munin.conf
/** /**
* in hours * in hours
*/ */
interval : Array<int>; reminders : Array<int>;
} }
} }
) )
>; >;
settings : { settings : {
poll_delay : float; interval : float;
}; };
labels : { labels : {
head : string; 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": { "settings": {
"poll_delay": conf_v1.frequency, "interval": conf_v1.frequency,
}, },
"labels": conf_v1.labels, "labels": conf_v1.labels,
}; };
@ -360,7 +381,7 @@ namespace _munin.conf
"nullable": false, "nullable": false,
"type": "integer", "type": "integer",
}, },
"interval": { "reminders": {
"nullable": false, "nullable": false,
"type": "array", "type": "array",
"items": { "items": {
@ -415,7 +436,7 @@ namespace _munin.conf
"nullable": false, "nullable": false,
"type": "object", "type": "object",
"properties": { "properties": {
"poll_delay": { "interval": {
"nullable": false, "nullable": false,
"type": "number", "type": "number",
"default": 1.0 "default": 1.0

View file

@ -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( const window_from : lib_plankton.pit.type_pit = lib_plankton.pit.shift_hour(
now, now,
hours + 0 hours + 0
); );
const window_to : lib_plankton.pit.type_pit = lib_plankton.pit.shift_hour( const window_to : lib_plankton.pit.type_pit = lib_plankton.pit.shift_hour(
now, now,
hours + (conf.settings.poll_delay / 2) hours + conf.settings.interval
); );
for (const event of events) { for (const event of events) {
const event_begin : lib_plankton.pit.type_pit = lib_plankton.pit.from_datetime(event.begin); 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", "munin.run.check_dueness",
{ {
"details": { "details": {
"event_begin": lib_plankton.pit.datetime_format(lib_plankton.pit.to_datetime(event_begin)), // "now": lib_plankton.pit.to_date_object(now).toISOString(),
"window_from": lib_plankton.pit.datetime_format(lib_plankton.pit.to_datetime(window_from)), "event_begin": lib_plankton.pit.to_date_object(event_begin).toISOString(),
"window_to": lib_plankton.pit.datetime_format(lib_plankton.pit.to_datetime(window_to)), "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": { "details": {
"event": event, "event": event,
"target": target, "target": target.show(),
} }
} }
); );
@ -128,7 +129,7 @@ namespace _munin
); );
while (true) { while (true) {
await run_iteration(conf, sources, targets, {"dry_run": dry_run}); 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"], "indicators_short": ["c"],
"type": lib_plankton.args.enum_type.string, "type": lib_plankton.args.enum_type.string,
"mode": lib_plankton.args.enum_mode.replace, "mode": lib_plankton.args.enum_mode.replace,
"default": "conf.json", "default": "munin.json",
"info": "path to configuration file", "info": "path to configuration file",
"name": "conf-path", "name": "conf-path",
}), }),
@ -243,7 +244,7 @@ namespace _munin
"threshold": args.verbosity, "threshold": args.verbosity,
} }
}, },
} },
] ]
], ],
} }

View file

@ -25,7 +25,7 @@ namespace _munin.sources.ical_feed
"path": url.path, "path": url.path,
"version": "HTTP/2", "version": "HTTP/2",
"method": lib_plankton.http.enum_method.get, "method": lib_plankton.http.enum_method.get,
"query": url.query, "query": ("?" + url.query),
"headers": {}, "headers": {},
"body": null, "body": null,
}; };
@ -64,13 +64,25 @@ namespace _munin.sources.ical_feed
) )
.map( .map(
vevent => { 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 = { const begin : lib_plankton.pit.type_datetime = {
"timezone_shift": 0, "timezone_shift": timezone_shift,
"date": vevent.dtstart.value.date, "date": vevent.dtstart.value.date,
"time": vevent.dtstart.value.time, "time": vevent.dtstart.value.time,
}; };
const end : lib_plankton.pit.type_datetime = { const end : lib_plankton.pit.type_datetime = {
"timezone_shift": 0, "timezone_shift": timezone_shift,
"date": vevent.dtend.value.date, "date": vevent.dtend.value.date,
"time": vevent.dtend.value.time, "time": vevent.dtend.value.time,
}; };

View file

@ -26,7 +26,7 @@ namespace _munin.targets.telegram_bot
export type type_parameters = { export type type_parameters = {
bot_token : string; bot_token : string;
chat_id : int; chat_id : int;
interval : Array<int>; reminders : Array<int>;
}; };
@ -78,7 +78,13 @@ namespace _munin.targets.telegram_bot
) : _munin.type_target ) : _munin.type_target
{ {
return { 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), "send": (labels, event) => send(parameters, labels, event),
}; };
} }

View file

@ -36,7 +36,8 @@ namespace _munin
/** /**
*/ */
export type type_target = { export type type_target = {
interval : Array<int>; reminders : Array<int>;
show : (() => string);
send : ( send : (
( (
labels : type_labels, labels : type_labels,