class implementation_check_kind_generic_remote(interface_check_kind): ''' [implementation] ''' def parameters_schema(self): return { "type": "object", "additionalProperties": False, "properties": { "ssh_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": [ "ssh_host" ] } ''' [implementation] ''' def normalize_conf_node(self, node): if (not "ssh_host" in node): raise ValueError("mandatory parameter \"ssh_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["ssh_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": stuff[2], "avail": stuff[3], "perc": int(stuff[4][:-1]), } if (data["perc"] > parameters["threshold"]): return { "condition": ( enum_condition.critical if parameters["strict"] else enum_condition.warning ), "info": { "ssh_host": parameters["ssh_host"], "mount_point": parameters["mount_point"], "device": data["device"], "used": data["used"], # ToDo: Humanlesbarkeit herstellen "available": data["avail"], # ToDo: Humanlesbarkeit herstellen "percentage": (str(data["perc"]) + "%"), "faults": [ translation_get("checks.generic_remote.overflow") ], } } else: return { "condition": enum_condition.ok, "info": {} }