[add] conf:v7 [mod] custom strings

This commit is contained in:
fenris 2025-07-19 12:00:38 +02:00
parent 49b8b4189e
commit eddae51d27
3 changed files with 272 additions and 30 deletions

View file

@ -352,6 +352,7 @@ namespace _munin.conf
* in hours
*/
reminders : Array<type_reminder_raw>;
language : string;
}
}
|
@ -365,6 +366,7 @@ namespace _munin.conf
* in hours
*/
reminders : Array<type_reminder_raw>;
language : string;
}
}
)
@ -373,11 +375,77 @@ namespace _munin.conf
interval : float;
};
};
/**
*/
export type type_conf = type_conf_v6;
type type_conf_v7 = {
sources : Array<
(
{
kind : "ical_feed";
data : {
url : string;
filtration : {
category_whitelist : (null | Array<string>);
category_blacklist : (null | Array<string>);
title_whitelist : (null | Array<string>);
title_blacklist : (null | Array<string>);
}
}
}
)
>;
targets : Array<
(
{
kind : "email";
data : {
smtp_host : string;
smtp_port : int;
smtp_username : string;
smtp_password : string;
sender : string;
receivers : Array<string>;
hide_tags : boolean;
/**
* in hours
*/
reminders : Array<type_reminder_raw>;
language : string;
strings : {
notification_head : string;
};
}
}
|
{
kind : "telegram_bot";
data : {
bot_token : string;
chat_id : int;
hide_tags : boolean;
/**
* in hours
*/
reminders : Array<type_reminder_raw>;
language : string;
strings : {
notification_head : string;
};
}
}
)
>;
settings : {
interval : float;
};
};
/**
*/
export type type_conf = type_conf_v7;
/**
@ -609,12 +677,118 @@ namespace _munin.conf
);
return {
"sources": conf_v5.sources,
"targets": conf_v5.targets,
"targets": (
conf_v5.targets
.map(
target => {
switch (target.kind) {
case "email": {
return {
"kind": "email",
"data": {
"smtp_host": target.data.smtp_host,
"smtp_port": target.data.smtp_port,
"smtp_username": target.data.smtp_username,
"smtp_password": target.data.smtp_password,
"sender": target.data.sender,
"receivers": target.data.receivers,
"hide_tags": target.data.hide_tags,
"reminders": target.data.reminders,
"language": "deu",
},
};
break;
}
case "telegram_bot": {
return {
"kind": "telegram_bot",
"data": {
"bot_token": target.data.bot_token,
"chat_id": target.data.chat_id,
"hide_tags": target.data.hide_tags,
"reminders": target.data.reminders,
"language": "deu",
},
};
break;
}
default: {
// return target;
throw (new Error("unhandled target kind: " + String(target)));
break;
}
}
}
)
),
"settings": conf_v5.settings,
};
}
/**
*/
function convert_from_v6(
conf_v6 : type_conf_v6
) : type_conf_v7
{
return {
"sources": conf_v6.sources,
"targets": (
conf_v6.targets
.map(
target => {
switch (target.kind) {
case "email": {
return {
"kind": "email",
"data": {
"smtp_host": target.data.smtp_host,
"smtp_port": target.data.smtp_port,
"smtp_username": target.data.smtp_username,
"smtp_password": target.data.smtp_password,
"sender": target.data.sender,
"receivers": target.data.receivers,
"hide_tags": target.data.hide_tags,
"reminders": target.data.reminders,
"language": target.data.language,
"strings": {
"notification_head": "{{core}}{{extra}}",
},
},
};
break;
}
case "telegram_bot": {
return {
"kind": "telegram_bot",
"data": {
"bot_token": target.data.bot_token,
"chat_id": target.data.chat_id,
"hide_tags": target.data.hide_tags,
"reminders": target.data.reminders,
"language": target.data.language,
"strings": {
"notification_head": "{{core}}{{extra}}",
},
},
};
break;
}
default: {
// return target;
throw (new Error("unhandled target kind: " + String(target)));
break;
}
}
}
)
),
"settings": conf_v6.settings,
};
}
/**
*/
function schema_source_kalender_digital(
@ -959,6 +1133,21 @@ namespace _munin.conf
"type": "string",
"default": "deu"
},
"strings": {
"nullable": false,
"type": "object",
"properties": {
"notification_head": {
"nullable": false,
"type": "string",
"default": "[{{core}}] {{extra}}"
},
},
"additionalProperties": false,
"required": [
],
"default": {},
},
},
"additionalProperties": false,
"required": [
@ -1022,6 +1211,21 @@ namespace _munin.conf
"type": "string",
"default": "deu"
},
"strings": {
"nullable": false,
"type": "object",
"properties": {
"notification_head": {
"nullable": false,
"type": "string",
"default": "{{core}}{{extra}}"
},
},
"additionalProperties": false,
"required": [
],
"default": {},
},
},
"additionalProperties": false,
"required": [
@ -1147,7 +1351,7 @@ namespace _munin.conf
/**
*/
export function schema(
version : string = "6"
version : string = "7"
) : lib_plankton.conf.type_schema
{
switch (version) {
@ -1173,7 +1377,10 @@ namespace _munin.conf
};
break;
}
default:
case "2":
case "3":
case "4":
case "5":
{
return {
"nullable": false,
@ -1192,6 +1399,24 @@ namespace _munin.conf
};
break;
}
default:
{
return {
"nullable": false,
"type": "object",
"properties": {
"sources": schema_sources(version),
"targets": schema_targets(version),
"settings": schema_settings(version),
},
"additionalProperties": false,
"required": [
"sources",
"targets",
],
};
break;
}
}
}
@ -1211,7 +1436,8 @@ namespace _munin.conf
"3": {"target": "4", "function": convert_from_v3},
"4": {"target": "5", "function": convert_from_v4},
"5": {"target": "6", "function": convert_from_v5},
"6": null,
"6": {"target": "7", "function": convert_from_v6},
"7": null,
}
);
@ -1249,7 +1475,7 @@ namespace _munin.conf
}
}
*/
return (conf_raw.content as type_conf_v6);
return (conf_raw.content as type_conf_v7);
}
}

