diff --git a/source/logic/checks/generic_remote.py b/source/logic/checks/generic_remote.py new file mode 100644 index 0000000..b92b35b --- /dev/null +++ b/source/logic/checks/generic_remote.py @@ -0,0 +1,105 @@ +class implementation_check_kind_generic_remote(interface_check_kind): + + ''' + [implementation] + ''' + def parameters_schema(self): + return { + "type": "object", + "additionalProperties": False, + "properties": { + "host" : { + "type" : "string" + }, + "user" : { + "type" : "string" + }, + "ssh_key" : { + "type" : "string" + }, + "mount_point" : { + "type" : "string", + "default" : "/" + }, + "threshold" : { + "type" : "integer", + "default" : 95, + "description" : "maximaler Füllstand in Prozent" + }, + "strict" : { + "type" : "boolean", + "default" : False + } + }, + "required": [ + "host", "user", "ssh_key" + ] + } + + + ''' + [implementation] + ''' + def normalize_conf_node(self, node): + if not "host" in node \ + or not "user" in node \ + or not "ssh_key" in node: + raise ValueError("MISSING STUFF!") + if not "mount_point" in node: + node["mount_point"] = "/" + if not "threshold" in node: + node["threshold"] = 95 + if not "strict" in node: + node["strict"] = "/" + + return node + + ''' + [implementation] + ''' + def run(self, parameters): + SSH_COMMAND=string_coin("ssh -i {{ssh_key}} {{user}}@{{host}} \"df {{mount_point}} | tr -s ' '\"", parameters) + + retval=shell_command(SSH_COMMAND) + + if retval["return_code"] > 0: + return { + "condition" : enum_condition.unknown, + "info" : { + "error" : retval["stderr"] + } + } + else: + parts=retval["stdout"].split("\n")[-1].split(" ") + ret={ + "device" : parts[0], + "used" : parts[2], + "avail" : parts[3], + "perc" : int(parts[4][:-1]) + } + + if ret["perc"] > parameters["threshold"]: + return { + "condition": ( + enum_condition.critical + if parameters["strict"] else + enum_condition.warning + ), + "info": { + "mount_point": parameters["mount_point"], + "device": ret["device"], + "used": ret["used"], # ToDo: Humanlesbarkeit herstellen + "available": ret["avail"], # ToDo: Humanlesbarkeit herstellen + "percentage": str(ret["perc"]) + "%", + "host" : parameters["host"], + "faults": [ + translation_get("checks.generic_remote.overflow") + ] + } + } + + else: + return { + "condition": enum_condition.ok, + "info" : {} + }