def test_save_autochecks_file(items, expected_content): autochecks.save_autochecks_file("host", items) autochecks_file = Path(cmk.utils.paths.autochecks_dir, "host.mk") with autochecks_file.open("r", encoding="utf-8") as f: # pylint: disable=no-member content = f.read() assert expected_content == content
def test_save_autochecks_file(items, expected_content): autochecks.save_autochecks_file(HostName("host"), items) autochecks_file = Path(cmk.utils.paths.autochecks_dir, "host.mk") with autochecks_file.open("r", encoding="utf-8") as f: content = f.read() assert expected_content == content
def _commandline_discovery_on_host( host_name: HostName, ipaddress: Optional[HostAddress], parsed_sections_broker: ParsedSectionsBroker, run_plugin_names: Container[CheckPluginName], only_new: bool, *, load_labels: bool, only_host_labels: bool, on_error: OnError, ) -> None: section.section_step("Analyse discovered host labels") host_labels = analyse_node_labels( host_name=host_name, ipaddress=ipaddress, parsed_sections_broker=parsed_sections_broker, load_labels=load_labels, save_labels=True, on_error=on_error, ) count = len(host_labels.new) if host_labels.new else ( "no new" if only_new else "no") section.section_success(f"Found {count} host labels") if only_host_labels: return section.section_step("Analyse discovered services") service_result = analyse_discovered_services( host_name=host_name, ipaddress=ipaddress, parsed_sections_broker=parsed_sections_broker, run_plugin_names=run_plugin_names, only_new=only_new, on_error=on_error, ) # TODO (mo): for the labels the corresponding code is in _host_labels. # We should put the persisting in one place. autochecks.save_autochecks_file(host_name, service_result.present) new_per_plugin = Counter(s.check_plugin_name for s in service_result.new) for name, count in sorted(new_per_plugin.items()): console.verbose("%s%3d%s %s\n" % (tty.green + tty.bold, count, tty.normal, name)) count = len(service_result.new) if service_result.new else ( "no new" if only_new else "no") section.section_success(f"Found {count} services") for detail in check_parsing_errors( parsed_sections_broker.parsing_errors()).details: console.warning(detail)
def test_save_autochecks_file(items, expected_content_py2, expected_content_py3): autochecks.save_autochecks_file("host", items) autochecks_file = Path(cmk.utils.paths.autochecks_dir, "host.mk") with autochecks_file.open("r", encoding="utf-8") as f: # pylint: disable=no-member content = f.read() expected_content = expected_content_py3 if sys.version_info[ 0] >= 3 else expected_content_py2 assert expected_content == content
def _do_discovery_for( host_name: HostName, ipaddress: Optional[HostAddress], parsed_sections_broker: ParsedSectionsBroker, run_plugin_names: Container[CheckPluginName], only_new: bool, discovery_parameters: DiscoveryParameters, ) -> None: host_labels = analyse_host_labels( host_name=host_name, ipaddress=ipaddress, parsed_sections_broker=parsed_sections_broker, discovery_parameters=discovery_parameters, ) service_result = analyse_discovered_services( host_name=host_name, ipaddress=ipaddress, parsed_sections_broker=parsed_sections_broker, discovery_parameters=discovery_parameters, run_plugin_names=run_plugin_names, only_new=only_new, ) # TODO (mo): for the labels the corresponding code is in _host_labels. # We should put the persisting and logging in one place. autochecks.save_autochecks_file(host_name, service_result.present) new_per_plugin = Counter(s.check_plugin_name for s in service_result.new) for name, count in sorted(new_per_plugin.items()): console.verbose("%s%3d%s %s\n" % (tty.green + tty.bold, count, tty.normal, name)) section.section_success("%s, %s" % ( f"Found {len(service_result.new)} services" if service_result.new else "Found no%s services" % (" new" if only_new else ""), f"{len(host_labels.new)} host labels" if host_labels.new else "no%s host labels" % (" new" if only_new else ""), ))
def test_remove_autochecks_file(): assert autochecks.has_autochecks("host") is False autochecks.save_autochecks_file("host", []) assert autochecks.has_autochecks("host") is True autochecks.remove_autochecks_file("host") assert autochecks.has_autochecks("host") is False
def test_has_autochecks(): assert autochecks.has_autochecks(HostName("host")) is False autochecks.save_autochecks_file(HostName("host"), []) assert autochecks.has_autochecks(HostName("host")) is True