[add] check_kind:script
This commit is contained in:
parent
c27b23d98b
commit
4f54551517
|
|
@ -25,26 +25,54 @@ namespace _heimdall.check_kinds.file_state
|
||||||
},
|
},
|
||||||
"age_threshold_concerning": {
|
"age_threshold_concerning": {
|
||||||
"description": "in seconds; ignored if 'exist_mode' is set to false",
|
"description": "in seconds; ignored if 'exist_mode' is set to false",
|
||||||
"type": ["null", "integer"],
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"type": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
"exclusiveMinimum": 0,
|
"exclusiveMinimum": 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
"default": null,
|
"default": null,
|
||||||
},
|
},
|
||||||
"age_threshold_critical": {
|
"age_threshold_critical": {
|
||||||
"description": "in seconds; ignored if 'exist_mode' is set to false",
|
"description": "in seconds; ignored if 'exist_mode' is set to false",
|
||||||
"type": ["null", "integer"],
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"type": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
"exclusiveMinimum": 0,
|
"exclusiveMinimum": 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
"default": null,
|
"default": null,
|
||||||
},
|
},
|
||||||
"size_threshold_concerning": {
|
"size_threshold_concerning": {
|
||||||
"description": "in bytes; ignored if 'exist_mode' is set to false",
|
"description": "in bytes; ignored if 'exist_mode' is set to false",
|
||||||
"type": ["null", "integer"],
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"type": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
"exclusiveMinimum": 0,
|
"exclusiveMinimum": 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
"default": null,
|
"default": null,
|
||||||
},
|
},
|
||||||
"size_threshold_critical": {
|
"size_threshold_critical": {
|
||||||
"description": "in bytes; ignored if 'exist_mode' is set to false",
|
"description": "in bytes; ignored if 'exist_mode' is set to false",
|
||||||
"type": ["null", "integer"],
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"type": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
"exclusiveMinimum": 0,
|
"exclusiveMinimum": 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
"default": null,
|
"default": null,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -64,15 +92,29 @@ namespace _heimdall.check_kinds.file_state
|
||||||
"age_threshold": {
|
"age_threshold": {
|
||||||
"deprecated": true,
|
"deprecated": true,
|
||||||
"description": "",
|
"description": "",
|
||||||
"type": ["null", "integer"],
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"type": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
"exclusiveMinimum": 0,
|
"exclusiveMinimum": 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
"default": null,
|
"default": null,
|
||||||
},
|
},
|
||||||
"size_threshold": {
|
"size_threshold": {
|
||||||
"deprecated": true,
|
"deprecated": true,
|
||||||
"description": "",
|
"description": "",
|
||||||
"type": ["null", "integer"],
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"type": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
"exclusiveMinimum": 0,
|
"exclusiveMinimum": 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
"default": null,
|
"default": null,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,14 @@ namespace _heimdall.check_kinds.http_request
|
||||||
"properties": {
|
"properties": {
|
||||||
"status_code": {
|
"status_code": {
|
||||||
"description": "checks whether the response status code is this",
|
"description": "checks whether the response status code is this",
|
||||||
"type": ["null", "integer"],
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"type": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
},
|
||||||
|
],
|
||||||
"default": 200
|
"default": 200
|
||||||
},
|
},
|
||||||
"headers": {
|
"headers": {
|
||||||
|
|
|
||||||
141
source/logic/check_kinds/script.ts
Normal file
141
source/logic/check_kinds/script.ts
Normal file
|
|
@ -0,0 +1,141 @@
|
||||||
|
namespace _heimdall.check_kinds.script
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function parameters_schema(
|
||||||
|
) : _heimdall.helpers.json_schema.type_schema
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"path": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"arguments": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"path",
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
function normalize_order_node(
|
||||||
|
node : any
|
||||||
|
) : any
|
||||||
|
{
|
||||||
|
if (! ("path" in node)) {
|
||||||
|
throw new Error("missing mandatory field 'path'");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const node_ = Object.assign(
|
||||||
|
{
|
||||||
|
"arguments": [],
|
||||||
|
},
|
||||||
|
node
|
||||||
|
);
|
||||||
|
return node_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
async function run(
|
||||||
|
parameters
|
||||||
|
) : Promise<_heimdall.type_result>
|
||||||
|
{
|
||||||
|
const nm_child_process = require("child_process");
|
||||||
|
|
||||||
|
type type_result = {
|
||||||
|
return_code : int;
|
||||||
|
stdout : string;
|
||||||
|
stderr : string;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* @see https://nodejs.org/api/child_process.html#child_processspawncommand-args-options
|
||||||
|
*/
|
||||||
|
const result : type_result = await new Promise<type_result>(
|
||||||
|
(resolve, reject) => {
|
||||||
|
nm_child_process.spawnSync(
|
||||||
|
parameters["path"],
|
||||||
|
parameters["arguments"],
|
||||||
|
{
|
||||||
|
},
|
||||||
|
(result) => {
|
||||||
|
if (result.error) {
|
||||||
|
reject(result.error);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
resolve(
|
||||||
|
{
|
||||||
|
"return_code": result.status,
|
||||||
|
"stdout": result.stdout,
|
||||||
|
"stderr": result.stdin,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
let condition : _heimdall.enum_condition;
|
||||||
|
switch (result.return_code) {
|
||||||
|
default: {
|
||||||
|
lib_plankton.log.notice(
|
||||||
|
lib_plankton.translate.get("check_kind_script_invalid_return_code"),
|
||||||
|
{
|
||||||
|
"return_code": result.return_code,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
condition = _heimdall.enum_condition.unknown;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 0: {
|
||||||
|
condition = _heimdall.enum_condition.ok;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 1: {
|
||||||
|
condition = _heimdall.enum_condition.unknown;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 2: {
|
||||||
|
condition = _heimdall.enum_condition.concerning;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 3: {
|
||||||
|
condition = _heimdall.enum_condition.critical;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
"condition": condition,
|
||||||
|
"info": {
|
||||||
|
"result": result,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
export function check_kind_implementation(
|
||||||
|
) : type_check_kind
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
"parameters_schema": parameters_schema,
|
||||||
|
"normalize_order_node": normalize_order_node,
|
||||||
|
"run": run,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,7 @@ namespace _heimdall.helpers.json_schema
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
type type_name = (
|
type type_name = (
|
||||||
"null"
|
"null"
|
||||||
|
|
|
|
||||||
|
|
@ -18,6 +19,7 @@ namespace _heimdall.helpers.json_schema
|
||||||
|
|
|
|
||||||
"object"
|
"object"
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -88,16 +90,12 @@ namespace _heimdall.helpers.json_schema
|
||||||
}
|
}
|
||||||
|
|
|
|
||||||
{
|
{
|
||||||
type ?: "array";
|
type : "array";
|
||||||
items ?: type_schema;
|
items ?: type_schema;
|
||||||
default ?: Array<any>;
|
default ?: Array<any>;
|
||||||
enum ?: Array<Array<any>>;
|
enum ?: Array<Array<any>>;
|
||||||
}
|
}
|
||||||
|
|
|
|
||||||
{
|
|
||||||
type ?: Array<type_name>;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
{
|
{
|
||||||
anyOf ?: Array<type_schema>;
|
anyOf ?: Array<type_schema>;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -245,6 +245,7 @@ async function main(
|
||||||
"console": _heimdall.notification_kinds.console.notification_kind_implementation(),
|
"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> = {
|
||||||
|
"script": _heimdall.check_kinds.script.check_kind_implementation(),
|
||||||
"http_request": _heimdall.check_kinds.http_request.check_kind_implementation(),
|
"http_request": _heimdall.check_kinds.http_request.check_kind_implementation(),
|
||||||
"file_state": _heimdall.check_kinds.file_state.check_kind_implementation(),
|
"file_state": _heimdall.check_kinds.file_state.check_kind_implementation(),
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -49,10 +49,22 @@ namespace _heimdall.order
|
||||||
) : _heimdall.helpers.json_schema.type_schema
|
) : _heimdall.helpers.json_schema.type_schema
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
"anyOf": [
|
"anyOf": (
|
||||||
|
[]
|
||||||
|
.concat(
|
||||||
|
allow_null
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
"type": "null",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
: []
|
||||||
|
)
|
||||||
|
.concat(
|
||||||
|
[
|
||||||
{
|
{
|
||||||
"description": "in seconds",
|
"description": "in seconds",
|
||||||
"type": (allow_null ? "integer" : ["null", "integer"]),
|
"type": "integer",
|
||||||
"exclusiveMinimum": 0,
|
"exclusiveMinimum": 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -65,7 +77,9 @@ namespace _heimdall.order
|
||||||
"week",
|
"week",
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
],
|
]
|
||||||
|
)
|
||||||
|
),
|
||||||
"default": default_,
|
"default": default_,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@
|
||||||
"source/logic/notification_kinds/_abstract.ts",
|
"source/logic/notification_kinds/_abstract.ts",
|
||||||
"source/logic/notification_kinds/console.ts",
|
"source/logic/notification_kinds/console.ts",
|
||||||
"source/logic/check_kinds/_abstract.ts",
|
"source/logic/check_kinds/_abstract.ts",
|
||||||
|
"source/logic/check_kinds/script.ts",
|
||||||
"source/logic/check_kinds/http_request.ts",
|
"source/logic/check_kinds/http_request.ts",
|
||||||
"source/logic/check_kinds/file_state.ts",
|
"source/logic/check_kinds/file_state.ts",
|
||||||
"source/logic/state_repository.ts",
|
"source/logic/state_repository.ts",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue