138 lines
3.2 KiB
Python
138 lines
3.2 KiB
Python
class implementation_check_kind_generic_remote(interface_check_kind):
|
|
|
|
'''
|
|
[implementation]
|
|
'''
|
|
def parameters_schema(self):
|
|
return {
|
|
"type": "object",
|
|
"additionalProperties": False,
|
|
"properties": {
|
|
"host" : {
|
|
"type" : "string"
|
|
},
|
|
"ssh_port": {
|
|
"type": ["null", "integer"],
|
|
"default": None
|
|
},
|
|
"ssh_user" : {
|
|
"type" : ["null", "string"],
|
|
"default": None,
|
|
},
|
|
"ssh_key" : {
|
|
"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": [
|
|
"host"
|
|
]
|
|
}
|
|
|
|
|
|
'''
|
|
[implementation]
|
|
'''
|
|
def normalize_conf_node(self, node):
|
|
if (not "host" in node):
|
|
raise ValueError("mandatory parameter \"host\" missing")
|
|
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):
|
|
inner_command = string_coin(
|
|
"df {{mount_point}} | tr -s \" \"",
|
|
{
|
|
"mount_point": parameters["mount_point"],
|
|
}
|
|
)
|
|
|
|
outer_command_parts = []
|
|
if True:
|
|
outer_command_parts.append("ssh");
|
|
if True:
|
|
outer_command_parts.append(string_coin("{{host}}", {"host": parameters["host"]}));
|
|
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 {
|
|
"condition": enum_condition.unknown,
|
|
"info": {
|
|
"error": result["stderr"],
|
|
}
|
|
}
|
|
else:
|
|
stuff = result["stdout"].split("\n")[-2].split(" ")
|
|
data = {
|
|
"device": stuff[0],
|
|
"used": int(stuff[2]),
|
|
"avail": int(stuff[3]),
|
|
"perc": int(stuff[4][:-1]),
|
|
}
|
|
if (data["perc"] > parameters["threshold"]):
|
|
return {
|
|
"condition": (
|
|
enum_condition.critical
|
|
if parameters["strict"] else
|
|
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": [
|
|
translation_get("checks.generic_remote.overflow")
|
|
],
|
|
}
|
|
}
|
|
else:
|
|
return {
|
|
"condition": enum_condition.ok,
|
|
"info": {}
|
|
}
|
|
|