[int]
This commit is contained in:
parent
2b6e350e3b
commit
0f6116ddcd
143
source/logic/base.ts
Normal file
143
source/logic/base.ts
Normal file
|
|
@ -0,0 +1,143 @@
|
||||||
|
namespace _heimdall
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
export enum enum_condition {
|
||||||
|
unknown = 0,
|
||||||
|
ok = 1,
|
||||||
|
concerning = 2,
|
||||||
|
critical = 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
export type type_result = {
|
||||||
|
condition : enum_condition;
|
||||||
|
info : any;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
export type type_interval = (
|
||||||
|
null
|
||||||
|
|
|
||||||
|
int
|
||||||
|
|
|
||||||
|
(
|
||||||
|
"minute"
|
||||||
|
|
|
||||||
|
"hour"
|
||||||
|
|
|
||||||
|
"day"
|
||||||
|
|
|
||||||
|
"week"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
export type type_schedule = {
|
||||||
|
regular_interval : type_interval;
|
||||||
|
attentive_interval : type_interval;
|
||||||
|
reminding_interval : type_interval;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
export type type_notification = {
|
||||||
|
kind : string;
|
||||||
|
parameters : any;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
export type type_check_common = {
|
||||||
|
active ?: boolean;
|
||||||
|
threshold ?: int;
|
||||||
|
annoy ?: boolean;
|
||||||
|
schedule ?: type_schedule;
|
||||||
|
notifications ?: Array<type_notification>;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
export type type_check = (
|
||||||
|
type_check_common
|
||||||
|
&
|
||||||
|
{
|
||||||
|
name : string;
|
||||||
|
title : string;
|
||||||
|
kind : string;
|
||||||
|
parameters : any;
|
||||||
|
custom : any;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
export type type_order = {
|
||||||
|
defaults : type_check_common;
|
||||||
|
includes : Array<string>;
|
||||||
|
checks : Array<type_check>;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
export type type_item_state = {
|
||||||
|
timestamp : int;
|
||||||
|
condition : _heimdall.enum_condition,
|
||||||
|
count : (null | int);
|
||||||
|
last_notification_timestamp : (null | int);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* converts a condition to a human readable string
|
||||||
|
*/
|
||||||
|
export function condition_show(
|
||||||
|
condition : enum_condition
|
||||||
|
) : string
|
||||||
|
{
|
||||||
|
return lib_plankton.translate.get(
|
||||||
|
(
|
||||||
|
(condition) => {
|
||||||
|
switch (condition) {
|
||||||
|
case enum_condition.unknown: return "conditions.unknown";
|
||||||
|
case enum_condition.ok: return "conditions.ok";
|
||||||
|
case enum_condition.concerning: return "conditions.concerning";
|
||||||
|
case enum_condition.critical: return "conditions.critical";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) (condition)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
def condition_encode(condition):
|
||||||
|
return {
|
||||||
|
enum_condition.unknown: "unknown",
|
||||||
|
enum_condition.ok: "ok",
|
||||||
|
enum_condition.concerning: "concerning",
|
||||||
|
enum_condition.critical: "critical",
|
||||||
|
}[condition]
|
||||||
|
|
||||||
|
|
||||||
|
def condition_decode(condition_encoded):
|
||||||
|
return {
|
||||||
|
"unknown": enum_condition.unknown,
|
||||||
|
"ok": enum_condition.ok,
|
||||||
|
"warning": enum_condition.concerning, # deprecated
|
||||||
|
"concerning": enum_condition.concerning,
|
||||||
|
"critical": enum_condition.critical,
|
||||||
|
}[condition_encoded]
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
namespace _heimdall
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
export enum enum_condition {
|
|
||||||
unknown = 0,
|
|
||||||
ok = 1,
|
|
||||||
concerning = 2,
|
|
||||||
critical = 3,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
export type type_result = {
|
|
||||||
condition : enum_condition;
|
|
||||||
info : any;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,14 +1,6 @@
|
||||||
async function main(
|
async function main(
|
||||||
) : Promise<void>
|
) : Promise<void>
|
||||||
{
|
{
|
||||||
// types
|
|
||||||
type type_item_state = {
|
|
||||||
timestamp : int;
|
|
||||||
condition : _heimdall.enum_condition,
|
|
||||||
count : (null | int);
|
|
||||||
last_notification_timestamp : (null | int);
|
|
||||||
};
|
|
||||||
|
|
||||||
// consts
|
// consts
|
||||||
const version : string = "0.8";
|
const version : string = "0.8";
|
||||||
|
|
||||||
|
|
@ -214,6 +206,7 @@ async function main(
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind> = {
|
const notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind> = {
|
||||||
|
"console": _heimdall.notification_kinds.console.notification_kind_implementation(),
|
||||||
};
|
};
|
||||||
const check_kind_implementations : Record<string, _heimdall.check_kinds.type_check_kind> = {
|
const check_kind_implementations : Record<string, _heimdall.check_kinds.type_check_kind> = {
|
||||||
"http_request": _heimdall.check_kinds.http_request.check_kind_implementation(),
|
"http_request": _heimdall.check_kinds.http_request.check_kind_implementation(),
|
||||||
|
|
@ -327,7 +320,7 @@ async function main(
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO: type
|
// TODO: type
|
||||||
let old_item_state : (null | type_item_state);
|
let old_item_state : (null | _heimdall.type_item_state);
|
||||||
|
|
||||||
let last_notification_timestamp : (null | int);
|
let last_notification_timestamp : (null | int);
|
||||||
|
|
||||||
|
|
@ -469,7 +462,7 @@ async function main(
|
||||||
args["send_ok_notifications"]
|
args["send_ok_notifications"]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
const new_item_state : type_item_state = {
|
const new_item_state : _heimdall.type_item_state = {
|
||||||
"timestamp": timestamp,
|
"timestamp": timestamp,
|
||||||
"condition": result.condition,
|
"condition": result.condition,
|
||||||
"count": count,
|
"count": count,
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,13 @@ namespace _heimdall.notification_kinds
|
||||||
export type type_notification_kind = {
|
export type type_notification_kind = {
|
||||||
parameters_schema : (() => _heimdall.helpers.json_schema.type_schema);
|
parameters_schema : (() => _heimdall.helpers.json_schema.type_schema);
|
||||||
normalize_order_node : ((node : any) => any);
|
normalize_order_node : ((node : any) => any);
|
||||||
notify : (parameters, name, data, state, info) => Promise<void>;
|
notify : (
|
||||||
|
parameters : any,
|
||||||
|
name : string,
|
||||||
|
data : type_check,
|
||||||
|
state : type_item_state,
|
||||||
|
info : any
|
||||||
|
) => Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
70
source/logic/notification_kinds/console.ts
Normal file
70
source/logic/notification_kinds/console.ts
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
namespace _heimdall.notification_kinds.console
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function parameters_schema(
|
||||||
|
) : _heimdall.helpers.json_schema.type_schema
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function normalize_order_node(
|
||||||
|
node : any
|
||||||
|
) : any
|
||||||
|
{
|
||||||
|
return Object.assign(
|
||||||
|
{
|
||||||
|
},
|
||||||
|
node
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function notify(
|
||||||
|
parameters : any,
|
||||||
|
name : string,
|
||||||
|
check : type_check,
|
||||||
|
state : type_item_state,
|
||||||
|
info : any
|
||||||
|
) : Promise<void>
|
||||||
|
{
|
||||||
|
process.stdout.write(
|
||||||
|
lib_plankton.string.coin(
|
||||||
|
"[{{title}}] <{{condition}}> {{info}}\n",
|
||||||
|
{
|
||||||
|
"title": check.title,
|
||||||
|
"condition": _heimdall.condition_show(state.condition),
|
||||||
|
"info": lib_plankton.json.encode(info, true),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return Promise.resolve<void>(undefined);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
export function notification_kind_implementation(
|
||||||
|
) : type_notification_kind
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
"parameters_schema": parameters_schema,
|
||||||
|
"normalize_order_node": normalize_order_node,
|
||||||
|
"notify": notify,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,77 +1,6 @@
|
||||||
namespace _heimdall.order
|
namespace _heimdall.order
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
type type_interval = (
|
|
||||||
null
|
|
||||||
|
|
|
||||||
int
|
|
||||||
|
|
|
||||||
(
|
|
||||||
"minute"
|
|
||||||
|
|
|
||||||
"hour"
|
|
||||||
|
|
|
||||||
"day"
|
|
||||||
|
|
|
||||||
"week"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
type type_schedule = {
|
|
||||||
regular_interval : type_interval;
|
|
||||||
attentive_interval : type_interval;
|
|
||||||
reminding_interval : type_interval;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
export type type_notification = {
|
|
||||||
kind : string;
|
|
||||||
parameters : any;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
export type type_check_common = {
|
|
||||||
active ?: boolean;
|
|
||||||
threshold ?: int;
|
|
||||||
annoy ?: boolean;
|
|
||||||
schedule ?: type_schedule;
|
|
||||||
notifications ?: Array<type_notification>;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
export type type_check = (
|
|
||||||
type_check_common
|
|
||||||
&
|
|
||||||
{
|
|
||||||
name : string;
|
|
||||||
title : string;
|
|
||||||
kind : string;
|
|
||||||
parameters : any;
|
|
||||||
custom : any;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
export type type_order = {
|
|
||||||
defaults : type_check_common;
|
|
||||||
includes : Array<string>;
|
|
||||||
checks : Array<type_check>;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
function schema_active(
|
function schema_active(
|
||||||
|
|
@ -302,7 +231,7 @@ namespace _heimdall.order
|
||||||
*/
|
*/
|
||||||
function normalize_interval(
|
function normalize_interval(
|
||||||
interval_raw
|
interval_raw
|
||||||
) : (null | type_interval)
|
) : (null | _heimdall.type_interval)
|
||||||
{
|
{
|
||||||
if (interval_raw === null) {
|
if (interval_raw === null) {
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -336,7 +265,7 @@ namespace _heimdall.order
|
||||||
*/
|
*/
|
||||||
function normalize_schedule(
|
function normalize_schedule(
|
||||||
node
|
node
|
||||||
) : type_schedule
|
) : _heimdall.type_schedule
|
||||||
{
|
{
|
||||||
const node_ = Object.assign(
|
const node_ = Object.assign(
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,11 @@
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"inputs": [
|
"inputs": [
|
||||||
"lib/plankton/plankton.d.ts",
|
"lib/plankton/plankton.d.ts",
|
||||||
"source/logic/condition.ts",
|
"source/logic/base.ts",
|
||||||
"source/logic/helpers/json_schema.ts",
|
"source/logic/helpers/json_schema.ts",
|
||||||
"source/logic/helpers/sqlite.ts",
|
"source/logic/helpers/sqlite.ts",
|
||||||
"source/logic/notification_kinds/_abstract.ts",
|
"source/logic/notification_kinds/_abstract.ts",
|
||||||
|
"source/logic/notification_kinds/console.ts",
|
||||||
"source/logic/check_kinds/_abstract.ts",
|
"source/logic/check_kinds/_abstract.ts",
|
||||||
"source/logic/check_kinds/http_request.ts",
|
"source/logic/check_kinds/http_request.ts",
|
||||||
"source/logic/state_repository.ts",
|
"source/logic/state_repository.ts",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue