core/source/logic/checks/generic_remote.py

139 lines
3.2 KiB
Python
Raw Normal View History

class implementation_check_kind_generic_remote(interface_check_kind):
'''
[implementation]
'''
def parameters_schema(self):
return {
"type": "object",
"additionalProperties": False,
"properties": {
2023-03-04 15:19:44 +01:00
"host" : {
"type" : "string"
},
2023-03-03 19:38:04 +01:00
"ssh_port": {
"type": ["null", "integer"],
"default": None
},
2023-03-03 19:38:04 +01:00
"ssh_user" : {
"type" : ["null", "string"],
"default": None,
},
"ssh_key" : {
2023-03-03 19:38:04 +01:00
"type" : ["null", "string"],
"default": None,
},
"mount_point" : {
"type" : "string",
"default" : "/"
},
"threshold" : {
"type" : "integer",
"default" : 95,
"description" : "maximaler Füllstand in Prozent"
},
"strict" : {
"type" : "boolean",
"default" : False
}
},
"required": [
2023-03-04 15:19:44 +01:00
"host"
]
}
'''
[implementation]
'''
def normalize_order_node(self, node):
2023-03-04 15:19:44 +01:00
if (not "host" in node):
raise ValueError("mandatory parameter \"host\" missing")
2023-03-03 19:38:04 +01:00
else:
return dict_merge(
{
"ssh_port": None,
"ssh_user": None,
"ssh_key": None,
"mount_point": "/",
"threshold": 95,
"strict": False,
},
node
)
'''
[implementation]
'''
def run(self, parameters):
2023-03-03 19:38:04 +01:00
inner_command = string_coin(
"df {{mount_point}} | tr -s \" \"",
{
"mount_point": parameters["mount_point"],
}
)
2023-03-03 19:38:04 +01:00
outer_command_parts = []
if True:
outer_command_parts.append("ssh");
if True:
2023-03-04 15:19:44 +01:00
outer_command_parts.append(string_coin("{{host}}", {"host": parameters["host"]}));
2023-03-03 19:38:04 +01:00
if (parameters["ssh_port"] is not None):
outer_command_parts.append(string_coin("-p {{port}}", {"port": ("%u" % parameters["ssh_port"])}));
if (parameters["ssh_user"] is not None):
outer_command_parts.append(string_coin("-l {{user}}", {"user": parameters["ssh_user"]}));
if (parameters["ssh_key"] is not None):
outer_command_parts.append(string_coin("-i {{key}}", {"key": parameters["ssh_key"]}));
if True:
outer_command_parts.append(string_coin("-o BatchMode=yes", {}))
if True:
outer_command_parts.append(string_coin("'{{inner_command}}'", {"inner_command": inner_command}))
outer_command = " ".join(outer_command_parts)
result = shell_command(outer_command)
if (result["return_code"] > 0):
return {
2023-03-03 19:38:04 +01:00
"condition": enum_condition.unknown,
"info": {
"error": result["stderr"],
}
}
else:
2023-03-03 19:38:04 +01:00
stuff = result["stdout"].split("\n")[-2].split(" ")
data = {
"device": stuff[0],
2023-03-04 15:19:44 +01:00
"used": int(stuff[2]),
"avail": int(stuff[3]),
2023-03-03 19:38:04 +01:00
"perc": int(stuff[4][:-1]),
}
faults = []
2023-03-03 19:38:04 +01:00
if (data["perc"] > parameters["threshold"]):
faults.append(translation_get("checks.generic_remote.overflow"))
else:
pass
return {
"condition": (
enum_condition.ok
if (len(faults) <= 0) else
(
enum_condition.critical
if parameters["strict"] else
2023-03-04 16:00:35 +01:00
enum_condition.concerning
)
),
"info": {
"data": {
"host": parameters["host"],
"device": data["device"],
"mount_point": parameters["mount_point"],
"used": format_bytes(data["used"]),
"available": format_bytes(data["avail"]),
"percentage": (str(data["perc"]) + "%"),
},
"faults": faults
}
}
2023-03-03 19:38:04 +01:00