diff --git a/examples/main.hmdl.json b/examples/main.hmdl.json index 1116016..99c1cf3 100644 --- a/examples/main.hmdl.json +++ b/examples/main.hmdl.json @@ -5,7 +5,7 @@ "attentive_interval": 1, "reminding_interval": 20 }, - "threshold": 3, + "threshold": 1, "notifications": [ { "kind": "console", @@ -15,6 +15,6 @@ ] }, "includes": [ - "file_state.hmdl.json" + "tls_certificate.hmdl.json" ] } diff --git a/examples/tls_certificate.hmdl.json b/examples/tls_certificate.hmdl.json index 69c786d..4aa0a87 100644 --- a/examples/tls_certificate.hmdl.json +++ b/examples/tls_certificate.hmdl.json @@ -5,14 +5,7 @@ "kind": "tls_certificate", "parameters": { "host": "greenscale.de", - "expiry_threshold": 50 - } - }, - { - "name": "test2", - "kind": "tls_certificate", - "parameters": { - "host": "chemnitz-gesundheit.de" + "expiry_threshold": 74 } } ] diff --git a/lib/plankton/plankton.d.ts b/lib/plankton/plankton.d.ts index 41d31f5..b6ac230 100644 --- a/lib/plankton/plankton.d.ts +++ b/lib/plankton/plankton.d.ts @@ -202,154 +202,6 @@ declare class class_observer { /** * @author frac */ -declare module lib_maybe { - /** - * @author fenris - */ - type type_maybe = { - kind: string; - parameters: Object; - }; - /** - * @author fenris - */ - function make_nothing(): type_maybe; - /** - * @author fenris - */ - function make_just(value: type_value): type_maybe; - /** - * @author fenris - */ - function is_nothing(maybe: type_maybe): boolean; - /** - * @author fenris - */ - function is_just(maybe: type_maybe): boolean; - /** - * @author fenris - */ - function cull(maybe: type_maybe): type_value; - /** - * @author fenris - */ - function propagate(maybe: type_maybe, function_: (value: type_value) => type_maybe): type_maybe; -} -/** - * @author fenris - */ -declare class class_maybe implements interface_showable { - /** - * @desc whether the wrapper is nothing - * @author fenris - */ - is_nothing(): boolean; - /** - * @desc whether the wrapper is just - * @author fenris - */ - is_just(): boolean; - /** - * @desc return the value, stored in the maybe-wrapper - * @author fenris - */ - cull(): type_value; - /** - * @author fenris - */ - toString(): string; - /** - * @author fenris - */ - distinguish(action_just: (value?: type_value) => void, action_nothing?: (reason?: string) => void): void; - /** - * @author fenris - */ - propagate(action: (value: type_value) => class_maybe): class_maybe; - /** - * @desc [implementation] - * @author fenris - */ - _show(): string; -} -/** - * @author fenris - */ -declare class class_nothing extends class_maybe { - /** - * @author fenris - */ - private reason; - /** - * @author fenris - */ - constructor(reason?: string); - /** - * @author fenris - */ - is_nothing(): boolean; - /** - * @author fenris - */ - is_just(): boolean; - /** - * @author fenris - */ - cull(): type_value; - /** - * @author fenris - */ - toString(): string; - /** - * @author fenris - */ - reason_get(): string; - /** - * @author fenris - */ - distinguish(action_just: (value?: type_value) => void, action_nothing?: (reason?: string) => void): void; - /** - * @author fenris - */ - propagate(action: (value: type_value) => class_maybe): class_maybe; -} -/** - * @author fenris - */ -declare class class_just extends class_maybe { - /** - * @author fenris - */ - private value; - /** - * @author fenris - */ - constructor(value: type_value); - /** - * @author fenris - */ - is_nothing(): boolean; - /** - * @author fenris - */ - is_just(): boolean; - /** - * @author fenris - */ - cull(): type_value; - /** - * @author fenris - */ - toString(): string; - /** - * @author fenris - */ - distinguish(action_just: (value?: type_value) => void, action_nothing?: (reason?: string) => void): void; - /** - * @author fenris - */ - propagate(action: (value: type_value) => class_maybe): class_maybe; -} /** * @author frac */ @@ -383,6 +235,65 @@ declare namespace lib_plankton.base { */ function object_merge(core: Record, mantle: Record): Record; } +declare module lib_plankton.pod { + /** + * @author fenris + */ + type type_pod = { + kind: ("empty" | "filled"); + value?: type_value; + }; + /** + * @author fenris + */ + function make_empty(): type_pod; + /** + * @author fenris + */ + function make_filled(value: type_value): type_pod; + /** + * whether the pod is filled + * + * @author fenris + */ + function is_filled(pod: type_pod): boolean; + /** + * return the value, stored in the pod-wrapper + * + * @author fenris + */ + function cull(pod: type_pod): type_value; + /** + * to pass on a empty-pod or to use a filled-pod + * + * @author fenris + */ + function propagate(pod: type_pod, function_: ((value: type_value) => type_value_)): type_pod; + /** + * @author fenris + */ + function distinguish(pod: type_pod, function_empty: (() => type_result), function_filled: ((value: type_value) => type_result)): type_result; + /** + */ + function show(pod: type_pod, options?: { + show_value?: ((value: type_value) => string); + }): string; +} +declare module lib_plankton.pod { + /** + */ + class class_pod { + private subject; + private constructor(); + is_empty(): boolean; + is_filled(): boolean; + cull(): type_value; + show(show_value?: any): string; + toString(): string; + propagate(function_: ((value: type_value) => type_value_)): class_pod; + distinguish(function_empty: (() => type_result), function_filled: ((value: type_value) => type_result)): type_result; + } +} declare namespace lib_plankton.call { /** * @desc hacked class for postfix function application @@ -544,11 +455,9 @@ declare namespace lib_plankton.call { /** * @author fenris */ - function promise_show(label: string): (result: type_result) => type_promise; /** * @author fenris */ - function promise_log(result: type_result): (result: type_result) => type_promise; /** * @author fenris */ @@ -1180,7 +1089,7 @@ declare namespace lib_plankton.string { to: string; }>, options?: {}): string; /** - * @desc replaces occurences of "${name}" in a string by the corresponding values of an argument object + * @desc replaces occurences of "{{name}}" in a string by the corresponding values of an argument object * @author fenris */ function coin(str: string, args: { @@ -1534,7 +1443,7 @@ declare namespace lib_plankton.translate { */ function fetch(identifier: string, path: string, args?: { [id: string]: string; - }): class_maybe; + }): lib_plankton.pod.type_pod; /** * @desc retrieves a string by going through the order and trying to fetch it for the current entry * @author fenris @@ -1830,7 +1739,7 @@ declare namespace lib_plankton.http { * @author fenris */ type type_response = { - version: string; + version: (null | string); status_code: int; headers: Record; body: Buffer; diff --git a/lib/plankton/plankton.js b/lib/plankton/plankton.js index 8e6d118..9dedef8 100644 --- a/lib/plankton/plankton.js +++ b/lib/plankton/plankton.js @@ -383,261 +383,6 @@ 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 »bacterio-plankton:base«. If not, see . - */ -var lib_maybe; -(function (lib_maybe) { - /** - * @author fenris - */ - function make_nothing() { - return { - "kind": "nothing", - "parameters": {} - }; - } - lib_maybe.make_nothing = make_nothing; - /** - * @author fenris - */ - function make_just(value) { - return { - "kind": "just", - "parameters": { - "value": value - } - }; - } - lib_maybe.make_just = make_just; - /** - * @author fenris - */ - function is_nothing(maybe) { - return (maybe.kind === "nothing"); - } - lib_maybe.is_nothing = is_nothing; - /** - * @author fenris - */ - function is_just(maybe) { - return (maybe.kind === "just"); - } - lib_maybe.is_just = is_just; - /** - * @author fenris - */ - function cull(maybe) { - if (!is_just(maybe)) { - var message = "cull from nothing"; - throw (new Error(message)); - } - else { - var value = maybe.parameters["value"]; - return value; - } - } - lib_maybe.cull = cull; - /** - * @author fenris - */ - function propagate(maybe, function_) { - if (!is_just(maybe)) { - } - else { - var value = maybe.parameters["value"]; - var maybe_ = function_(value); - return maybe_; - } - } - lib_maybe.propagate = propagate; -})(lib_maybe || (lib_maybe = {})); -/** - * @author fenris - */ -/*export*/ var class_maybe = /** @class */ (function () { - function class_maybe() { - } - /** - * @desc whether the wrapper is nothing - * @author fenris - */ - class_maybe.prototype.is_nothing = function () { - throw (new Error("not implemented: class_maybe.is_nothing")); - }; - /** - * @desc whether the wrapper is just - * @author fenris - */ - class_maybe.prototype.is_just = function () { - throw (new Error("not implemented: class_maybe.is_just")); - }; - /** - * @desc return the value, stored in the maybe-wrapper - * @author fenris - */ - class_maybe.prototype.cull = function () { - throw (new Error("not implemented: class_maybe.cull")); - }; - /** - * @author fenris - */ - class_maybe.prototype.toString = function () { - throw (new Error("not implemented: class_maybe.cull")); - }; - /** - * @author fenris - */ - class_maybe.prototype.distinguish = function (action_just, action_nothing) { - if (action_nothing === void 0) { action_nothing = function () { }; } - throw (new Error("not implemented: class_maybe.distinguish")); - }; - /** - * @author fenris - */ - class_maybe.prototype.propagate = function (action) { - throw (new Error("not implemented: class_maybe.propagate")); - }; - /** - * @desc [implementation] - * @author fenris - */ - class_maybe.prototype._show = function () { - return this.toString(); - }; - return class_maybe; -}()); -/** - * @author fenris - */ -/*export*/ var class_nothing = /** @class */ (function (_super) { - __extends(class_nothing, _super); - /** - * @author fenris - */ - function class_nothing(reason) { - if (reason === void 0) { reason = null; } - var _this = _super.call(this) || this; - _this.reason = reason; - return _this; - } - /** - * @author fenris - */ - class_nothing.prototype.is_nothing = function () { - return true; - }; - /** - * @author fenris - */ - class_nothing.prototype.is_just = function () { - return false; - }; - /** - * @author fenris - */ - class_nothing.prototype.cull = function () { - var message = "you shouldn't cull a nothing-value …"; - // lib_plankton.log.warn(message); - return null; - }; - /** - * @author fenris - */ - class_nothing.prototype.toString = function () { - return "<\u00B7>"; - }; - /** - * @author fenris - */ - class_nothing.prototype.reason_get = function () { - var content = ((this.reason == null) ? "·" : this.reason); - return "<- ".concat(content, " ->"); - }; - /** - * @author fenris - */ - class_nothing.prototype.distinguish = function (action_just, action_nothing) { - if (action_nothing === void 0) { action_nothing = function () { }; } - action_nothing(this.reason); - }; - /** - * @author fenris - */ - class_nothing.prototype.propagate = function (action) { - return (new class_nothing(this.reason)); - }; - return class_nothing; -}(class_maybe)); -/** - * @author fenris - */ -/*export*/ var class_just = /** @class */ (function (_super) { - __extends(class_just, _super); - /** - * @author fenris - */ - function class_just(value) { - var _this = _super.call(this) || this; - _this.value = value; - return _this; - } - /** - * @author fenris - */ - class_just.prototype.is_nothing = function () { - return false; - }; - /** - * @author fenris - */ - class_just.prototype.is_just = function () { - return true; - }; - /** - * @author fenris - */ - class_just.prototype.cull = function () { - return this.value; - }; - /** - * @author fenris - */ - class_just.prototype.toString = function () { - var content = instance_show(this.value); - return "<+ ".concat(content, " +>"); - }; - /** - * @author fenris - */ - class_just.prototype.distinguish = function (action_just, action_nothing) { - if (action_nothing === void 0) { action_nothing = function () { }; } - action_just(this.value); - }; - /** - * @author fenris - */ - class_just.prototype.propagate = function (action) { - return action(this.value); - }; - return class_just; -}(class_maybe)); -/* -This file is part of »bacterio-plankton:base«. - -Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:base« 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. - -»bacterio-plankton:base« 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 »bacterio-plankton:base«. If not, see . */ @@ -690,6 +435,148 @@ var lib_plankton; })(base = lib_plankton.base || (lib_plankton.base = {})); })(lib_plankton || (lib_plankton = {})); /* +This file is part of »bacterio-plankton:pod«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:pod« 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. + +»bacterio-plankton:pod« 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 »bacterio-plankton:pod«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var pod; + (function (pod_1) { + /** + * @author fenris + */ + function make_empty() { + return { + "kind": "empty" + }; + } + pod_1.make_empty = make_empty; + /** + * @author fenris + */ + function make_filled(value) { + return { + "kind": "filled", + "value": value + }; + } + pod_1.make_filled = make_filled; + /** + * whether the pod is filled + * + * @author fenris + */ + function is_filled(pod) { + return (pod.kind === "filled"); + } + pod_1.is_filled = is_filled; + /** + * return the value, stored in the pod-wrapper + * + * @author fenris + */ + function cull(pod) { + if (!is_filled(pod)) { + throw (new Error("cull from empty")); + } + else { + return pod.value; + } + } + pod_1.cull = cull; + /** + * to pass on a empty-pod or to use a filled-pod + * + * @author fenris + */ + function propagate(pod, function_) { + if (!is_filled(pod)) { + return make_empty(); + } + else { + return make_filled(function_(pod.value)); + } + } + pod_1.propagate = propagate; + /** + * @author fenris + */ + function distinguish(pod, function_empty, function_filled) { + return ((!is_filled(pod)) + ? function_empty() + : function_filled(pod.value)); + } + pod_1.distinguish = distinguish; + /** + */ + function show(pod, options = {}) { + options = Object.assign({ + "show_value": value => String(value), + }, options); + if (!is_filled(pod)) { + return "<·>"; + } + else { + return ("<- " + options.show_value(pod.value) + " ->"); + } + } + pod_1.show = show; + })(pod = lib_plankton.pod || (lib_plankton.pod = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:pod«. + +Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:pod« 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. + +»bacterio-plankton:pod« 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 »bacterio-plankton:pod«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var pod; + (function (pod) { + /** + */ + class class_pod { + constructor(subject) { this.subject = subject; } + is_empty() { return (!pod.is_filled(this.subject)); } + is_filled() { return pod.is_filled(this.subject); } + cull() { return pod.cull(this.subject); } + show(show_value = undefined) { return pod.show(this.subject, show_value); } + toString() { return this.show(); } + propagate(function_) { return new class_pod(pod.propagate(this.subject, function_)); } + distinguish(function_empty, function_filled) { return pod.distinguish(this.subject, function_empty, function_filled); } + } + pod.class_pod = class_pod; + })(pod = lib_plankton.pod || (lib_plankton.pod = {})); +})(lib_plankton || (lib_plankton = {})); +/* This file is part of »bacterio-plankton:call«. Copyright 2016-2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' @@ -1113,21 +1000,27 @@ var lib_plankton; /** * @author fenris */ - function promise_show(label) { - return (result => promise_make((resolve, reject) => { - // lib_plankton.log.info(label + ": " + instance_show(result)); - process.stdout.write(label + ": " + instance_show(result)); - resolve(result); - })); + /* + export function promise_show(label : string) : (result : type_result)=>type_promise { + return ( + result => promise_make( + (resolve, reject) => { + // lib_plankton.log.info(label + ": " + instance_show(result)); + process.stdout.write(label + ": " + instance_show(result)); + resolve(result); + } + ) + ); } - call.promise_show = promise_show; + */ /** * @author fenris */ - function promise_log(result) { - return promise_show("log"); + /* + export function promise_log(result : type_result) : (result : type_result)=>type_promise { + return promise_show("log"); } - call.promise_log = promise_log; + */ /** * @author fenris */ @@ -1442,16 +1335,16 @@ var lib_plankton; function deferral_compose_parallel({ "left": deferral_left, "right": deferral_right, }) { return (deferral_make((input, convey) => { let object = { - "left": lib_maybe.make_nothing(), - "right": lib_maybe.make_nothing(), + "left": lib_plankton.pod.make_empty(), + "right": lib_plankton.pod.make_empty(), }; let finish = function () { - if (lib_maybe.is_just(object.left) + if (lib_plankton.pod.is_filled(object.left) && - lib_maybe.is_just(object.right)) { + lib_plankton.pod.is_filled(object.right)) { let result = { - "left": lib_maybe.cull(object.left), - "right": lib_maybe.cull(object.right), + "left": lib_plankton.pod.cull(object.left), + "right": lib_plankton.pod.cull(object.right), }; convey(result); } @@ -1460,11 +1353,11 @@ var lib_plankton; } }; deferral_use(deferral_left, input, output_left => { - object.left = lib_maybe.make_just(output_left); + object.left = lib_plankton.pod.make_filled(output_left); finish(); }); deferral_use(deferral_right, input, output_right => { - object.right = lib_maybe.make_just(output_right); + object.right = lib_plankton.pod.make_filled(output_right); finish(); }); })); @@ -2302,14 +2195,14 @@ var lib_plankton; "info": lib_plankton.log.enum_level.info, "notice": lib_plankton.log.enum_level.notice, "warning": lib_plankton.log.enum_level.warning, - "error": lib_plankton.log.enum_level.error + "error": lib_plankton.log.enum_level.error, }[type]), "incident": message, "details": { "prefix": prefix, "level": level, - "indent": indent - } + "indent": indent, + }, }; lib_plankton.log.add(entry); } @@ -2445,7 +2338,7 @@ var lib_plankton; var _this = this; var nm_fs = require("fs"); nm_fs.writeFile(this.path, { - "flag": "a+" + "flag": "a+", }, (("<" + (new Date(Date.now())).toISOString().slice(0, 19) + ">") + " " @@ -2618,7 +2511,7 @@ var lib_plankton; "info": log.enum_level.info, "notice": log.enum_level.notice, "warning": log.enum_level.warning, - "error": log.enum_level.error + "error": log.enum_level.error, }[level_string]; } /** @@ -3185,7 +3078,7 @@ var lib_plankton; } string.replace = replace; /** - * @desc replaces occurences of "${name}" in a string by the corresponding values of an argument object + * @desc replaces occurences of "{{name}}" in a string by the corresponding values of an argument object * @author fenris */ function coin(str, args, options = {}) { @@ -4081,7 +3974,7 @@ var lib_plankton; } return { "keys": keys, - "data": from.map(function (line) { return keys.map(function (name) { return line[name]; }); }) + "data": from.map(function (line) { return keys.map(function (name) { return line[name]; }); }), }; } code.flatten_encode = flatten_encode; @@ -4274,7 +4167,7 @@ var lib_plankton; return (new Promise(function (resolve, reject) { nm_fs.readFile(path, { "encoding": "utf8", - "flag": "r" + "flag": "r", }, function (error, content) { if (error == null) { resolve(content); @@ -4293,7 +4186,7 @@ var lib_plankton; var nm_fs = require("fs"); return (new Promise(function (resolve, reject) { nm_fs.readFile(path, { - "flag": "r" + "flag": "r", }, function (error, content) { if (error == null) { resolve(content); @@ -4330,13 +4223,13 @@ var lib_plankton; function write(path, content, options) { if (options === void 0) { options = {}; } options = Object.assign({ - "encoding": "utf-8" + "encoding": "utf-8", }, options); var nm_fs = require("fs"); return (new Promise(function (resolve, reject) { nm_fs.writeFile(path, content, { "encoding": options.encoding, - "flag": "w" + "flag": "w", }, function (error) { if (error == null) { resolve(undefined); @@ -4357,7 +4250,7 @@ var lib_plankton; var nm_fs = require("fs"); return (new Promise(function (resolve, reject) { nm_fs.writeFile(path, content, { - "flag": "w" + "flag": "w", }, function (error) { if (error == null) { resolve(undefined); @@ -4502,7 +4395,7 @@ var lib_plankton; if (translate._verbosity >= 1) { console.warn(`${_logprefix} no package '${identifier}'`); } - return (new class_nothing()); + return (lib_plankton.pod.make_empty()); } else { // let str : string = lib_plankton.object.path_read(_packages[identifier].tree, path); @@ -4511,7 +4404,7 @@ var lib_plankton; if (translate._verbosity >= 1) { console.warn(`${_logprefix} string '${path}' missing in package '${identifier}'`); } - return (new class_nothing()); + return (lib_plankton.pod.make_empty()); } else { // resolve references @@ -4539,13 +4432,13 @@ var lib_plankton; // fetch referenced string { let result_ = fetch(identifier, path_, args_); - if (result_.is_just()) { + if (lib_plankton.pod.is_filled(result_)) { let front = str.slice(0, matching.index); let back = str.slice(matching.index + matching[0].length); - str = (front + result_.cull() + back); + str = (front + lib_plankton.pod.cull(result_) + back); } else { - return (new class_nothing()); + return (lib_plankton.pod.make_empty()); break; } } @@ -4559,7 +4452,7 @@ var lib_plankton; { str = lib_plankton.string.coin(str, args); } - return (new class_just(str)); + return (lib_plankton.pod.make_filled(str)); } } } @@ -4575,13 +4468,13 @@ var lib_plankton; if (translate._verbosity >= 2) { console.info(`${_logprefix} getting translation for string '${path}' with arguments ${JSON.stringify(args)} …`); } - let result = new class_nothing(); + let result = lib_plankton.pod.make_empty(); let found = _order.some(identifier => { if (translate._verbosity >= 2) { console.info(`${_logprefix} trying package '${identifier}' …`); } let result_ = fetch(identifier, path, args); - if (result_.is_just()) { + if (lib_plankton.pod.is_filled(result_)) { result = result_; return true; } @@ -4590,7 +4483,7 @@ var lib_plankton; } }); if (found) { - let str = result.cull(); + let str = lib_plankton.pod.cull(result); if (translate._verbosity >= 3) { console.info(`${_logprefix} found translation: '${str}'`); } @@ -4862,8 +4755,8 @@ var lib_plankton; "info": info, "hidden": hidden, "parameters": { - "index": index - } + "index": index, + }, })); }; /** @@ -4881,8 +4774,8 @@ var lib_plankton; "hidden": hidden, "parameters": { "indicators_short": indicators_short, - "indicators_long": indicators_long - } + "indicators_long": indicators_long, + }, })); }; /** @@ -5128,17 +5021,17 @@ var lib_plankton; "symbols": { "delimiter": " ", "prefix": "--", - "assignment": "=" - } + "assignment": "=", + }, }, "url": { "symbols": { "delimiter": "&", "prefix": "", - "assignment": "=" + "assignment": "=", } } - } + }, }; /** * @author fenris @@ -5215,14 +5108,14 @@ var lib_plankton; "pattern_from": pattern_from, "pattern_to": pattern_to, "input": input, - "result": result + "result": result, }); input = result; } } } lib_plankton.log.debug("lib_args:read:current_input", { - "input": input + "input": input, }); } // parsing @@ -5233,18 +5126,18 @@ var lib_plankton; var index_expected_1 = 0; parts.forEach(function (part) { lib_plankton.log.debug("lib_args:read:analyzing", { - "part": part + "part": part, }); var found = [ function () { lib_plankton.log.debug("lib_args:read:probing_as_volatile", { - "part": part + "part": part, }); for (var _i = 0, _a = Object.entries(_this.filter(args.enum_kind.volatile)); _i < _a.length; _i++) { var _b = _a[_i], name = _b[0], argument = _b[1]; lib_plankton.log.debug("lib_args:read:probing_as_volatile:trying", { "part": part, - "argument": argument.toString() + "argument": argument.toString(), }); var pattern = ""; { @@ -5263,12 +5156,12 @@ var lib_plankton; pattern += pattern_back; } lib_plankton.log.debug("lib_args:read:probing_as_volatile:pattern", { - "pattern": pattern + "pattern": pattern, }); var regexp = new RegExp(pattern); var matching = regexp.exec(part); lib_plankton.log.debug("lib_args:read:probing_as_volatile:matching", { - "matching": matching + "matching": matching, }); if (matching == null) { // do nothing @@ -5282,7 +5175,7 @@ var lib_plankton; }, function () { lib_plankton.log.debug("lib_args:read:probing_as_positional", { - "part": part + "part": part, }); var positional = _this.filter(args.enum_kind.positional); for (var _i = 0, _a = Object.entries(positional); _i < _a.length; _i++) { @@ -5293,7 +5186,7 @@ var lib_plankton; else { lib_plankton.log.debug("lib_args:read:probing_as_positional:trying", { "part": part, - "argument": argument.toString() + "argument": argument.toString(), }); var pattern = ""; { @@ -5302,12 +5195,12 @@ var lib_plankton; pattern += pattern_back; } lib_plankton.log.debug("lib_args:read:probing_as_positional:pattern", { - "pattern": pattern + "pattern": pattern, }); var regexp = new RegExp(pattern); var matching = regexp.exec(part); lib_plankton.log.debug("lib_args:read:probing_as_positional:matching", { - "matching": matching + "matching": matching, }); if (matching == null) { return false; @@ -5324,7 +5217,7 @@ var lib_plankton; ].some(function (x) { return x(); }); if (!found) { lib_plankton.log.warning("lib_args:read:could_not_parse", { - "part": part + "part": part, }); } }); @@ -5797,7 +5690,10 @@ var lib_plankton; function decode_response(response_raw) { const lines = response_raw.split(linebreak); const first = lines.shift(); - const status_code = parseInt(first.split(" ")[1]); + const first_parts = first.split(" "); + const version = first_parts[0]; + const status_code = parseInt(first_parts[1]); + // first_parts.slice(2) ? probably irrelevant let headers = {}; while (true) { const line = lines.shift(); @@ -5812,7 +5708,7 @@ var lib_plankton; const body = Buffer["from"](lines.join(linebreak)); const response = { // TODO - "version": "HTTP/1.1", + "version": version, "status_code": status_code, "headers": headers, "body": body, @@ -5842,7 +5738,6 @@ var lib_plankton; ((request.query === null) ? "" : request.query)); - console.info({ target }); switch (options.implementation) { default: { return Promise.reject("invalid implementation: " + options.implementation); @@ -5862,6 +5757,7 @@ var lib_plankton; case http.enum_method.head: return "HEAD"; } })(request.method)), + "headers": request.headers, "redirect": (options.follow_redirects ? "follow" : "manual"), "signal": (signal ?? undefined), }) @@ -5872,7 +5768,7 @@ var lib_plankton; .then((response_raw) => (response_raw.text() .then((body) => Promise.resolve({ // TODO - "version": "HTTP/1.1", + "version": null, "status_code": response_raw.status, "headers": ((headers_raw => { let headers = {}; @@ -5931,7 +5827,7 @@ var lib_plankton; res.on("end", () => { resolve({ // TODO - "version": "HTTP/1.1", + "version": null, "status_code": res.statusCode, "headers": res.headers, "body": response_body, diff --git a/source/app/cli.ts b/source/app/cli.ts index cf5f5eb..367210d 100644 --- a/source/app/cli.ts +++ b/source/app/cli.ts @@ -169,6 +169,20 @@ async function main( "info": lib_plankton.translate.get("help.args.time_to_live"), } ), + "working_directory": new lib_plankton.args.class_argument( + { + "name": "working_directory", + "type": lib_plankton.args.enum_type.string, + "kind": lib_plankton.args.enum_kind.volatile, + "mode": lib_plankton.args.enum_mode.replace, + "default": ".", + "parameters": { + "indicators_long": ["working-directory"], + "indicators_short": ["w"], + }, + "info": lib_plankton.translate.get("help.args.working_directory"), + } + ), "verbosity": new lib_plankton.args.class_argument( { "name": "verbosity", @@ -235,9 +249,14 @@ async function main( ) } else { + const order_path : string = ( + args["order_path"].startsWith("/") + ? args["order_path"] + : (args["working_directory"] + "/" + args["order_path"]) + ); const nm_path = require("path"); const nm_fs = require("fs"); - if (! nm_fs.existsSync(args["order_path"])) { + if (! nm_fs.existsSync(order_path)) { lib_plankton.log.error( lib_plankton.translate.get("misc.order_file_not_found"), { @@ -247,7 +266,7 @@ async function main( } else { const order : _heimdall.type_order = await _heimdall.order.load( - nm_path.normalize(args["order_path"]) + nm_path.normalize(order_path) ); if (args["expose_full_order"]) { process.stdout.write(lib_plankton.json.encode(order, true) + "\n"); diff --git a/source/localization/de.json b/source/localization/de.json index 58c8b1a..a2e00e5 100644 --- a/source/localization/de.json +++ b/source/localization/de.json @@ -16,6 +16,7 @@ "help.args.show_schema": "nur das hmdl-JSON-Schema zur Standard-Ausgabe schreiben und beenden", "help.args.expose_full_order": "nur den Pfad zur Datenbank-Datei zur Standard-Ausgabe schreiben und beenden (nützlich für Fehlersuche)", "help.args.show_version": "nur die Version zur Standard-Ausgabe schreiben und beenden", + "help.args.working_directory": "Verzichnis in welchem die Auftrags-Datei zu finden ist, falls mit relativem Pfad angegeben", "help.args.verbosity": "Schwellwert für Log-Ausgaben", "checks.script.execution_failed": "Ausführung gescheitert", "checks.script.invalid_return_code": "ungültiger Rückgabe-Code", diff --git a/source/localization/en.json b/source/localization/en.json index bfa7680..c4e599d 100644 --- a/source/localization/en.json +++ b/source/localization/en.json @@ -16,6 +16,7 @@ "help.args.show_schema": "print the hmdl JSON schema to stdout and exit", "help.args.expose_full_order": "only print the extended order to stdout and exit (useful for debugging)", "help.args.show_version": "only print the version to stdout and exit", + "help.args.working_directory": "directory to loof for the order file, in case its path is specified relatively", "help.args.verbosity": "threshold for log outputs", "checks.script.execution_failed": "execution failed", "checks.script.invalid_return_code": "invalid return code", diff --git a/source/logic/master.ts b/source/logic/master.ts index 8c72919..91d4a60 100644 --- a/source/logic/master.ts +++ b/source/logic/master.ts @@ -116,7 +116,7 @@ namespace _heimdall.master ); lib_plankton.log.info( lib_plankton.translate.get( - "cleanup_info", + "misc.cleanup_info", { "count": count.toFixed(0), } @@ -264,111 +264,110 @@ namespace _heimdall.master "count": count, "last_notification_timestamp": last_notification_timestamp, } - - const timestamp : int = _heimdall.get_current_timestamp(); - const due : boolean = determine_due( - check, - timestamp, - old_item_state + } + const timestamp : int = _heimdall.get_current_timestamp(); + const due : boolean = determine_due( + check, + timestamp, + old_item_state + ); + if (! due) { + // do nothing + } + else { + process.stderr.write( + lib_plankton.string.coin( + "-- {{check_name}}\n", + { + "check_name": check.name, + } + ) ); - if (! due) { + + // execute check and set new state + let result : _heimdall.type_result; + try { + result = await check_kind_implementations[check.kind].run(check.parameters); + } + catch (error) { + result = { + "condition": _heimdall.enum_condition.unknown, + "info": { + "cause": lib_plankton.translate.get("misc.check_procedure_failed"), + "error": error.toString(), + }, + }; + } + const count : (null | int) = ( + ( + (old_item_state === null) + || + (old_item_state.condition !== result.condition) + ) + ? 1 + : ( + ( + (! (old_item_state.count === null)) + && + ((old_item_state.count + 1) <= check.threshold) + ) + ? (old_item_state.count + 1) + : null + ) + ); + const shall_send_notification : boolean = determine_shall_send_notification( + check, + options.send_ok_notifications, + count, + timestamp, + old_item_state, + result + ); + const new_item_state : _heimdall.type_item_state = { + "timestamp": timestamp, + "condition": result.condition, + "count": count, + "last_notification_timestamp": ( + shall_send_notification + ? timestamp + : ( + (old_item_state === null) + ? null + : old_item_state.last_notification_timestamp + ) + ), + } + await _heimdall.state_repository.feed( + check.name, + timestamp, + result.condition, + shall_send_notification, + result.info + ); + + // send notifications + if (! shall_send_notification) { // do nothing } else { - process.stderr.write( - lib_plankton.string.coin( - "-- {{check_name}}\n", - { - "check_name": check.name, - } - ) - ); - - // execute check and set new state - let result : _heimdall.type_result; - try { - result = await check_kind_implementations[check.kind].run(check.parameters); - } - catch (error) { - result = { - "condition": _heimdall.enum_condition.unknown, - "info": { - "cause": lib_plankton.translate.get("misc.check_procedure_failed"), - "error": error.toString(), - }, - }; - } - const count : (null | int) = ( - ( - (old_item_state === null) - || - (old_item_state.condition !== result.condition) - ) - ? 1 - : ( - ( - (! (old_item_state.count === null)) - && - ((old_item_state.count + 1) <= check.threshold) - ) - ? (old_item_state.count + 1) - : null - ) - ); - const shall_send_notification : boolean = determine_shall_send_notification( - check, - options.send_ok_notifications, - count, - timestamp, - old_item_state, - result - ); - const new_item_state : _heimdall.type_item_state = { - "timestamp": timestamp, - "condition": result.condition, - "count": count, - "last_notification_timestamp": ( - shall_send_notification - ? timestamp - : ( - (old_item_state === null) - ? null - : old_item_state.last_notification_timestamp - ) - ), - } - await _heimdall.state_repository.feed( - check.name, - timestamp, - result.condition, - shall_send_notification, - result.info - ); - - // send notifications - if (! shall_send_notification) { - // do nothing - } - else { - check.notifications.forEach( - notification => { - notification_kind_implementations[notification.kind].notify( - notification.parameters, - check.name, - check, - new_item_state, - Object.assign( - ( - (check.custom === null) - ? {} - : {"custom": check.custom} - ), - result.info - ) + check.notifications.forEach( + notification => { + notification_kind_implementations[notification.kind].notify( + notification.parameters, + check.name, + check, + new_item_state, + Object.assign( + ( + (check.custom === null) + ? {} + : {"custom": check.custom} + ), + result.info ) - } - ); - } + ) + } + ); } } } diff --git a/source/test/data.json b/source/test/data.json new file mode 100644 index 0000000..429ee07 --- /dev/null +++ b/source/test/data.json @@ -0,0 +1,666 @@ +{ + "parameters": { + "check": { + "active": true, + "threshold": 1, + "schedule": { + "attentive_interval": 120, + "regular_interval": 3600, + "reminding_interval": 86400 + }, + "notifications": [], + "name": "test", + "title": "Test", + "kind": "BOGUS", + "parameters": {}, + "custom": null, + "annoy": true + }, + "old_item_state": { + "timestamp": "2023-01-15T11:00:00", + "last_notification_timestamp": "2023-01-15T10:00:00" + } + }, + "cases": [ + { + "name": "{\"annoy\":false,\"condition\":\"unknown\",\"threshold_reached\":false,\"passed\":\"none\"}", + "input": { + "annoy": false, + "condition": "unknown", + "threshold_reached": false, + "passed": "none" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"unknown\",\"threshold_reached\":false,\"passed\":\"attentive\"}", + "input": { + "annoy": false, + "condition": "unknown", + "threshold_reached": false, + "passed": "attentive" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"unknown\",\"threshold_reached\":false,\"passed\":\"regular\"}", + "input": { + "annoy": false, + "condition": "unknown", + "threshold_reached": false, + "passed": "regular" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"unknown\",\"threshold_reached\":false,\"passed\":\"reminding\"}", + "input": { + "annoy": false, + "condition": "unknown", + "threshold_reached": false, + "passed": "reminding" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"unknown\",\"threshold_reached\":true,\"passed\":\"none\"}", + "input": { + "annoy": false, + "condition": "unknown", + "threshold_reached": true, + "passed": "none" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"unknown\",\"threshold_reached\":true,\"passed\":\"attentive\"}", + "input": { + "annoy": false, + "condition": "unknown", + "threshold_reached": true, + "passed": "attentive" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"unknown\",\"threshold_reached\":true,\"passed\":\"regular\"}", + "input": { + "annoy": false, + "condition": "unknown", + "threshold_reached": true, + "passed": "regular" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"unknown\",\"threshold_reached\":true,\"passed\":\"reminding\"}", + "input": { + "annoy": false, + "condition": "unknown", + "threshold_reached": true, + "passed": "reminding" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"ok\",\"threshold_reached\":false,\"passed\":\"none\"}", + "input": { + "annoy": false, + "condition": "ok", + "threshold_reached": false, + "passed": "none" + }, + "output": false + }, + { + "name": "{\"annoy\":false,\"condition\":\"ok\",\"threshold_reached\":false,\"passed\":\"attentive\"}", + "input": { + "annoy": false, + "condition": "ok", + "threshold_reached": false, + "passed": "attentive" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"ok\",\"threshold_reached\":false,\"passed\":\"regular\"}", + "input": { + "annoy": false, + "condition": "ok", + "threshold_reached": false, + "passed": "regular" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"ok\",\"threshold_reached\":false,\"passed\":\"reminding\"}", + "input": { + "annoy": false, + "condition": "ok", + "threshold_reached": false, + "passed": "reminding" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"ok\",\"threshold_reached\":true,\"passed\":\"none\"}", + "input": { + "annoy": false, + "condition": "ok", + "threshold_reached": true, + "passed": "none" + }, + "output": false + }, + { + "name": "{\"annoy\":false,\"condition\":\"ok\",\"threshold_reached\":true,\"passed\":\"attentive\"}", + "input": { + "annoy": false, + "condition": "ok", + "threshold_reached": true, + "passed": "attentive" + }, + "output": false + }, + { + "name": "{\"annoy\":false,\"condition\":\"ok\",\"threshold_reached\":true,\"passed\":\"regular\"}", + "input": { + "annoy": false, + "condition": "ok", + "threshold_reached": true, + "passed": "regular" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"ok\",\"threshold_reached\":true,\"passed\":\"reminding\"}", + "input": { + "annoy": false, + "condition": "ok", + "threshold_reached": true, + "passed": "reminding" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"concerning\",\"threshold_reached\":false,\"passed\":\"none\"}", + "input": { + "annoy": false, + "condition": "concerning", + "threshold_reached": false, + "passed": "none" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"concerning\",\"threshold_reached\":false,\"passed\":\"attentive\"}", + "input": { + "annoy": false, + "condition": "concerning", + "threshold_reached": false, + "passed": "attentive" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"concerning\",\"threshold_reached\":false,\"passed\":\"regular\"}", + "input": { + "annoy": false, + "condition": "concerning", + "threshold_reached": false, + "passed": "regular" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"concerning\",\"threshold_reached\":false,\"passed\":\"reminding\"}", + "input": { + "annoy": false, + "condition": "concerning", + "threshold_reached": false, + "passed": "reminding" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"concerning\",\"threshold_reached\":true,\"passed\":\"none\"}", + "input": { + "annoy": false, + "condition": "concerning", + "threshold_reached": true, + "passed": "none" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"concerning\",\"threshold_reached\":true,\"passed\":\"attentive\"}", + "input": { + "annoy": false, + "condition": "concerning", + "threshold_reached": true, + "passed": "attentive" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"concerning\",\"threshold_reached\":true,\"passed\":\"regular\"}", + "input": { + "annoy": false, + "condition": "concerning", + "threshold_reached": true, + "passed": "regular" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"concerning\",\"threshold_reached\":true,\"passed\":\"reminding\"}", + "input": { + "annoy": false, + "condition": "concerning", + "threshold_reached": true, + "passed": "reminding" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"critical\",\"threshold_reached\":false,\"passed\":\"none\"}", + "input": { + "annoy": false, + "condition": "critical", + "threshold_reached": false, + "passed": "none" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"critical\",\"threshold_reached\":false,\"passed\":\"attentive\"}", + "input": { + "annoy": false, + "condition": "critical", + "threshold_reached": false, + "passed": "attentive" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"critical\",\"threshold_reached\":false,\"passed\":\"regular\"}", + "input": { + "annoy": false, + "condition": "critical", + "threshold_reached": false, + "passed": "regular" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"critical\",\"threshold_reached\":false,\"passed\":\"reminding\"}", + "input": { + "annoy": false, + "condition": "critical", + "threshold_reached": false, + "passed": "reminding" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"critical\",\"threshold_reached\":true,\"passed\":\"none\"}", + "input": { + "annoy": false, + "condition": "critical", + "threshold_reached": true, + "passed": "none" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"critical\",\"threshold_reached\":true,\"passed\":\"attentive\"}", + "input": { + "annoy": false, + "condition": "critical", + "threshold_reached": true, + "passed": "attentive" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"critical\",\"threshold_reached\":true,\"passed\":\"regular\"}", + "input": { + "annoy": false, + "condition": "critical", + "threshold_reached": true, + "passed": "regular" + }, + "output": true + }, + { + "name": "{\"annoy\":false,\"condition\":\"critical\",\"threshold_reached\":true,\"passed\":\"reminding\"}", + "input": { + "annoy": false, + "condition": "critical", + "threshold_reached": true, + "passed": "reminding" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"unknown\",\"threshold_reached\":false,\"passed\":\"none\"}", + "input": { + "annoy": true, + "condition": "unknown", + "threshold_reached": false, + "passed": "none" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"unknown\",\"threshold_reached\":false,\"passed\":\"attentive\"}", + "input": { + "annoy": true, + "condition": "unknown", + "threshold_reached": false, + "passed": "attentive" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"unknown\",\"threshold_reached\":false,\"passed\":\"regular\"}", + "input": { + "annoy": true, + "condition": "unknown", + "threshold_reached": false, + "passed": "regular" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"unknown\",\"threshold_reached\":false,\"passed\":\"reminding\"}", + "input": { + "annoy": true, + "condition": "unknown", + "threshold_reached": false, + "passed": "reminding" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"unknown\",\"threshold_reached\":true,\"passed\":\"none\"}", + "input": { + "annoy": true, + "condition": "unknown", + "threshold_reached": true, + "passed": "none" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"unknown\",\"threshold_reached\":true,\"passed\":\"attentive\"}", + "input": { + "annoy": true, + "condition": "unknown", + "threshold_reached": true, + "passed": "attentive" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"unknown\",\"threshold_reached\":true,\"passed\":\"regular\"}", + "input": { + "annoy": true, + "condition": "unknown", + "threshold_reached": true, + "passed": "regular" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"unknown\",\"threshold_reached\":true,\"passed\":\"reminding\"}", + "input": { + "annoy": true, + "condition": "unknown", + "threshold_reached": true, + "passed": "reminding" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"ok\",\"threshold_reached\":false,\"passed\":\"none\"}", + "input": { + "annoy": true, + "condition": "ok", + "threshold_reached": false, + "passed": "none" + }, + "output": false + }, + { + "name": "{\"annoy\":true,\"condition\":\"ok\",\"threshold_reached\":false,\"passed\":\"attentive\"}", + "input": { + "annoy": true, + "condition": "ok", + "threshold_reached": false, + "passed": "attentive" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"ok\",\"threshold_reached\":false,\"passed\":\"regular\"}", + "input": { + "annoy": true, + "condition": "ok", + "threshold_reached": false, + "passed": "regular" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"ok\",\"threshold_reached\":false,\"passed\":\"reminding\"}", + "input": { + "annoy": true, + "condition": "ok", + "threshold_reached": false, + "passed": "reminding" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"ok\",\"threshold_reached\":true,\"passed\":\"none\"}", + "input": { + "annoy": true, + "condition": "ok", + "threshold_reached": true, + "passed": "none" + }, + "output": false + }, + { + "name": "{\"annoy\":true,\"condition\":\"ok\",\"threshold_reached\":true,\"passed\":\"attentive\"}", + "input": { + "annoy": true, + "condition": "ok", + "threshold_reached": true, + "passed": "attentive" + }, + "output": false + }, + { + "name": "{\"annoy\":true,\"condition\":\"ok\",\"threshold_reached\":true,\"passed\":\"regular\"}", + "input": { + "annoy": true, + "condition": "ok", + "threshold_reached": true, + "passed": "regular" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"ok\",\"threshold_reached\":true,\"passed\":\"reminding\"}", + "input": { + "annoy": true, + "condition": "ok", + "threshold_reached": true, + "passed": "reminding" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"concerning\",\"threshold_reached\":false,\"passed\":\"none\"}", + "input": { + "annoy": true, + "condition": "concerning", + "threshold_reached": false, + "passed": "none" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"concerning\",\"threshold_reached\":false,\"passed\":\"attentive\"}", + "input": { + "annoy": true, + "condition": "concerning", + "threshold_reached": false, + "passed": "attentive" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"concerning\",\"threshold_reached\":false,\"passed\":\"regular\"}", + "input": { + "annoy": true, + "condition": "concerning", + "threshold_reached": false, + "passed": "regular" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"concerning\",\"threshold_reached\":false,\"passed\":\"reminding\"}", + "input": { + "annoy": true, + "condition": "concerning", + "threshold_reached": false, + "passed": "reminding" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"concerning\",\"threshold_reached\":true,\"passed\":\"none\"}", + "input": { + "annoy": true, + "condition": "concerning", + "threshold_reached": true, + "passed": "none" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"concerning\",\"threshold_reached\":true,\"passed\":\"attentive\"}", + "input": { + "annoy": true, + "condition": "concerning", + "threshold_reached": true, + "passed": "attentive" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"concerning\",\"threshold_reached\":true,\"passed\":\"regular\"}", + "input": { + "annoy": true, + "condition": "concerning", + "threshold_reached": true, + "passed": "regular" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"concerning\",\"threshold_reached\":true,\"passed\":\"reminding\"}", + "input": { + "annoy": true, + "condition": "concerning", + "threshold_reached": true, + "passed": "reminding" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"critical\",\"threshold_reached\":false,\"passed\":\"none\"}", + "input": { + "annoy": true, + "condition": "critical", + "threshold_reached": false, + "passed": "none" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"critical\",\"threshold_reached\":false,\"passed\":\"attentive\"}", + "input": { + "annoy": true, + "condition": "critical", + "threshold_reached": false, + "passed": "attentive" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"critical\",\"threshold_reached\":false,\"passed\":\"regular\"}", + "input": { + "annoy": true, + "condition": "critical", + "threshold_reached": false, + "passed": "regular" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"critical\",\"threshold_reached\":false,\"passed\":\"reminding\"}", + "input": { + "annoy": true, + "condition": "critical", + "threshold_reached": false, + "passed": "reminding" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"critical\",\"threshold_reached\":true,\"passed\":\"none\"}", + "input": { + "annoy": true, + "condition": "critical", + "threshold_reached": true, + "passed": "none" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"critical\",\"threshold_reached\":true,\"passed\":\"attentive\"}", + "input": { + "annoy": true, + "condition": "critical", + "threshold_reached": true, + "passed": "attentive" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"critical\",\"threshold_reached\":true,\"passed\":\"regular\"}", + "input": { + "annoy": true, + "condition": "critical", + "threshold_reached": true, + "passed": "regular" + }, + "output": true + }, + { + "name": "{\"annoy\":true,\"condition\":\"critical\",\"threshold_reached\":true,\"passed\":\"reminding\"}", + "input": { + "annoy": true, + "condition": "critical", + "threshold_reached": true, + "passed": "reminding" + }, + "output": true + } + ] +} diff --git a/source/test/test.mocha.ts b/source/test/test.mocha.ts index d75c9b7..3d8cda5 100644 --- a/source/test/test.mocha.ts +++ b/source/test/test.mocha.ts @@ -1,4 +1,5 @@ const nm_assert = require("assert"); +const nm_fs = require("fs"); declare var describe; declare var it; @@ -18,125 +19,10 @@ describe( "critical": _heimdall.enum_condition.critical, }[condition_raw]; }; + const data = JSON.parse(nm_fs.readFileSync("./test-data.json")); describe( "master.determine_due", () => { - const dimensions = [ - {"name": "annoy", "elements": [false, true]}, - {"name": "condition", "elements": ["unknown", "ok", "concerning", "critical"]}, - {"name": "treshold_reached", "elements": [false, true]}, - {"name": "passed", "elements": ["none", "attentive", "regular", "reminding"]}, - ]; - const parameters = { - "check": { - "active": true, - "threshold": 1, - "schedule": { - "attentive_interval": 120, - "regular_interval": 3600, - "reminding_interval": 86400, - }, - "notifications": [], - "name": "test", - "title": "Test", - "kind": "BOGUS", - "parameters": {}, - "custom": null, - }, - "old_item_state": { - "timestamp": "2023-01-15T11:00:00", - "last_notification_timestamp": "2023-01-15T10:00:00", - }, - }; - const cases = ( - dimensions - .reduce( - (product, dimension) => ( - product - .map( - tuple => ( - dimension.elements - .map( - element => Object.fromEntries( - Object.entries(tuple) - .concat([[dimension.name, element]]) - ) - ) - ) - ) - .reduce( - ((x, y) => x.concat(y)), - [] - ) - ), - [{}] - ) - .map( - input => ({ - "name": JSON.stringify(input), - "input": input, - // "output": false, - }) - ) - ); - const data = { - "parameters": parameters, - "cases": ( - cases - .map( - case_ => { - // setup - const check : _heimdall.type_check = Object.assign( - parameters["check"], - { - "annoy": case_.input["annoy"], - } - ); - const old_item_state : _heimdall.type_item_state = { - "timestamp": datetimestring_to_timestamp(parameters["old_item_state"]["timestamp"]), - "condition": resolve_condition(case_.input["condition"]), - "count": (case_.input["treshold_reached"] ? null : 0), - "last_notification_timestamp": datetimestring_to_timestamp(parameters["old_item_state"]["last_notification_timestamp"]), - }; - const timestamp : int = ( - datetimestring_to_timestamp( - parameters["old_item_state"]["timestamp"] - ) - + - ( - { - "none": 0, - "attentive": parameters["check"]["schedule"]["attentive_interval"], - "regular": parameters["check"]["schedule"]["regular_interval"], - "reminding": parameters["check"]["schedule"]["reminding_interval"] - }[case_.input["passed"]] - ) - + - 60 - ); -console.info({check,old_item_state,timestamp}); - - // execution - const result : boolean = _heimdall.master.determine_due( - check, - old_item_state, - { - "timestamp": timestamp, - } - ); - - return Object.assign( - case_, - { - "output": result, - } - ); - } - ) - ) - }; -process.stdout.write(JSON.stringify(data, undefined, "\t") + "\n"); - /* data.cases.forEach( case_ => { it( @@ -152,7 +38,7 @@ process.stdout.write(JSON.stringify(data, undefined, "\t") + "\n"); const old_item_state : _heimdall.type_item_state = { "timestamp": datetimestring_to_timestamp(data.parameters["old_item_state"]["timestamp"]), "condition": resolve_condition(case_.input["condition"]), - "count": (case_.input["treshold_reached"] ? null : 0), + "count": (case_.input["threshold_reached"] ? null : 0), "last_notification_timestamp": datetimestring_to_timestamp(data.parameters["old_item_state"]["last_notification_timestamp"]), }; const timestamp : int = ( @@ -171,7 +57,6 @@ process.stdout.write(JSON.stringify(data, undefined, "\t") + "\n"); + 60 ); -console.info({check,old_item_state,timestamp}); // execution const result : boolean = _heimdall.master.determine_due( @@ -188,7 +73,6 @@ console.info({check,old_item_state,timestamp}); ); } ); - */ } ); } diff --git a/tools/build b/tools/build index 6386005..b711cd3 100755 --- a/tools/build +++ b/tools/build @@ -1,25 +1,69 @@ -#!/usr/bin/env sh +#!/usr/bin/env python3 -## vars - -path_prj_core_from=tools/heimdall-core.prj.json -path_prj_core_to=heimdall-core.prj.json -path_prj_app_from=tools/heimdall-app.prj.json -path_prj_app_to=heimdall-app.prj.json -path_prj_test_from=tools/heimdall-test.prj.json -path_prj_test_to=heimdall-test.prj.json +import os as _os +import shutil as _shutil +import argparse as _argparse -## exec +def file_copy( + path_from, + path_to +): + _shutil.copyfile(path_from, path_to) -cp ${path_prj_core_from} ${path_prj_core_to} -cp ${path_prj_app_from} ${path_prj_app_to} -cp ${path_prj_test_from} ${path_prj_test_to} -koralle --execute ${path_prj_app_to} -chmod +r build/heimdall -koralle --execute ${path_prj_test_to} +def file_remove( + path +): + _os.remove(path) -rm ${path_prj_test_to} -rm ${path_prj_app_to} -rm ${path_prj_core_to} + +def shell_execute( + command +): + _os.system(command) + + + +def main( +): + ## args + + argument_parser = _argparse.ArgumentParser() + argument_parser.add_argument( + "-t", + "--include-tests", + action = "store_true" + ) + args = argument_parser.parse_args() + + + ## consts + + path_prj_core_from = "tools/heimdall-core.prj.json" + path_prj_core_to = "heimdall-core.prj.json" + path_prj_app_from = "tools/heimdall-app.prj.json" + path_prj_app_to = "heimdall-app.prj.json" + path_prj_test_from = "tools/heimdall-test.prj.json" + path_prj_test_to = "heimdall-test.prj.json" + + + ## exec + + file_copy(path_prj_core_from, path_prj_core_to) + file_copy(path_prj_app_from, path_prj_app_to) + file_copy(path_prj_test_from, path_prj_test_to) + + shell_execute("koralle --execute %s" % path_prj_app_to) + shell_execute("chmod +r build/heimdall") + if (not args.include_tests): + pass + else: + shell_execute("koralle --execute %s" % path_prj_test_to) + + file_remove(path_prj_test_to) + file_remove(path_prj_app_to) + file_remove(path_prj_core_to) + + +main() diff --git a/tools/heimdall-test.prj.json b/tools/heimdall-test.prj.json index edcffca..de4d3a6 100644 --- a/tools/heimdall-test.prj.json +++ b/tools/heimdall-test.prj.json @@ -4,31 +4,45 @@ "heimdall-core.prj.json" ], "roottask": { - "name": "link", + "name": "all", + "type": "group", "sub": [ { - "name": "compile", - "type": "typescript", + "name": "link", + "sub": [ + { + "name": "compile", + "type": "typescript", + "parameters": { + "inputs": [ + "lib/plankton/plankton.d.ts", + "temp/heimdall-core.d.ts", + "source/test/test.mocha.ts" + ], + "target": "es2020", + "strict": true, + "output": "temp/heimdall-test.mocha.raw.js" + } + } + ], + "type": "concat", "parameters": { "inputs": [ - "lib/plankton/plankton.d.ts", - "temp/heimdall-core.d.ts", - "source/test/test.mocha.ts" + "lib/plankton/plankton.js", + "temp/heimdall-core.js", + "temp/heimdall-test.mocha.raw.js" ], - "target": "es2020", - "strict": true, - "output": "temp/heimdall-test.mocha.raw.js" + "output": "build/heimdall-test.mocha.js" + } + }, + { + "name": "data", + "type": "copy", + "parameters": { + "input": "source/test/data.json", + "output": "build/test-data.json" } } - ], - "type": "concat", - "parameters": { - "inputs": [ - "lib/plankton/plankton.js", - "temp/heimdall-core.js", - "temp/heimdall-test.mocha.raw.js" - ], - "output": "build/heimdall-test.mocha.js" - } + ] } } diff --git a/tools/install b/tools/install index 3609f58..5d5951c 100755 --- a/tools/install +++ b/tools/install @@ -1,8 +1,17 @@ #!/usr/bin/env sh -mkdir -p /usr/local/bin/ -cp build/heimdall /usr/local/bin/heimdall +## args -mkdir -p /usr/local/share/icons/ +if [ $# -ge 1 ] ; then directory=$1 && shift ; else directory="/opt/heimdall" ; fi + + +## exec + +mkdir --parents ${directory} +cp --recursive --update --verbose build/* ${directory}/ + +mkdir --parents /usr/local/bin/ +echo "dir=\$(pwd) && cd ${directory} && ./heimdall --working-directory=\${dir} \$@" > /usr/local/bin/heimdall + +mkdir --parents /usr/local/share/icons/ cp media/icon.png /usr/local/share/icons/heimdall.png -