Compare commits
3 commits
196ee61fd9
...
0ac13808c5
Author | SHA1 | Date | |
---|---|---|---|
![]() |
0ac13808c5 | ||
![]() |
7a882e76ea | ||
![]() |
c23175163b |
|
@ -6236,7 +6236,7 @@ var lib_plankton;
|
|||
const http_response = await lib_plankton.http.call(http_request);
|
||||
const output_wrapped = lib_plankton.json.decode(http_response.body.toString());
|
||||
if (!output_wrapped.ok) {
|
||||
return Promise.reject(new Error());
|
||||
return Promise.reject(JSON.stringify(output_wrapped));
|
||||
}
|
||||
else {
|
||||
return Promise.resolve(output_wrapped.result);
|
||||
|
|
215
source/conf.ts
215
source/conf.ts
|
@ -136,6 +136,7 @@ namespace _munin.conf
|
|||
smtp_port : int;
|
||||
smtp_username : string;
|
||||
smtp_password : string;
|
||||
sender : string;
|
||||
receivers : Array<string>;
|
||||
/**
|
||||
* in hours
|
||||
|
@ -171,7 +172,71 @@ namespace _munin.conf
|
|||
|
||||
/**
|
||||
*/
|
||||
export type type_conf = type_conf_v3;
|
||||
type type_conf_v4 = {
|
||||
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<int>;
|
||||
}
|
||||
}
|
||||
|
|
||||
{
|
||||
kind : "telegram_bot";
|
||||
data : {
|
||||
bot_token : string;
|
||||
chat_id : int;
|
||||
hide_tags : boolean;
|
||||
/**
|
||||
* in hours
|
||||
*/
|
||||
reminders : Array<int>;
|
||||
}
|
||||
}
|
||||
)
|
||||
>;
|
||||
settings : {
|
||||
interval : float;
|
||||
};
|
||||
labels : {
|
||||
head : string;
|
||||
title : string;
|
||||
time : string;
|
||||
location : string;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
export type type_conf = type_conf_v4;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -253,6 +318,84 @@ namespace _munin.conf
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
function convert_from_v3(
|
||||
conf_v3 : type_conf_v3
|
||||
) : type_conf_v4
|
||||
{
|
||||
return {
|
||||
"sources": conf_v3.sources.map(
|
||||
source => {
|
||||
switch (source.kind) {
|
||||
case "ical_feed": {
|
||||
return {
|
||||
"kind": "ical_feed",
|
||||
"data": {
|
||||
"url": source.data.url,
|
||||
"filtration": {
|
||||
"category_whitelist": null,
|
||||
"category_blacklist": source.data.filtration.category_blacklist,
|
||||
"title_whitelist": null,
|
||||
"title_blacklist": source.data.filtration.category_blacklist,
|
||||
},
|
||||
}
|
||||
};
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
// return source;
|
||||
throw (new Error("unhandled source kind: " + source.kind));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
),
|
||||
"targets": conf_v3.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": false,
|
||||
"reminders": target.data.reminders,
|
||||
},
|
||||
};
|
||||
break;
|
||||
}
|
||||
case "telegram_bot": {
|
||||
return {
|
||||
"kind": "telegram_bot",
|
||||
"data": {
|
||||
"bot_token": target.data.bot_token,
|
||||
"chat_id": target.data.chat_id,
|
||||
"hide_tags": false,
|
||||
"reminders": target.data.reminders,
|
||||
},
|
||||
};
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
// return target;
|
||||
throw (new Error("unhandled target kind: " + String(target)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
),
|
||||
"settings": conf_v3.settings,
|
||||
"labels": conf_v3.labels,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
function schema_source_kalender_digital(
|
||||
|
@ -280,7 +423,7 @@ namespace _munin.conf
|
|||
"type": "object",
|
||||
"properties": {
|
||||
"category_blacklist": {
|
||||
"nullable": false,
|
||||
"nullable": true,
|
||||
"type": "array",
|
||||
"items": {
|
||||
"nullable": false,
|
||||
|
@ -289,7 +432,7 @@ namespace _munin.conf
|
|||
"default": [],
|
||||
},
|
||||
"title_blacklist": {
|
||||
"nullable": false,
|
||||
"nullable": true,
|
||||
"type": "array",
|
||||
"items": {
|
||||
"nullable": false,
|
||||
|
@ -345,23 +488,41 @@ namespace _munin.conf
|
|||
"nullable": false,
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"category_blacklist": {
|
||||
"nullable": false,
|
||||
"category_whitelist": {
|
||||
"nullable": true,
|
||||
"type": "array",
|
||||
"items": {
|
||||
"nullable": false,
|
||||
"type": "string",
|
||||
},
|
||||
"default": [],
|
||||
"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": false,
|
||||
"nullable": true,
|
||||
"type": "array",
|
||||
"items": {
|
||||
"nullable": false,
|
||||
"type": "string",
|
||||
},
|
||||
"default": [],
|
||||
"default": null,
|
||||
},
|
||||
},
|
||||
"additionalProperties": false,
|
||||
|
@ -433,6 +594,11 @@ namespace _munin.conf
|
|||
"type": "string",
|
||||
}
|
||||
},
|
||||
"hide_tags": {
|
||||
"nullable": false,
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
},
|
||||
"reminders": {
|
||||
"nullable": false,
|
||||
"type": "array",
|
||||
|
@ -527,6 +693,11 @@ namespace _munin.conf
|
|||
"nullable": false,
|
||||
"type": "integer",
|
||||
},
|
||||
"hide_tags": {
|
||||
"nullable": false,
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
},
|
||||
"reminders": {
|
||||
"nullable": false,
|
||||
"type": "array",
|
||||
|
@ -652,8 +823,8 @@ namespace _munin.conf
|
|||
|
||||
/**
|
||||
*/
|
||||
function schema(
|
||||
version : string
|
||||
export function schema(
|
||||
version : string = "4"
|
||||
) : lib_plankton.conf.type_schema
|
||||
{
|
||||
switch (version) {
|
||||
|
@ -679,9 +850,9 @@ namespace _munin.conf
|
|||
};
|
||||
break;
|
||||
}
|
||||
default:
|
||||
case "2":
|
||||
case "3": {
|
||||
case "3":
|
||||
case "4": {
|
||||
return {
|
||||
"nullable": false,
|
||||
"type": "object",
|
||||
|
@ -715,27 +886,37 @@ namespace _munin.conf
|
|||
{
|
||||
"1": {"target": "2", "function": convert_from_v1},
|
||||
"2": {"target": "3", "function": convert_from_v2},
|
||||
"3": null,
|
||||
"3": {"target": "4", "function": convert_from_v3},
|
||||
"4": null,
|
||||
}
|
||||
);
|
||||
|
||||
/*
|
||||
switch (conf_raw.version) {
|
||||
case "1": {
|
||||
const conf_v1 : type_conf_v1 = (conf_raw.content as type_conf_v1);
|
||||
const conf_v2 : type_conf_v2 = convert_from_v1(conf_v1);
|
||||
const conf_v3 : type_conf_v3 = convert_from_v2(conf_v2);
|
||||
return conf_v3;
|
||||
const conf_v4 : type_conf_v4 = convert_from_v3(conf_v3);
|
||||
return conf_v4;
|
||||
break;
|
||||
}
|
||||
case "2": {
|
||||
const conf_v2 : type_conf_v2 = (conf_raw.content as type_conf_v2);
|
||||
const conf_v3 : type_conf_v3 = convert_from_v2(conf_v2);
|
||||
return conf_v3;
|
||||
const conf_v4 : type_conf_v4 = convert_from_v3(conf_v3);
|
||||
return conf_v4;
|
||||
break;
|
||||
}
|
||||
case "3": {
|
||||
const conf_v3 : type_conf_v3 = (conf_raw.content as type_conf_v3);
|
||||
return conf_v3;
|
||||
const conf_v4 : type_conf_v4 = convert_from_v3(conf_v3);
|
||||
return conf_v4;
|
||||
break;
|
||||
}
|
||||
case "4": {
|
||||
const conf_v4 : type_conf_v4 = (conf_raw.content as type_conf_v4);
|
||||
return conf_v4;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
@ -743,6 +924,8 @@ namespace _munin.conf
|
|||
break;
|
||||
}
|
||||
}
|
||||
*/
|
||||
return (conf_raw.content as type_conf_v4);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
143
source/main.ts
143
source/main.ts
|
@ -88,7 +88,7 @@ namespace _munin
|
|||
}
|
||||
else {
|
||||
lib_plankton.log._info(
|
||||
"munin.remind",
|
||||
"munin.remind.do",
|
||||
{
|
||||
"details": {
|
||||
"event": event,
|
||||
|
@ -100,7 +100,19 @@ namespace _munin
|
|||
// do nothing
|
||||
}
|
||||
else {
|
||||
await target.send(conf.labels, event);
|
||||
try {
|
||||
await target.send(conf.labels, event);
|
||||
}
|
||||
catch (error) {
|
||||
lib_plankton.log.error(
|
||||
"munin.remind.error",
|
||||
{
|
||||
"details": {
|
||||
"message": String(error),
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -176,6 +188,15 @@ namespace _munin
|
|||
"info": "path to configuration file",
|
||||
"name": "conf-path",
|
||||
}),
|
||||
"conf_schema": lib_plankton.args.class_argument.volatile({
|
||||
"indicators_long": ["conf-schema"],
|
||||
"indicators_short": ["s"],
|
||||
"type": lib_plankton.args.enum_type.string,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": "",
|
||||
"info": "only print the configuration schema in a specific version (latest version via argument '_')",
|
||||
"name": "conf-schema",
|
||||
}),
|
||||
"conf_expose": lib_plankton.args.class_argument.volatile({
|
||||
"indicators_long": ["conf-expose"],
|
||||
"indicators_short": ["e"],
|
||||
|
@ -187,11 +208,11 @@ namespace _munin
|
|||
}),
|
||||
"single_run": lib_plankton.args.class_argument.volatile({
|
||||
"indicators_long": ["single-run"],
|
||||
"indicators_short": ["s"],
|
||||
"indicators_short": ["x"],
|
||||
"type": lib_plankton.args.enum_type.boolean,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": false,
|
||||
"info": "whether to only execute on iteration at run",
|
||||
"info": "whether to only execute one iteration at run",
|
||||
"name": "single-run",
|
||||
}),
|
||||
"verbosity": lib_plankton.args.class_argument.volatile({
|
||||
|
@ -240,46 +261,10 @@ namespace _munin
|
|||
);
|
||||
}
|
||||
else {
|
||||
// init
|
||||
const conf : _munin.conf.type_conf = await _munin.conf.load(args.conf_path);
|
||||
lib_plankton.log.set_main_logger(
|
||||
[
|
||||
{
|
||||
"kind": "filtered",
|
||||
"data": {
|
||||
"core": {
|
||||
"kind": "std",
|
||||
"data": {
|
||||
"target": "stdout",
|
||||
"format": {
|
||||
"kind": "human_readable",
|
||||
"data": {
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"predicate": [
|
||||
[
|
||||
{
|
||||
"item": {
|
||||
"kind": "level",
|
||||
"data": {
|
||||
"threshold": args.verbosity,
|
||||
}
|
||||
},
|
||||
},
|
||||
]
|
||||
],
|
||||
}
|
||||
},
|
||||
]
|
||||
);
|
||||
|
||||
// exec
|
||||
if (args.conf_expose) {
|
||||
if (args.conf_schema !== "") {
|
||||
process.stdout.write(
|
||||
lib_plankton.json.encode(
|
||||
conf,
|
||||
_munin.conf.schema((args.conf_schema === "_") ? undefined : args.conf_schema),
|
||||
{
|
||||
"formatted": true,
|
||||
}
|
||||
|
@ -288,20 +273,70 @@ namespace _munin
|
|||
"\n"
|
||||
);
|
||||
}
|
||||
switch (/*args.action*/"run") {
|
||||
default: {
|
||||
throw (new Error("unhandled action: " + args.action));
|
||||
break;
|
||||
}
|
||||
case "run": {
|
||||
run(
|
||||
conf,
|
||||
else {
|
||||
// init
|
||||
const conf : _munin.conf.type_conf = await _munin.conf.load(args.conf_path);
|
||||
lib_plankton.log.set_main_logger(
|
||||
[
|
||||
{
|
||||
"single_run": args.single_run,
|
||||
"dry_run": args.dry_run,
|
||||
}
|
||||
"kind": "filtered",
|
||||
"data": {
|
||||
"core": {
|
||||
"kind": "std",
|
||||
"data": {
|
||||
"target": "stdout",
|
||||
"format": {
|
||||
"kind": "human_readable",
|
||||
"data": {
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"predicate": [
|
||||
[
|
||||
{
|
||||
"item": {
|
||||
"kind": "level",
|
||||
"data": {
|
||||
"threshold": args.verbosity,
|
||||
}
|
||||
},
|
||||
},
|
||||
]
|
||||
],
|
||||
}
|
||||
},
|
||||
]
|
||||
);
|
||||
|
||||
// exec
|
||||
if (args.conf_expose) {
|
||||
process.stdout.write(
|
||||
lib_plankton.json.encode(
|
||||
conf,
|
||||
{
|
||||
"formatted": true,
|
||||
}
|
||||
)
|
||||
+
|
||||
"\n"
|
||||
);
|
||||
break;
|
||||
}
|
||||
switch (/*args.action*/"run") {
|
||||
default: {
|
||||
throw (new Error("unhandled action: " + args.action));
|
||||
break;
|
||||
}
|
||||
case "run": {
|
||||
run(
|
||||
conf,
|
||||
{
|
||||
"single_run": args.single_run,
|
||||
"dry_run": args.dry_run,
|
||||
}
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,8 +26,10 @@ namespace _munin.sources.ical_feed
|
|||
export type type_parameters = {
|
||||
url : string;
|
||||
filtration : {
|
||||
category_blacklist : Array<string>;
|
||||
title_blacklist : Array<string>;
|
||||
category_whitelist : (null | Array<string>);
|
||||
category_blacklist : (null | Array<string>);
|
||||
title_whitelist : (null | Array<string>);
|
||||
title_blacklist : (null | Array<string>);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -56,27 +58,52 @@ namespace _munin.sources.ical_feed
|
|||
vcalendar.vevents
|
||||
.filter(
|
||||
vevent => (
|
||||
// category
|
||||
// category whitelist
|
||||
(
|
||||
vevent.categories.every(
|
||||
(parameters.filtration.category_whitelist === null)
|
||||
||
|
||||
vevent.categories.some(
|
||||
category => (
|
||||
! (
|
||||
parameters.filtration.category_blacklist
|
||||
.map(category_ => category_.toLowerCase())
|
||||
.includes(category.toLowerCase())
|
||||
)
|
||||
parameters.filtration.category_whitelist
|
||||
.map(category_ => category_.toLowerCase())
|
||||
.includes(category.toLowerCase())
|
||||
)
|
||||
)
|
||||
)
|
||||
&&
|
||||
// title
|
||||
// category blacklist
|
||||
(
|
||||
parameters.filtration.title_blacklist.every(
|
||||
(parameters.filtration.category_blacklist === null)
|
||||
||
|
||||
vevent.categories.every (
|
||||
category => ! (
|
||||
parameters.filtration.category_blacklist
|
||||
.map(category_ => category_.toLowerCase())
|
||||
.includes(category.toLowerCase())
|
||||
)
|
||||
)
|
||||
)
|
||||
&&
|
||||
// title whitelist
|
||||
(
|
||||
(parameters.filtration.title_whitelist === null)
|
||||
||
|
||||
parameters.filtration.title_whitelist.some(
|
||||
title => (
|
||||
! (
|
||||
vevent.summary.toLowerCase()
|
||||
.includes(title.toLowerCase())
|
||||
)
|
||||
vevent.summary.toLowerCase()
|
||||
.includes(title.toLowerCase())
|
||||
)
|
||||
)
|
||||
)
|
||||
&&
|
||||
// title blacklist
|
||||
(
|
||||
(parameters.filtration.title_blacklist === null)
|
||||
||
|
||||
parameters.filtration.title_blacklist.every(
|
||||
title => ! (
|
||||
vevent.summary.toLowerCase()
|
||||
.includes(title.toLowerCase())
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
|
@ -30,6 +30,7 @@ namespace _munin.targets.email
|
|||
smtp_password : string;
|
||||
sender : string;
|
||||
receivers : Array<string>;
|
||||
hide_tags : boolean;
|
||||
/**
|
||||
* in hours
|
||||
*/
|
||||
|
@ -76,7 +77,7 @@ namespace _munin.targets.email
|
|||
{
|
||||
"title_label": labels.title.toUpperCase(),
|
||||
"macro_tags": (
|
||||
(event.tags === null)
|
||||
(parameters.hide_tags || (event.tags === null))
|
||||
?
|
||||
""
|
||||
:
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace _munin.targets.telegram_bot
|
|||
export type type_parameters = {
|
||||
bot_token : string;
|
||||
chat_id : int;
|
||||
hide_tags : boolean;
|
||||
reminders : Array<int>;
|
||||
};
|
||||
|
||||
|
@ -46,7 +47,7 @@ namespace _munin.targets.telegram_bot
|
|||
{
|
||||
"head": labels.head,
|
||||
"macro_tags": (
|
||||
(event.tags === null)
|
||||
(parameters.hide_tags || (event.tags === null))
|
||||
?
|
||||
""
|
||||
:
|
||||
|
|
Loading…
Reference in a new issue