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> { let shell_exec_result : (null | _heimdall.helpers.misc.type_shell_exec_result); let error : any; try { shell_exec_result = await _heimdall.helpers.misc.shell_exec( parameters["path"], parameters["arguments"], ); error = null; } catch (error_) { shell_exec_result = null; error = error_; } let condition : _heimdall.enum_condition; if ((error !== null) || (shell_exec_result === null)) { lib_plankton.log.notice( lib_plankton.translate.get("checks.script.execution_failed"), { "error": String(error), } ); condition = _heimdall.enum_condition.unknown; } else { switch (shell_exec_result.return_code) { default: { lib_plankton.log.notice( lib_plankton.translate.get("checks.script.invalid_return_code"), { "return_code": shell_exec_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": shell_exec_result, }, }; } /** */ export function check_kind_implementation( ) : type_check_kind { return { "parameters_schema": parameters_schema, "normalize_order_node": normalize_order_node, "run": run, }; } }