#### # Returns module in XML format. Accepts only {dict} ######################################################################################### def print_module( module: dict = None, print_flag: bool = False ) -> str: """ Returns module in XML format. Accepts only {dict}. - Only works with one module at a time: otherwise iteration is needed. - Module "value" field accepts str type or [list] for datalists. - Use print_flag to show modules' XML in STDOUT. """ module_xml = "" if module is not None: data = dict(module) module_xml = ("\n" "\t\n" "\t" + str(data["type"]) + "\n" ) if type(data["type"]) is not str and "string" not in data["type"]: #### Strip spaces if module not generic_data_string data["value"] = data["value"].strip() if isinstance(data["value"], list): # Checks if value is a list module_xml += "\t\n" for value in data["value"]: if type(value) is dict and "value" in value: module_xml += "\t\n" module_xml += "\t\t\n" if "timestamp" in value: module_xml += "\t\t\n" module_xml += "\t\n" module_xml += "\t\n" else: module_xml += "\t\n" if "desc" in data: module_xml += "\t\n" if "unit" in data: module_xml += "\t\n" if "interval" in data: module_xml += "\t\n" if "tags" in data: module_xml += "\t" + str(data["tags"]) + "\n" if "module_group" in data: module_xml += "\t" + str(data["module_group"]) + "\n" if "module_parent" in data: module_xml += "\t" + str(data["module_parent"]) + "\n" if "min_warning" in data: module_xml += "\t\n" if "min_warning_forced" in data: module_xml += "\t\n" if "max_warning" in data: module_xml += "\t\n" if "max_warning_forced" in data: module_xml += "\t\n" if "min_critical" in data: module_xml += "\t\n" if "min_critical_forced" in data: module_xml += "\t\n" if "max_critical" in data: module_xml += "\t\n" if "max_critical_forced" in data: module_xml += "\t\n" if "str_warning" in data: module_xml += "\t\n" if "str_warning_forced" in data: module_xml += "\t\n" if "str_critical" in data: module_xml += "\t\n" if "str_critical_forced" in data: module_xml += "\t\n" if "critical_inverse" in data: module_xml += "\t\n" if "warning_inverse" in data: module_xml += "\t\n" if "max" in data: module_xml += "\t\n" if "min" in data: module_xml += "\t\n" if "post_process" in data: module_xml += "\t\n" if "disabled" in data: module_xml += "\t\n" if "min_ff_event" in data: module_xml += "\t\n" if "status" in data: module_xml += "\t\n" if "timestamp" in data: module_xml += "\t\n" if "custom_id" in data: module_xml += "\t\n" if "critical_instructions" in data: module_xml += "\t\n" if "warning_instructions" in data: module_xml += "\t\n" if "unknown_instructions" in data: module_xml += "\t\n" if "quiet" in data: module_xml += "\t\n" if "module_ff_interval" in data: module_xml += "\t\n" if "crontab" in data: module_xml += "\t\n" if "min_ff_event_normal" in data: module_xml += "\t\n" if "min_ff_event_warning" in data: module_xml += "\t\n" if "min_ff_event_critical" in data: module_xml += "\t\n" if "ff_type" in data: module_xml += "\t\n" if "ff_timeout" in data: module_xml += "\t\n" if "each_ff" in data: module_xml += "\t\n" if "module_parent_unlink" in data: module_xml += "\t\n" if "alert" in data: for alert in data["alert"]: module_xml += "\t\n" module_xml += "\n" if print_flag: print(module_xml) return module_xml #### # Returns log module in XML format. Accepts only {dict} ######################################################################################### def print_log_module( module: dict = None, print_flag: bool = False ) -> str: """ Returns log module in XML format. Accepts only {dict}. - Only works with one module at a time: otherwise iteration is needed. - Module "value" field accepts str type. - Use not_print_flag to avoid printing the XML (only populates variables). """ module_xml = "" if module is not None: data = dict(module) module_xml = ("\n" "\t\n" "\t\"" + str(data["value"]) + "\"\n" ) module_xml += "\n" if print_flag: print(module_xml) return module_xml