core/source/logic/checks/script.py

62 lines
1.1 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_conf_node(self, node):
return dict_merge(
{
},
node
)
'''
[implementation]
'''
2022-11-30 08:15:35 +01:00
def run(self, parameters):
2023-03-03 14:13:08 +01:00
result = shell_command([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:13:08 +01:00
elif (result.return_code == 1):
2022-11-29 23:53:14 +01:00
condition = enum_condition.unknown
2023-03-03 14:13:08 +01:00
elif (result.return_code == 2):
2022-11-29 23:53:14 +01:00
condition = enum_condition.warning
2023-03-03 14:13:08 +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:13:08 +01:00
"stdout": result.stdout,
"stderr": result.stderr,
},
2022-11-29 23:53:14 +01:00
}