2024-07-02 15:02:35 +02:00
|
|
|
/*
|
|
|
|
|
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
|
|
|
|
|
<info@greenscale.de>
|
|
|
|
|
|
|
|
|
|
»heimdall« is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
»heimdall« 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 General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with »heimdall«. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2023-07-27 17:37:45 +02:00
|
|
|
/**
|
|
|
|
|
* @todo outsource
|
|
|
|
|
*/
|
|
|
|
|
declare var __dirname;
|
|
|
|
|
|
|
|
|
|
|
2023-06-19 18:40:13 +02:00
|
|
|
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
|
2023-06-23 12:16:44 +02:00
|
|
|
/*
|
2023-06-19 18:40:13 +02:00
|
|
|
|
|
|
|
|
|
(
|
|
|
|
|
"minute"
|
|
|
|
|
|
|
|
|
|
|
"hour"
|
|
|
|
|
|
|
|
|
|
|
"day"
|
|
|
|
|
|
|
|
|
|
|
"week"
|
|
|
|
|
)
|
2023-06-23 12:16:44 +02:00
|
|
|
*/
|
2023-06-19 18:40:13 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
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);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2023-07-06 15:09:34 +02:00
|
|
|
/**
|
|
|
|
|
*/
|
|
|
|
|
export function get_current_timestamp(
|
|
|
|
|
) : int
|
|
|
|
|
{
|
|
|
|
|
return Math.floor(Date.now() / 1000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-06-19 18:40:13 +02:00
|
|
|
/**
|
|
|
|
|
* 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]
|
|
|
|
|
*/
|
|
|
|
|
}
|