diff --git a/source/logic/base.ts b/source/logic/base.ts index d3d2573..5978791 100644 --- a/source/logic/base.ts +++ b/source/logic/base.ts @@ -25,6 +25,7 @@ namespace _heimdall null | int + /* | ( "minute" @@ -35,6 +36,7 @@ namespace _heimdall | "week" ) + */ ); diff --git a/source/logic/check_kinds/file_state.ts b/source/logic/check_kinds/file_state.ts new file mode 100644 index 0000000..a3c6f2f --- /dev/null +++ b/source/logic/check_kinds/file_state.ts @@ -0,0 +1,190 @@ +namespace _heimdall.check_kinds.file_state +{ + + /** + */ + function parameters_schema( + ) : _heimdall.helpers.json_schema.type_schema + { + return { + "type": "object", + "additionalProperties": false, + "properties": { + "path": { + "type": "string" + }, + "exist_mode": { + "description": "whether the file is supposed to exist or not", + "type": "boolean", + "default": true, + }, + "exist_critical": { + "description": "whether a violation of the extist state (parameter 'exist_mode') shall be considered as critical (true) or concerning (false)", + "type": "boolean", + "default": true, + }, + "age_threshold_concerning": { + "description": "in seconds; ignored if 'exist_mode' is set to false", + "type": ["null", "integer"], + "exclusiveMinimum": 0, + "default": null, + }, + "age_threshold_critical": { + "description": "in seconds; ignored if 'exist_mode' is set to false", + "type": ["null", "integer"], + "exclusiveMinimum": 0, + "default": null, + }, + "size_threshold_concerning": { + "description": "in bytes; ignored if 'exist_mode' is set to false", + "type": ["null", "integer"], + "exclusiveMinimum": 0, + "default": null, + }, + "size_threshold_critical": { + "description": "in bytes; ignored if 'exist_mode' is set to false", + "type": ["null", "integer"], + "exclusiveMinimum": 0, + "default": null, + }, + + // deprecated + "strict": { + "deprecated": true, + "description": "", + "type": "boolean", + "default": true, + }, + "exist": { + "deprecated": true, + "description": "", + "type": "boolean", + "default": true, + }, + "age_threshold": { + "deprecated": true, + "description": "", + "type": ["null", "integer"], + "exclusiveMinimum": 0, + "default": null, + }, + "size_threshold": { + "deprecated": true, + "description": "", + "type": ["null", "integer"], + "exclusiveMinimum": 0, + "default": null, + }, + }, + "required": [ + "path", + ] + }; + } + + + /** + */ + function normalize_order_node( + node : any + ) : any + { + const version : string = ( + (! ("exist_mode" in node) + ? "v1" + : "v2" + ); + + switch (version) { + default: { + throw (new Error("unhandled version")); + break; + } + case "v1": { + if (! ("path" in node)) { + throw new Error("missing mandatory field 'path'"); + } + else { + const node_ = Object.assign( + { + "strict": true, + "exist": true, + "age_threshold": null, + "size_threshold": null, + }, + node + ); + return { + "exist_mode": node_["exist"], + "exist_critical": node_["strict"], + "age_threshold_concerning": ( + node_["strict"] + ? null + : node_["age_threshold"] + ), + "age_threshold_critical": ( + node_["strict"] + ? node_["age_threshold"] + : null + ), + "size_threshold_concerning": ( + node_["strict"] + ? null + : node_["age_threshold"] + ), + "size_threshold_critical": ( + node_["strict"] + ? node_["age_threshold"] + : null + ), + }; + } + break; + } + case "v2": { + if (! ("path" in node)) { + throw new Error("missing mandatory field 'path'"); + } + else { + const node_ = Object.assign( + { + "exist_mode": true, + "exist_critical": true, + "age_threshold_concerning": null, + "age_threshold_critical": null, + "size_threshold_concerning": null, + "size_threshold_critical": null, + }, + node + ); + return node_; + } + break; + } + } + } + + + /** + */ + async function run( + parameters + ) : Promise<_heimdall.type_result> + { + return Promise.reject<_heimdall.type_result>(new Error("not implemented")); + } + + + /** + */ + export function check_kind_implementation( + ) : type_check_kind + { + return { + "parameters_schema": parameters_schema, + "normalize_order_node": normalize_order_node, + "run": run, + }; + } + +}