2025-04-25 12:50:13 +02:00
|
|
|
/*
|
|
|
|
This file is part of »munin«.
|
|
|
|
|
|
|
|
Copyright 2025 'Fenris Wolf' <fenris@folksprak.org>
|
|
|
|
|
|
|
|
»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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
namespace _munin
|
2025-04-25 00:48:05 +02:00
|
|
|
{
|
2025-06-30 13:06:51 +02:00
|
|
|
|
2025-04-25 00:48:05 +02:00
|
|
|
/**
|
|
|
|
*/
|
|
|
|
export async function main(
|
|
|
|
args_raw : Array<string>
|
|
|
|
): Promise<void>
|
|
|
|
{
|
|
|
|
// args
|
|
|
|
const arg_handler : lib_plankton.args.class_handler = new lib_plankton.args.class_handler(
|
|
|
|
{
|
|
|
|
"action": lib_plankton.args.class_argument.positional({
|
|
|
|
"index": 0,
|
|
|
|
"type": lib_plankton.args.enum_type.string,
|
|
|
|
"mode": lib_plankton.args.enum_mode.replace,
|
|
|
|
"default": "run",
|
2025-06-30 13:06:51 +02:00
|
|
|
"info": "what to do : test | run",
|
2025-04-25 00:48:05 +02:00
|
|
|
"name": "action",
|
|
|
|
}),
|
|
|
|
"conf_path": lib_plankton.args.class_argument.volatile({
|
|
|
|
"indicators_long": ["conf-path"],
|
|
|
|
"indicators_short": ["c"],
|
|
|
|
"type": lib_plankton.args.enum_type.string,
|
|
|
|
"mode": lib_plankton.args.enum_mode.replace,
|
2025-04-28 21:51:03 +02:00
|
|
|
"default": "munin.json",
|
2025-04-25 00:48:05 +02:00
|
|
|
"info": "path to configuration file",
|
|
|
|
"name": "conf-path",
|
|
|
|
}),
|
2025-05-18 06:46:37 +02:00
|
|
|
"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",
|
|
|
|
}),
|
2025-04-25 12:50:13 +02:00
|
|
|
"conf_expose": lib_plankton.args.class_argument.volatile({
|
|
|
|
"indicators_long": ["conf-expose"],
|
|
|
|
"indicators_short": ["e"],
|
|
|
|
"type": lib_plankton.args.enum_type.boolean,
|
|
|
|
"mode": lib_plankton.args.enum_mode.replace,
|
|
|
|
"default": false,
|
|
|
|
"info": "whether to expose the full configuration",
|
|
|
|
"name": "conf-expose",
|
|
|
|
}),
|
2025-04-29 22:19:45 +02:00
|
|
|
"single_run": lib_plankton.args.class_argument.volatile({
|
|
|
|
"indicators_long": ["single-run"],
|
2025-05-18 06:46:37 +02:00
|
|
|
"indicators_short": ["x"],
|
2025-04-29 22:19:45 +02:00
|
|
|
"type": lib_plankton.args.enum_type.boolean,
|
|
|
|
"mode": lib_plankton.args.enum_mode.replace,
|
|
|
|
"default": false,
|
2025-05-18 06:46:37 +02:00
|
|
|
"info": "whether to only execute one iteration at run",
|
2025-04-29 22:19:45 +02:00
|
|
|
"name": "single-run",
|
|
|
|
}),
|
2025-04-25 12:50:13 +02:00
|
|
|
"verbosity": lib_plankton.args.class_argument.volatile({
|
|
|
|
"indicators_long": ["verbosity"],
|
|
|
|
"indicators_short": ["v"],
|
2025-04-25 00:48:05 +02:00
|
|
|
"type": lib_plankton.args.enum_type.string,
|
|
|
|
"mode": lib_plankton.args.enum_mode.replace,
|
2025-04-25 12:50:13 +02:00
|
|
|
"default": "notice",
|
|
|
|
"info": "error | warning | notice | info | debug",
|
|
|
|
"name": "verbosity",
|
|
|
|
}),
|
|
|
|
"dry_run": lib_plankton.args.class_argument.volatile({
|
|
|
|
"indicators_long": ["dry-run"],
|
|
|
|
"indicators_short": ["q"],
|
|
|
|
"type": lib_plankton.args.enum_type.boolean,
|
|
|
|
"mode": lib_plankton.args.enum_mode.replace,
|
|
|
|
"default": false,
|
2025-06-12 07:39:33 +02:00
|
|
|
"info": "whether to skip the sending of reminders (logs will be written)",
|
2025-04-25 12:50:13 +02:00
|
|
|
"name": "dry-run",
|
2025-04-25 00:48:05 +02:00
|
|
|
}),
|
|
|
|
"help": lib_plankton.args.class_argument.volatile({
|
|
|
|
"indicators_long": ["help"],
|
|
|
|
"indicators_short": ["h"],
|
|
|
|
"type": lib_plankton.args.enum_type.boolean,
|
|
|
|
"mode": lib_plankton.args.enum_mode.replace,
|
|
|
|
"default": false,
|
|
|
|
"info": "alias for action 'help'",
|
|
|
|
"name": "help",
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
);
|
|
|
|
const args : Record<string, any> = arg_handler.read(
|
|
|
|
lib_plankton.args.enum_environment.cli,
|
|
|
|
args_raw.join(" ")
|
|
|
|
);
|
|
|
|
|
2025-07-01 12:06:08 +02:00
|
|
|
await lib_plankton.translate.initialize(
|
|
|
|
{
|
|
|
|
"packages": [
|
|
|
|
lib_plankton.json.decode(
|
|
|
|
await lib_plankton.file.read("localization/de.json"),
|
|
|
|
await lib_plankton.file.read("localization/en.json"),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2025-04-27 22:30:22 +02:00
|
|
|
if (args.help) {
|
2025-04-25 00:48:05 +02:00
|
|
|
process.stdout.write(
|
|
|
|
arg_handler.generate_help(
|
|
|
|
{
|
2025-04-25 10:54:41 +02:00
|
|
|
"programname": "munin",
|
|
|
|
"description": "sends reminders about upcoming events",
|
|
|
|
"executable": "node build/munin",
|
2025-04-25 00:48:05 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
2025-05-18 06:46:37 +02:00
|
|
|
if (args.conf_schema !== "") {
|
2025-04-25 12:50:13 +02:00
|
|
|
process.stdout.write(
|
|
|
|
lib_plankton.json.encode(
|
2025-05-18 06:46:37 +02:00
|
|
|
_munin.conf.schema((args.conf_schema === "_") ? undefined : args.conf_schema),
|
2025-04-25 12:50:13 +02:00
|
|
|
{
|
|
|
|
"formatted": true,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
+
|
|
|
|
"\n"
|
|
|
|
);
|
|
|
|
}
|
2025-05-18 06:46:37 +02:00
|
|
|
else {
|
2025-06-30 13:06:51 +02:00
|
|
|
switch (args.action) {
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
throw (new Error("unhandled action: " + args.action));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "test":
|
|
|
|
{
|
|
|
|
_munin.test.all();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "run":
|
|
|
|
{
|
|
|
|
// init
|
|
|
|
const conf : _munin.conf.type_conf = await _munin.conf.load(args.conf_path);
|
|
|
|
lib_plankton.log.set_main_logger(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"kind": "filtered",
|
2025-05-18 06:46:37 +02:00
|
|
|
"data": {
|
2025-06-30 13:06:51 +02:00
|
|
|
"core": {
|
|
|
|
"kind": "std",
|
2025-05-18 06:46:37 +02:00
|
|
|
"data": {
|
2025-06-30 13:06:51 +02:00
|
|
|
"target": "stdout",
|
|
|
|
"format": {
|
|
|
|
"kind": "jsonl",
|
|
|
|
"data": {
|
|
|
|
"structured": true
|
|
|
|
}
|
|
|
|
}
|
2025-05-18 06:46:37 +02:00
|
|
|
}
|
2025-06-30 13:06:51 +02:00
|
|
|
},
|
|
|
|
"predicate": [
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"item": {
|
|
|
|
"kind": "level",
|
|
|
|
"data": {
|
|
|
|
"threshold": args.verbosity,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
],
|
2025-05-18 06:46:37 +02:00
|
|
|
}
|
|
|
|
},
|
2025-06-30 13:06:51 +02:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
// exec
|
|
|
|
if (args.conf_expose) {
|
|
|
|
process.stdout.write(
|
|
|
|
lib_plankton.json.encode(
|
|
|
|
conf,
|
|
|
|
{
|
|
|
|
"formatted": true,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
+
|
|
|
|
"\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_munin.logic.run(
|
2025-05-18 06:46:37 +02:00
|
|
|
conf,
|
|
|
|
{
|
|
|
|
"single_run": args.single_run,
|
|
|
|
"dry_run": args.dry_run,
|
|
|
|
}
|
|
|
|
);
|
2025-06-30 13:06:51 +02:00
|
|
|
|
2025-05-18 06:46:37 +02:00
|
|
|
break;
|
|
|
|
}
|
2025-04-25 00:48:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.resolve<void>(undefined);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-04-25 12:50:13 +02:00
|
|
|
_munin.main(process.argv.slice(2))
|
2025-04-25 00:48:05 +02:00
|
|
|
.then(() => {})
|
|
|
|
.catch((reason) => {process.stderr.write(String(reason) + "\n");})
|
|
|
|
;
|
|
|
|
|