/* This file is part of »munin«. Copyright 2025 'Fenris Wolf' »munin« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. »munin« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with »munin«. If not, see . */ namespace _munin.conf { /** */ type type_reminder_raw = { frequency : ( "hourly" | "daily" | "weekly" | "monthly" ); offset : int; from : int; to : int; }; /** * @todo rename to "type_conf" */ type type_conf_v6 = { sources : Array< ( { kind : "ical_feed"; data : { url : string; filtration : { category_whitelist : (null | Array); category_blacklist : (null | Array); title_whitelist : (null | Array); title_blacklist : (null | Array); } } } ) >; targets : Array< ( { kind : "email"; data : { smtp_host : string; smtp_port : int; smtp_username : string; smtp_password : string; sender : string; receivers : Array; hide_tags : boolean; reminders : Array; language : string; strings : { notification_head : string; }; } } | { kind : "telegram_bot"; data : { bot_token : string; chat_id : int; hide_tags : boolean; reminders : Array; language : string; strings : { notification_head : string; }; } } ) >; settings : { interval : float; }; }; /** */ const current_version : string = "6"; /** * @todo remove */ export type type_conf = type_conf_v6; /** */ function schema_source_ical_feed( ) : lib_plankton.conf.type_schema { return { "type": "object", "properties": { "kind": { "nullable": false, "type": "string", "enum": ["ical_feed"] }, "data": { "nullable": false, "type": "object", "properties": { "url": { "nullable": false, "type": "string" }, "filtration": { "nullable": false, "type": "object", "properties": { "category_whitelist": { "nullable": true, "type": "array", "items": { "nullable": false, "type": "string", }, "default": null, }, "category_blacklist": { "nullable": true, "type": "array", "items": { "nullable": false, "type": "string", }, "default": null, }, "title_whitelist": { "nullable": true, "type": "array", "items": { "nullable": false, "type": "string", }, "default": null, }, "title_blacklist": { "nullable": true, "type": "array", "items": { "nullable": false, "type": "string", }, "default": null, }, }, "additionalProperties": false, "required": [ ], "default": {} }, }, "additionalProperties": false, "required": [ "url", ] } }, "additionalProperties": false, "required": [ "kind", "data", ] }; } /** */ function schema_sources( ) : lib_plankton.conf.type_schema { return { "nullable": false, "type": "array", "items": { "nullable": false, "anyOf": [ schema_source_ical_feed(), ], } }; } /** */ function schema_reminder( ) : lib_plankton.conf.type_schema { return { "nullable": false, "type": "object", "properties": { "frequency": { "nullable": false, "type": "string", "enum": [ "hourly", "daily", "weekly", "monthly", ] }, "offset": { "nullable": false, "type": "integer", "default": 0 }, "from": { "nullable": false, "type": "integer" }, "to": { "nullable": false, "type": "integer" }, }, "additionalProperties": false, "required": [ "frequency", "from", "to", ] }; } /** */ function default_reminder( ) : any { return [ { "frequency": "hourly", "from": 24, "to": 25 } ]; } /** */ function schema_target_email( ) : lib_plankton.conf.type_schema { return { "nullable": false, "type": "object", "properties": { "kind": { "nullable": false, "type": "string", "enum": ["email"] }, "data": { "nullable": false, "type": "object", "properties": { "smtp_host": { "nullable": false, "type": "string", }, "smtp_port": { "nullable": false, "type": "integer", }, "smtp_username": { "nullable": false, "type": "string", }, "smtp_password": { "nullable": false, "type": "string", }, "sender": { "nullable": false, "type": "string", "default": "munin" }, "receivers": { "nullable": false, "type": "array", "items": { "nullable": false, "type": "string", } }, "hide_tags": { "nullable": false, "type": "boolean", "default": false, }, "reminders": { "nullable": false, "type": "array", "items": schema_reminder(), "default": default_reminder(), }, "language": { "nullable": false, "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": [ "smtp_host", "smtp_port", "smtp_username", "smtp_password", "receivers", ] } }, "additionalProperties": false, "required": [ "kind", "data", ] }; } /** */ function schema_target_telegram_bot( ) : lib_plankton.conf.type_schema { return { "nullable": false, "type": "object", "properties": { "kind": { "nullable": false, "type": "string", "enum": ["telegram_bot"] }, "data": { "nullable": false, "type": "object", "properties": { "bot_token": { "nullable": false, "type": "string", }, "chat_id": { "nullable": false, "type": "integer", }, "hide_tags": { "nullable": false, "type": "boolean", "default": false, }, "reminders": { "nullable": false, "type": "array", "items": schema_reminder(), "default": default_reminder(), }, "language": { "nullable": false, "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": [ "bot_token", "chat_id", ] } }, "additionalProperties": false, "required": [ "kind", "data", ] }; } /** */ function schema_targets( ) : lib_plankton.conf.type_schema { return { "nullable": false, "type": "array", "items": { "nullable": false, "anyOf": [ schema_target_email(), schema_target_telegram_bot(), ] } }; } /** */ function schema_settings( ) : lib_plankton.conf.type_schema { return { "nullable": false, "type": "object", "properties": { "interval": { "nullable": false, "type": "number", "default": 1.0 } }, "additionalProperties": false, "required": [ ], "default": { } }; } /** */ export function schema( ) : lib_plankton.conf.type_schema { return { "nullable": false, "type": "object", "properties": { "sources": schema_sources(), "targets": schema_targets(), "settings": schema_settings(), }, "additionalProperties": false, "required": [ "sources", "targets", ], }; } /** */ export function schema_extended( ) : lib_plankton.conf.type_schema { return { "type": "object", "properties": { "version": { "nullable": false, "type": "string", "enum": [current_version], }, "content": _munin.conf.schema(), } } } /** */ export async function load( path : string ) : Promise { const conf_raw : {version : string; content : any} = await lib_plankton.conf.load_versioned( path, schema, { "v6": null, } ); if (conf_raw.version !== current_version) { throw (new Error("conf expected in version '" + current_version + "'")); } else { return (conf_raw.content as type_conf_v6); } } }