2023-06-18 23:29:57 +02:00
|
|
|
async function main(
|
|
|
|
|
) : Promise<void>
|
|
|
|
|
{
|
|
|
|
|
// consts
|
|
|
|
|
const version : string = "0.8";
|
|
|
|
|
|
|
|
|
|
// init
|
|
|
|
|
await lib_plankton.translate.initialize_promise(
|
|
|
|
|
{
|
|
|
|
|
"verbosity": 1,
|
|
|
|
|
"order": ["de", "en"],
|
|
|
|
|
"packages": await Promise.all(
|
|
|
|
|
[
|
|
|
|
|
{"identifier": "de", "path": "localization/de.json"},
|
|
|
|
|
{"identifier": "en", "path": "localization/en.json"},
|
|
|
|
|
]
|
|
|
|
|
.map(
|
|
|
|
|
(entry) => (
|
|
|
|
|
lib_plankton.file.read(entry.path)
|
|
|
|
|
.then(content => Promise.resolve(JSON.parse(content)))
|
|
|
|
|
.then(tree => Promise.resolve({"meta": {"identifier": entry.identifier}, "tree": tree}))
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// args
|
|
|
|
|
const arg_handler : lib_plankton.args.class_handler = new lib_plankton.args.class_handler(
|
|
|
|
|
{
|
|
|
|
|
"order_path": new lib_plankton.args.class_argument(
|
|
|
|
|
{
|
|
|
|
|
"name": "order_path",
|
|
|
|
|
"type": lib_plankton.args.enum_type.string,
|
|
|
|
|
"kind": lib_plankton.args.enum_kind.positional,
|
|
|
|
|
"mode": lib_plankton.args.enum_mode.replace,
|
|
|
|
|
"default": "monitoring.hmdl.json",
|
|
|
|
|
"parameters": {
|
|
|
|
|
"index": 0,
|
|
|
|
|
},
|
|
|
|
|
"info": lib_plankton.translate.get("help.args.order_path"),
|
|
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
"show_help": new lib_plankton.args.class_argument(
|
|
|
|
|
{
|
|
|
|
|
"name": "help",
|
|
|
|
|
"type": lib_plankton.args.enum_type.boolean,
|
|
|
|
|
"kind": lib_plankton.args.enum_kind.volatile,
|
|
|
|
|
"mode": lib_plankton.args.enum_mode.replace,
|
|
|
|
|
"default": false,
|
|
|
|
|
"parameters": {
|
|
|
|
|
"indicators_long": ["help"],
|
|
|
|
|
"indicators_short": ["h"],
|
|
|
|
|
},
|
|
|
|
|
"info": lib_plankton.translate.get("help.args.show_help"),
|
|
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
"show_version": new lib_plankton.args.class_argument(
|
|
|
|
|
{
|
|
|
|
|
"name": "version",
|
|
|
|
|
"type": lib_plankton.args.enum_type.boolean,
|
|
|
|
|
"kind": lib_plankton.args.enum_kind.volatile,
|
|
|
|
|
"mode": lib_plankton.args.enum_mode.replace,
|
|
|
|
|
"default": false,
|
|
|
|
|
"parameters": {
|
|
|
|
|
"indicators_long": ["version"],
|
|
|
|
|
"indicators_short": ["v"],
|
|
|
|
|
},
|
|
|
|
|
"info": lib_plankton.translate.get("help.args.show_version"),
|
|
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
"show_schema": new lib_plankton.args.class_argument(
|
|
|
|
|
{
|
|
|
|
|
"name": "schema",
|
|
|
|
|
"type": lib_plankton.args.enum_type.boolean,
|
|
|
|
|
"kind": lib_plankton.args.enum_kind.volatile,
|
|
|
|
|
"mode": lib_plankton.args.enum_mode.replace,
|
|
|
|
|
"default": false,
|
|
|
|
|
"parameters": {
|
|
|
|
|
"indicators_long": ["schema"],
|
|
|
|
|
"indicators_short": ["s"],
|
|
|
|
|
},
|
|
|
|
|
"info": lib_plankton.translate.get("help.args.show_schema"),
|
|
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
"expose_full_order": new lib_plankton.args.class_argument(
|
|
|
|
|
{
|
|
|
|
|
"name": "expose_full_order",
|
|
|
|
|
"type": lib_plankton.args.enum_type.boolean,
|
|
|
|
|
"kind": lib_plankton.args.enum_kind.volatile,
|
|
|
|
|
"mode": lib_plankton.args.enum_mode.replace,
|
|
|
|
|
"default": false,
|
|
|
|
|
"parameters": {
|
|
|
|
|
"indicators_long": ["expose-full-order"],
|
|
|
|
|
"indicators_short": ["e"],
|
|
|
|
|
},
|
|
|
|
|
"info": lib_plankton.translate.get("help.args.expose_full_order"),
|
|
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
"erase_state": new lib_plankton.args.class_argument(
|
|
|
|
|
{
|
|
|
|
|
"name": "erase_state",
|
|
|
|
|
"type": lib_plankton.args.enum_type.boolean,
|
|
|
|
|
"kind": lib_plankton.args.enum_kind.volatile,
|
|
|
|
|
"mode": lib_plankton.args.enum_mode.replace,
|
|
|
|
|
"default": false,
|
|
|
|
|
"parameters": {
|
|
|
|
|
"indicators_long": ["erase-state"],
|
|
|
|
|
"indicators_short": ["x"],
|
|
|
|
|
},
|
|
|
|
|
"info": lib_plankton.translate.get("help.args.erase_state"),
|
|
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
"database_path": new lib_plankton.args.class_argument(
|
|
|
|
|
{
|
|
|
|
|
"name": "database_path",
|
|
|
|
|
"type": lib_plankton.args.enum_type.string,
|
|
|
|
|
"kind": lib_plankton.args.enum_kind.volatile,
|
|
|
|
|
"mode": lib_plankton.args.enum_mode.replace,
|
|
|
|
|
"default": false,
|
|
|
|
|
"parameters": {
|
|
|
|
|
"indicators_long": ["database-path"],
|
|
|
|
|
"indicators_short": ["d"],
|
|
|
|
|
},
|
|
|
|
|
"info": lib_plankton.translate.get("help.args.database_path"),
|
|
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
"mutex_path": new lib_plankton.args.class_argument(
|
|
|
|
|
{
|
|
|
|
|
"name": "mutex_path",
|
|
|
|
|
"type": lib_plankton.args.enum_type.string,
|
|
|
|
|
"kind": lib_plankton.args.enum_kind.volatile,
|
|
|
|
|
"mode": lib_plankton.args.enum_mode.replace,
|
|
|
|
|
"default": false,
|
|
|
|
|
"parameters": {
|
|
|
|
|
"indicators_long": ["mutex-path"],
|
|
|
|
|
"indicators_short": ["m"],
|
|
|
|
|
},
|
|
|
|
|
"info": lib_plankton.translate.get("help.args.mutex_path"),
|
|
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
"send_ok_notifications": new lib_plankton.args.class_argument(
|
|
|
|
|
{
|
|
|
|
|
"name": "send_ok_notifications",
|
|
|
|
|
"type": lib_plankton.args.enum_type.boolean,
|
|
|
|
|
"kind": lib_plankton.args.enum_kind.volatile,
|
|
|
|
|
"mode": lib_plankton.args.enum_mode.replace,
|
|
|
|
|
"default": false,
|
|
|
|
|
"parameters": {
|
|
|
|
|
"indicators_long": ["send-ok-notifications"],
|
|
|
|
|
"indicators_short": ["y"],
|
|
|
|
|
},
|
|
|
|
|
"info": lib_plankton.translate.get("help.args.send_ok_notifications"),
|
|
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
"language": new lib_plankton.args.class_argument(
|
|
|
|
|
{
|
|
|
|
|
"name": "language",
|
|
|
|
|
"type": lib_plankton.args.enum_type.string,
|
|
|
|
|
"kind": lib_plankton.args.enum_kind.volatile,
|
|
|
|
|
"mode": lib_plankton.args.enum_mode.replace,
|
|
|
|
|
"default": false,
|
|
|
|
|
"parameters": {
|
|
|
|
|
"indicators_long": ["language"],
|
|
|
|
|
"indicators_short": ["l"],
|
|
|
|
|
},
|
|
|
|
|
"info": lib_plankton.translate.get("help.args.language"),
|
|
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
"time_to_live": new lib_plankton.args.class_argument(
|
|
|
|
|
{
|
|
|
|
|
"name": "time_to_live",
|
|
|
|
|
"type": lib_plankton.args.enum_type.float,
|
|
|
|
|
"kind": lib_plankton.args.enum_kind.volatile,
|
|
|
|
|
"mode": lib_plankton.args.enum_mode.replace,
|
|
|
|
|
"default": (60 * 60 * 24 * 7),
|
|
|
|
|
"parameters": {
|
|
|
|
|
"indicators_long": ["time-to-live"],
|
|
|
|
|
"indicators_short": ["t"],
|
|
|
|
|
},
|
|
|
|
|
"info": lib_plankton.translate.get("help.args.time_to_live"),
|
|
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
const args : Record<string, any> = arg_handler.read(
|
|
|
|
|
lib_plankton.args.enum_environment.cli,
|
|
|
|
|
process.argv.slice(2).join(" ")
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// exec
|
|
|
|
|
if (args.show_help) {
|
|
|
|
|
process.stdout.write(
|
|
|
|
|
arg_handler.generate_help(
|
|
|
|
|
{
|
|
|
|
|
"programname": "heimdall",
|
|
|
|
|
"description": lib_plankton.translate.get("help.title"),
|
|
|
|
|
"executable": "heimdall",
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (args.show_version) {
|
|
|
|
|
process.stdout.write(version + "\n");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (args.show_version) {
|
|
|
|
|
process.stdout.write(version + "\n");
|
|
|
|
|
}
|
|
|
|
|
else {
|
2023-06-19 13:05:17 +02:00
|
|
|
const check_kind_implementations : Record<string, _heimdall.check_kinds.type_check_kind> = {
|
2023-06-18 23:29:57 +02:00
|
|
|
};
|
2023-06-19 13:05:17 +02:00
|
|
|
const notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind> = {
|
2023-06-18 23:29:57 +02:00
|
|
|
};
|
|
|
|
|
if (args.show_schema) {
|
|
|
|
|
process.stdout.write(
|
|
|
|
|
lib_plankton.json.encode(
|
|
|
|
|
_heimdall.order.schema_root(
|
|
|
|
|
check_kind_implementations,
|
2023-06-19 13:05:17 +02:00
|
|
|
notification_kind_implementations
|
2023-06-18 23:29:57 +02:00
|
|
|
),
|
|
|
|
|
true
|
|
|
|
|
)
|
|
|
|
|
+
|
|
|
|
|
"\n"
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
else {
|
2023-06-19 13:05:17 +02:00
|
|
|
const nm_path = require("path");
|
|
|
|
|
const nm_fs = require("fs");
|
|
|
|
|
if (! nm_fs.existsSync(args["order_path"])) {
|
|
|
|
|
process.stderr.write(
|
|
|
|
|
lib_plankton.translate.get(
|
|
|
|
|
"misc.order_file_not_found",
|
|
|
|
|
{
|
|
|
|
|
"path": args["order_path"],
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// get order data
|
|
|
|
|
const order = await _heimdall.order.load(
|
|
|
|
|
check_kind_implementations,
|
|
|
|
|
notification_kind_implementations,
|
|
|
|
|
nm_path.normalize(args["order_path"])
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (args["expose_full_order"]) {
|
|
|
|
|
process.stdout.write(lib_plankton.json.encode(order, true) + "\n");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
const database_path : string = (
|
|
|
|
|
(args["database_path"] !== null)
|
|
|
|
|
? args["database_path"]
|
|
|
|
|
: nm_path.join(
|
|
|
|
|
// TODO get path from fs or path module?
|
|
|
|
|
"/tmp",
|
|
|
|
|
lib_plankton.string.coin(
|
|
|
|
|
"monitoring-state-{{id}}.sqlite",
|
|
|
|
|
{
|
|
|
|
|
"id": lib_plankton.call.convey(
|
|
|
|
|
args["order_path"],
|
|
|
|
|
[
|
|
|
|
|
nm_path.normalize,
|
|
|
|
|
// encode(ascii),
|
|
|
|
|
x => lib_plankton.sha256.get(x),
|
|
|
|
|
x => x.slice(0, 8),
|
|
|
|
|
]
|
|
|
|
|
),
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
lib_plankton.log.info(
|
|
|
|
|
lib_plankton.translate.get("misc.state_file_path"),
|
|
|
|
|
{
|
|
|
|
|
"database_path": database_path,
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// mutex check
|
|
|
|
|
if (nm_path.exists(args["mutex_path"])) {
|
|
|
|
|
lib_plankton.log.error(
|
|
|
|
|
lib_plankton.translate.get("misc.still_running"),
|
|
|
|
|
{
|
|
|
|
|
"mutex_path": args["mutex_path"],
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
process.exit(2);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
await _heimdall.state_repository.setup(database_path);
|
|
|
|
|
const clean_count : int = await _heimdall.state_repository.clean(
|
|
|
|
|
database_path,
|
|
|
|
|
args["time_to_live"],
|
|
|
|
|
args["erase_state"]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// create mutex file
|
|
|
|
|
await lib_plankton.file.write(args["mutex_path"], "");
|
|
|
|
|
|
|
|
|
|
order.checks.forEach(
|
|
|
|
|
check => {
|
|
|
|
|
if (! check.active) {
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
process.stdout.write(JSON.stringify(order, undefined, "\t") + "\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// drop mutex file
|
|
|
|
|
await lib_plankton.file.delete(args["mutex_path"]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-06-18 23:29:57 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main();
|