core/source/logic/checks/script.py

64 lines
1.2 KiB
Python
Raw Normal View History

2022-11-29 23:53:14 +01:00
class implementation_check_kind_script(interface_check_kind):
'''
[implementation]
'''
def parameters_schema(self):
return {
"type": "object",
"additionalProperties": False,
"properties": {
"path": {
"type": "string"
},
"arguments": {
"type": "array",
"item": {
"type": "string"
}
},
},
"required": [
"path",
]
}
2022-11-29 23:53:14 +01:00
'''
[implementation]
'''
def normalize_order_node(self, node):
2022-11-29 23:53:14 +01:00
return dict_merge(
{
},
node
)
'''
[implementation]
'''
2022-11-30 08:15:35 +01:00
def run(self, parameters):
2023-03-03 14:56:06 +01:00
result = shell_command(
" ".join([parameters["path"]] + parameters["arguments"])
)
if (result["return_code"] == 0):
2022-11-29 23:53:14 +01:00
condition = enum_condition.ok
2023-03-03 14:56:06 +01:00
elif (result["return_code"] == 1):
2022-11-29 23:53:14 +01:00
condition = enum_condition.unknown
2023-03-03 14:56:06 +01:00
elif (result["return_code"] == 2):
2023-03-04 16:00:35 +01:00
condition = enum_condition.concerning
2023-03-03 14:56:06 +01:00
elif (result["return_code"] == 3):
2022-11-29 23:53:14 +01:00
condition = enum_condition.critical
else:
# raise ValueError("invalid exit code: %i" % result.returncode)
condition = enum_condition.unknown
2022-11-29 23:53:14 +01:00
return {
"condition": condition,
"info": {
2023-03-03 14:56:06 +01:00
"stdout": result["stdout"],
"stderr": result["stderr"],
},
2022-11-29 23:53:14 +01:00
}