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" }, "critical": { "description": "whether a violation of this check shall be leveled as critical instead of concerning", "type": "boolean", "default": True }, "strict": { "deprecated": True, "description": "alias for 'critical'", "type": "boolean", "default": True }, }, "required": [ "host", ] } ''' [implementation] ''' def normalize_order_node(self, node): version = ( "v1" if (not ("critical" in node)) else "v2" ) if (version == "v1"): if (not "host" in node): raise ValueError("mandatory parameter \"host\" missing") else: node_ = dict_merge( { "ssh_port": None, "ssh_user": None, "ssh_key": None, "mount_point": "/", "threshold": 95, "strict": False, }, node ) return { "ssh_port": node_["ssh_port"], "ssh_user": node_["ssh_user"], "ssh_key": node_["ssh_key"], "mount_point": node_["ssh_path"], "threshold": node_["ssh_threshold"], "critical": node_["strict"], } elif (version == "v2"): if (not "host" in node): raise ValueError("mandatory parameter \"host\" missing") else: node_ = dict_merge( { "ssh_port": None, "ssh_user": None, "ssh_key": None, "mount_point": "/", "threshold": 95, "critical": False, }, node ) return node_ else: raise ValueError("unhandled") ''' [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]), } faults = [] 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 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 } }