From ccdbe1f0df4936f1c8123283236e2158d1883315 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Fra=C3=9F?= Date: Thu, 31 Aug 2023 19:15:40 +0200 Subject: [PATCH] [fix] various --- source/helpers/misc.ts | 13 +- source/logic/master.ts | 43 ++-- source/logic/order.ts | 8 +- source/test/data.json | 442 ++++---------------------------------- source/test/test.mocha.ts | 71 +++++- tools/install | 2 +- 6 files changed, 147 insertions(+), 432 deletions(-) diff --git a/source/helpers/misc.ts b/source/helpers/misc.ts index 35e0033..0b8aa9c 100644 --- a/source/helpers/misc.ts +++ b/source/helpers/misc.ts @@ -6,10 +6,15 @@ namespace _heimdall.helpers.misc export function get_env_language( ) : (null | string) { - const env_lang : string = process.env["LANG"]; - const locale : string = env_lang.split(".")[0]; - const language : string = locale.split("_")[0]; - return language; + const env_lang : (undefined | string) = process.env["LANG"]; + if (env_lang === undefined) { + return null; + } + else { + const locale : string = env_lang.split(".")[0]; + const language : string = locale.split("_")[0]; + return language; + } } /** diff --git a/source/logic/master.ts b/source/logic/master.ts index 91d4a60..d71dab2 100644 --- a/source/logic/master.ts +++ b/source/logic/master.ts @@ -25,12 +25,12 @@ namespace _heimdall.master ( (old_item_state === null) || - (old_item_state.condition !== _heimdall.enum_condition.ok) - || ((options.timestamp - old_item_state.timestamp) >= check.schedule.regular_interval) || ( - (! (old_item_state.count === null)) + (old_item_state.count !== null) + && + (old_item_state.condition !== _heimdall.enum_condition.ok) && ((options.timestamp - old_item_state.timestamp) >= check.schedule.attentive_interval) ) @@ -42,7 +42,7 @@ namespace _heimdall.master /** * @todo automated tests */ - function determine_shall_send_notification( + export function determine_shall_send_notification( check : _heimdall.type_check, send_ok_notifications : boolean, count : (null | int), @@ -234,42 +234,35 @@ namespace _heimdall.master } > = await _heimdall.state_repository.probe( check.name, - (check.threshold + 1), + (check.threshold + 1) ); if (rows.length <= 0) { old_item_state = null; } else { - let count : int = 1; - rows.slice(1).some( - (row) => { - if (row.condition === rows[0].condition) { - count += 1; - return true; - } - else { - return false; - } + let index : int = 1; + while (index < rows.length) { + if (rows[index].condition === rows[0].condition) { + index += 1; + } + else { + break; } - ); - if (count > check.threshold) { - count = null; - } - else { - // do nothing } old_item_state = { "timestamp": rows[0].timestamp, "condition": rows[0].condition, - "count": count, + "count": ((index < check.threshold) ? index : null), "last_notification_timestamp": last_notification_timestamp, - } + }; } const timestamp : int = _heimdall.get_current_timestamp(); const due : boolean = determine_due( check, - timestamp, - old_item_state + old_item_state, + { + "timestamp": timestamp, + } ); if (! due) { // do nothing diff --git a/source/logic/order.ts b/source/logic/order.ts index 5e1928f..2b17fa2 100644 --- a/source/logic/order.ts +++ b/source/logic/order.ts @@ -375,7 +375,7 @@ namespace _heimdall.order } else { const node_ : type_check = Object.assign( - Object.assign( + lib_plankton.object.patched( defaults, { "title": node.name, @@ -473,19 +473,19 @@ namespace _heimdall.order ("defaults" in node) ? node["defaults"] : {} - ) + ); const defaults : type_check_common = ( options.use_implicit_default_values ? normalize_defaults( defaults_raw ) : defaults_raw - ) + ); const includes : Array = ( ("includes" in node) ? node["includes"] : [] - ) + ); return { "defaults": defaults, "includes": includes, diff --git a/source/test/data.json b/source/test/data.json index 429ee07..8be87e9 100644 --- a/source/test/data.json +++ b/source/test/data.json @@ -14,7 +14,7 @@ "kind": "BOGUS", "parameters": {}, "custom": null, - "annoy": true + "annoy": false }, "old_item_state": { "timestamp": "2023-01-15T11:00:00", @@ -23,19 +23,17 @@ }, "cases": [ { - "name": "{\"annoy\":false,\"condition\":\"unknown\",\"threshold_reached\":false,\"passed\":\"none\"}", + "name": "{\"condition\":\"unknown\",\"threshold_reached\":false,\"passed\":\"none\"}", "input": { - "annoy": false, "condition": "unknown", "threshold_reached": false, "passed": "none" }, - "output": true + "output": false }, { - "name": "{\"annoy\":false,\"condition\":\"unknown\",\"threshold_reached\":false,\"passed\":\"attentive\"}", + "name": "{\"condition\":\"unknown\",\"threshold_reached\":false,\"passed\":\"attentive\"}", "input": { - "annoy": false, "condition": "unknown", "threshold_reached": false, "passed": "attentive" @@ -43,9 +41,8 @@ "output": true }, { - "name": "{\"annoy\":false,\"condition\":\"unknown\",\"threshold_reached\":false,\"passed\":\"regular\"}", + "name": "{\"condition\":\"unknown\",\"threshold_reached\":false,\"passed\":\"regular\"}", "input": { - "annoy": false, "condition": "unknown", "threshold_reached": false, "passed": "regular" @@ -53,9 +50,8 @@ "output": true }, { - "name": "{\"annoy\":false,\"condition\":\"unknown\",\"threshold_reached\":false,\"passed\":\"reminding\"}", + "name": "{\"condition\":\"unknown\",\"threshold_reached\":false,\"passed\":\"reminding\"}", "input": { - "annoy": false, "condition": "unknown", "threshold_reached": false, "passed": "reminding" @@ -63,29 +59,26 @@ "output": true }, { - "name": "{\"annoy\":false,\"condition\":\"unknown\",\"threshold_reached\":true,\"passed\":\"none\"}", + "name": "{\"condition\":\"unknown\",\"threshold_reached\":true,\"passed\":\"none\"}", "input": { - "annoy": false, "condition": "unknown", "threshold_reached": true, "passed": "none" }, - "output": true + "output": false }, { - "name": "{\"annoy\":false,\"condition\":\"unknown\",\"threshold_reached\":true,\"passed\":\"attentive\"}", + "name": "{\"condition\":\"unknown\",\"threshold_reached\":true,\"passed\":\"attentive\"}", "input": { - "annoy": false, "condition": "unknown", "threshold_reached": true, "passed": "attentive" }, - "output": true + "output": false }, { - "name": "{\"annoy\":false,\"condition\":\"unknown\",\"threshold_reached\":true,\"passed\":\"regular\"}", + "name": "{\"condition\":\"unknown\",\"threshold_reached\":true,\"passed\":\"regular\"}", "input": { - "annoy": false, "condition": "unknown", "threshold_reached": true, "passed": "regular" @@ -93,9 +86,8 @@ "output": true }, { - "name": "{\"annoy\":false,\"condition\":\"unknown\",\"threshold_reached\":true,\"passed\":\"reminding\"}", + "name": "{\"condition\":\"unknown\",\"threshold_reached\":true,\"passed\":\"reminding\"}", "input": { - "annoy": false, "condition": "unknown", "threshold_reached": true, "passed": "reminding" @@ -103,9 +95,8 @@ "output": true }, { - "name": "{\"annoy\":false,\"condition\":\"ok\",\"threshold_reached\":false,\"passed\":\"none\"}", + "name": "{\"condition\":\"ok\",\"threshold_reached\":false,\"passed\":\"none\"}", "input": { - "annoy": false, "condition": "ok", "threshold_reached": false, "passed": "none" @@ -113,19 +104,17 @@ "output": false }, { - "name": "{\"annoy\":false,\"condition\":\"ok\",\"threshold_reached\":false,\"passed\":\"attentive\"}", + "name": "{\"condition\":\"ok\",\"threshold_reached\":false,\"passed\":\"attentive\"}", "input": { - "annoy": false, "condition": "ok", "threshold_reached": false, "passed": "attentive" }, - "output": true + "output": false }, { - "name": "{\"annoy\":false,\"condition\":\"ok\",\"threshold_reached\":false,\"passed\":\"regular\"}", + "name": "{\"condition\":\"ok\",\"threshold_reached\":false,\"passed\":\"regular\"}", "input": { - "annoy": false, "condition": "ok", "threshold_reached": false, "passed": "regular" @@ -133,9 +122,8 @@ "output": true }, { - "name": "{\"annoy\":false,\"condition\":\"ok\",\"threshold_reached\":false,\"passed\":\"reminding\"}", + "name": "{\"condition\":\"ok\",\"threshold_reached\":false,\"passed\":\"reminding\"}", "input": { - "annoy": false, "condition": "ok", "threshold_reached": false, "passed": "reminding" @@ -143,9 +131,8 @@ "output": true }, { - "name": "{\"annoy\":false,\"condition\":\"ok\",\"threshold_reached\":true,\"passed\":\"none\"}", + "name": "{\"condition\":\"ok\",\"threshold_reached\":true,\"passed\":\"none\"}", "input": { - "annoy": false, "condition": "ok", "threshold_reached": true, "passed": "none" @@ -153,9 +140,8 @@ "output": false }, { - "name": "{\"annoy\":false,\"condition\":\"ok\",\"threshold_reached\":true,\"passed\":\"attentive\"}", + "name": "{\"condition\":\"ok\",\"threshold_reached\":true,\"passed\":\"attentive\"}", "input": { - "annoy": false, "condition": "ok", "threshold_reached": true, "passed": "attentive" @@ -163,9 +149,8 @@ "output": false }, { - "name": "{\"annoy\":false,\"condition\":\"ok\",\"threshold_reached\":true,\"passed\":\"regular\"}", + "name": "{\"condition\":\"ok\",\"threshold_reached\":true,\"passed\":\"regular\"}", "input": { - "annoy": false, "condition": "ok", "threshold_reached": true, "passed": "regular" @@ -173,9 +158,8 @@ "output": true }, { - "name": "{\"annoy\":false,\"condition\":\"ok\",\"threshold_reached\":true,\"passed\":\"reminding\"}", + "name": "{\"condition\":\"ok\",\"threshold_reached\":true,\"passed\":\"reminding\"}", "input": { - "annoy": false, "condition": "ok", "threshold_reached": true, "passed": "reminding" @@ -183,389 +167,62 @@ "output": true }, { - "name": "{\"annoy\":false,\"condition\":\"concerning\",\"threshold_reached\":false,\"passed\":\"none\"}", + "name": "{\"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\"}", + "name": "{\"condition\":\"concerning\",\"threshold_reached\":false,\"passed\":\"attentive\"}", "input": { - "annoy": true, - "condition": "ok", + "condition": "concerning", "threshold_reached": false, "passed": "attentive" }, "output": true }, { - "name": "{\"annoy\":true,\"condition\":\"ok\",\"threshold_reached\":false,\"passed\":\"regular\"}", + "name": "{\"condition\":\"concerning\",\"threshold_reached\":false,\"passed\":\"regular\"}", "input": { - "annoy": true, - "condition": "ok", + "condition": "concerning", "threshold_reached": false, "passed": "regular" }, "output": true }, { - "name": "{\"annoy\":true,\"condition\":\"ok\",\"threshold_reached\":false,\"passed\":\"reminding\"}", + "name": "{\"condition\":\"concerning\",\"threshold_reached\":false,\"passed\":\"reminding\"}", "input": { - "annoy": true, - "condition": "ok", + "condition": "concerning", "threshold_reached": false, "passed": "reminding" }, "output": true }, { - "name": "{\"annoy\":true,\"condition\":\"ok\",\"threshold_reached\":true,\"passed\":\"none\"}", + "name": "{\"condition\":\"concerning\",\"threshold_reached\":true,\"passed\":\"none\"}", "input": { - "annoy": true, - "condition": "ok", + "condition": "concerning", "threshold_reached": true, "passed": "none" }, "output": false }, { - "name": "{\"annoy\":true,\"condition\":\"ok\",\"threshold_reached\":true,\"passed\":\"attentive\"}", + "name": "{\"condition\":\"concerning\",\"threshold_reached\":true,\"passed\":\"attentive\"}", "input": { - "annoy": true, - "condition": "ok", + "condition": "concerning", "threshold_reached": true, "passed": "attentive" }, "output": false }, { - "name": "{\"annoy\":true,\"condition\":\"ok\",\"threshold_reached\":true,\"passed\":\"regular\"}", + "name": "{\"condition\":\"concerning\",\"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" @@ -573,9 +230,8 @@ "output": true }, { - "name": "{\"annoy\":true,\"condition\":\"concerning\",\"threshold_reached\":true,\"passed\":\"reminding\"}", + "name": "{\"condition\":\"concerning\",\"threshold_reached\":true,\"passed\":\"reminding\"}", "input": { - "annoy": true, "condition": "concerning", "threshold_reached": true, "passed": "reminding" @@ -583,19 +239,17 @@ "output": true }, { - "name": "{\"annoy\":true,\"condition\":\"critical\",\"threshold_reached\":false,\"passed\":\"none\"}", + "name": "{\"condition\":\"critical\",\"threshold_reached\":false,\"passed\":\"none\"}", "input": { - "annoy": true, "condition": "critical", "threshold_reached": false, "passed": "none" }, - "output": true + "output": false }, { - "name": "{\"annoy\":true,\"condition\":\"critical\",\"threshold_reached\":false,\"passed\":\"attentive\"}", + "name": "{\"condition\":\"critical\",\"threshold_reached\":false,\"passed\":\"attentive\"}", "input": { - "annoy": true, "condition": "critical", "threshold_reached": false, "passed": "attentive" @@ -603,9 +257,8 @@ "output": true }, { - "name": "{\"annoy\":true,\"condition\":\"critical\",\"threshold_reached\":false,\"passed\":\"regular\"}", + "name": "{\"condition\":\"critical\",\"threshold_reached\":false,\"passed\":\"regular\"}", "input": { - "annoy": true, "condition": "critical", "threshold_reached": false, "passed": "regular" @@ -613,9 +266,8 @@ "output": true }, { - "name": "{\"annoy\":true,\"condition\":\"critical\",\"threshold_reached\":false,\"passed\":\"reminding\"}", + "name": "{\"condition\":\"critical\",\"threshold_reached\":false,\"passed\":\"reminding\"}", "input": { - "annoy": true, "condition": "critical", "threshold_reached": false, "passed": "reminding" @@ -623,29 +275,26 @@ "output": true }, { - "name": "{\"annoy\":true,\"condition\":\"critical\",\"threshold_reached\":true,\"passed\":\"none\"}", + "name": "{\"condition\":\"critical\",\"threshold_reached\":true,\"passed\":\"none\"}", "input": { - "annoy": true, "condition": "critical", "threshold_reached": true, "passed": "none" }, - "output": true + "output": false }, { - "name": "{\"annoy\":true,\"condition\":\"critical\",\"threshold_reached\":true,\"passed\":\"attentive\"}", + "name": "{\"condition\":\"critical\",\"threshold_reached\":true,\"passed\":\"attentive\"}", "input": { - "annoy": true, "condition": "critical", "threshold_reached": true, "passed": "attentive" }, - "output": true + "output": false }, { - "name": "{\"annoy\":true,\"condition\":\"critical\",\"threshold_reached\":true,\"passed\":\"regular\"}", + "name": "{\"condition\":\"critical\",\"threshold_reached\":true,\"passed\":\"regular\"}", "input": { - "annoy": true, "condition": "critical", "threshold_reached": true, "passed": "regular" @@ -653,9 +302,8 @@ "output": true }, { - "name": "{\"annoy\":true,\"condition\":\"critical\",\"threshold_reached\":true,\"passed\":\"reminding\"}", + "name": "{\"condition\":\"critical\",\"threshold_reached\":true,\"passed\":\"reminding\"}", "input": { - "annoy": true, "condition": "critical", "threshold_reached": true, "passed": "reminding" diff --git a/source/test/test.mocha.ts b/source/test/test.mocha.ts index 3d8cda5..401b6e8 100644 --- a/source/test/test.mocha.ts +++ b/source/test/test.mocha.ts @@ -32,7 +32,7 @@ describe( const check : _heimdall.type_check = Object.assign( data.parameters["check"], { - "annoy": case_.input["annoy"], + "annoy": false, } ); const old_item_state : _heimdall.type_item_state = { @@ -75,5 +75,74 @@ describe( ); } ); + /* + describe( + "master.determine_shall_send_notification", + () => { + it( + "test", + () => { + // setup + const check : _heimdall.type_check = { + "name": "iks.web.2", + "title": "web.2", + "kind": "http_request", + "parameters": { + "request": { + "method": "GET", + "target": "https://iks-sachsen.de" + }, + "timeout": 5, + "follow_redirects": true, + "response": { + "status_code": 200 + }, + "critical": true + }, + "custom": null, + "active": false, + "threshold": 3, + "annoy": false, + "schedule": { + "regular_interval": 60, + "attentive_interval": 10, + "reminding_interval": 86400 + }, + "notifications": [ + { + "kind": "console", + "parameters": { + } + } + ] + }; + const old_item_state : _heimdall.type_item_state = { + "timestamp": 1693493942, + "condition": _heimdall.enum_condition.critical, + "count": 2, + "last_notification_timestamp": 1693493942, + }; + const timestamp : int = 1693495622; + + // execution + const result : boolean = _heimdall.master.determine_shall_send_notification( + check, + false, + 3, + timestamp, + old_item_state, + { + "condition": _heimdall.enum_condition.critical, + "info": {}, + } + ); + + // assertions + nm_assert.equal(result, false); + } + ); + } + ); + */ } ); diff --git a/tools/install b/tools/install index 5d5951c..7f5ed7b 100755 --- a/tools/install +++ b/tools/install @@ -11,7 +11,7 @@ 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 +echo "NODE_PATH=\${NODE_PATH}:${directory} ${directory}/heimdall \$@" > /usr/local/bin/heimdall mkdir --parents /usr/local/share/icons/ cp media/icon.png /usr/local/share/icons/heimdall.png