View file

@ -33,6 +33,9 @@ namespace _munin.targets.email
hide_tags : boolean;
reminders : Array<_munin.type_reminder>;
language : string;
strings : {
notification_head : string;
};
};
@ -165,17 +168,22 @@ namespace _munin.targets.email
summarize_event(parameters, events[0])
:
lib_plankton.string.coin(
"[{{head}}] {{count}} {{events}}",
parameters.strings.notification_head,
{
"head": lib_plankton.string.coin(
"core": lib_plankton.string.coin(
"{{event}}-{{reminder}}",
{
"event": get_translation(parameters, "core.event.event").toLowerCase(),
"reminder": get_translation(parameters, "core.reminder.reminder").toLowerCase(),
}
),
"count": events.length.toFixed(0),
"events": get_translation(parameters, "core.event.events"),
"extra": lib_plankton.string.coin(
"{{count}} {{events}}",
{
"count": events.length.toFixed(0),
"events": get_translation(parameters, "core.event.events"),
}
),
}
)
),

View file

@ -29,6 +29,9 @@ namespace _munin.targets.telegram_bot
hide_tags : boolean;
reminders : Array<_munin.type_reminder>;
language : string;
strings : {
notification_head : string;
};
};
@ -116,29 +119,34 @@ namespace _munin.targets.telegram_bot
parameters.bot_token,
parameters.chat_id,
lib_plankton.string.coin(
"*{{head_core}}{{head_extra}}*\n\n{{events}}",
"*{{head}}*\n\n{{body}}",
{
"head_core": lib_plankton.string.coin(
"{{event}}-{{reminder}}",
"head": lib_plankton.string.coin(
parameters.strings.notification_head,
{
"event": lib_plankton.string.capitalize(get_translation(parameters, "core.event.event")),
"reminder": lib_plankton.string.capitalize(get_translation(parameters, "core.reminder.reminder")),
"core": lib_plankton.string.coin(
"{{label_event}}-{{label_reminder}}",
{
"label_event": lib_plankton.string.capitalize(get_translation(parameters, "core.event.event")),
"label_reminder": lib_plankton.string.capitalize(get_translation(parameters, "core.reminder.reminder")),
}
),
"extra": (
(events.length <= 1)
?
""
:
lib_plankton.string.coin(
" ({{count}} {{events}})",
{
"count": events.length.toFixed(0),
"events": get_translation(parameters, "core.event.events"),
}
)
),
}
),
"head_extra": (
(events.length <= 1)
?
""
:
lib_plankton.string.coin(
" ({{count}} {{events}})",
{
"count": events.length.toFixed(0),
"events": get_translation(parameters, "core.event.events"),
}
)
),
"events": (
"body": (
events
.map(event => render_event(parameters, event))
.join("\n\n--------\n\n")