Skip to content

Commit

Permalink
Move code for host labels to its own section
Browse files Browse the repository at this point in the history
Change-Id: I91d4f318e4886d8fc5b9ad8b89bb40887ee7848a
  • Loading branch information
si-23 committed Sep 29, 2020
1 parent 756cf01 commit abf7ad5
Showing 1 changed file with 44 additions and 31 deletions.
75 changes: 44 additions & 31 deletions cmk/base/discovery.py
Expand Up @@ -473,29 +473,6 @@ def _do_discovery_for(
section.section_success(", ".join(messages))


def _perform_host_label_discovery(
hostname: HostName,
discovered_host_labels: DiscoveredHostLabels,
only_new: bool,
) -> Tuple[DiscoveredHostLabels, Counter[CheckPluginName]]:

# Take over old items if -I is selected
if only_new:
return_host_labels = DiscoveredHostLabels.from_dict(
DiscoveredHostLabelsStore(hostname).load())
else:
return_host_labels = DiscoveredHostLabels()

new_host_labels_per_plugin: Counter[CheckPluginName] = Counter()
for discovered_label in discovered_host_labels.values():
if discovered_label.name in return_host_labels:
continue
return_host_labels.add_label(discovered_label)
new_host_labels_per_plugin[discovered_label.plugin_name] += 1

return return_host_labels, new_host_labels_per_plugin


# determine changed services on host.
# param mode: can be one of "new", "remove", "fixall", "refresh"
# param servic_filter: if a filter is set, it controls whether items are touched by the discovery.
Expand Down Expand Up @@ -1085,18 +1062,41 @@ def _may_rediscover(params: config.DiscoveryCheckParameters, now_ts: float,


#.
# .--Discovery-----------------------------------------------------------.
# | ____ _ |
# | | _ \(_)___ ___ _____ _____ _ __ _ _ |
# | | | | | / __|/ __/ _ \ \ / / _ \ '__| | | | |
# | | |_| | \__ \ (_| (_) \ V / __/ | | |_| | |
# | |____/|_|___/\___\___/ \_/ \___|_| \__, | |
# | |___/ |
# .--Host labels---------------------------------------------------------.
# | _ _ _ _ _ _ |
# | | | | | ___ ___| |_ | | __ _| |__ ___| |___ |
# | | |_| |/ _ \/ __| __| | |/ _` | '_ \ / _ \ / __| |
# | | _ | (_) \__ \ |_ | | (_| | |_) | __/ \__ \ |
# | |_| |_|\___/|___/\__| |_|\__,_|_.__/ \___|_|___/ |
# | |
# +----------------------------------------------------------------------+
# | Core code of actual service discovery |
# | |
# '----------------------------------------------------------------------'


def _perform_host_label_discovery(
hostname: HostName,
discovered_host_labels: DiscoveredHostLabels,
only_new: bool,
) -> Tuple[DiscoveredHostLabels, Counter[CheckPluginName]]:

# Take over old items if -I is selected
if only_new:
return_host_labels = DiscoveredHostLabels.from_dict(
DiscoveredHostLabelsStore(hostname).load())
else:
return_host_labels = DiscoveredHostLabels()

new_host_labels_per_plugin: Counter[CheckPluginName] = Counter()
for discovered_label in discovered_host_labels.values():
if discovered_label.name in return_host_labels:
continue
return_host_labels.add_label(discovered_label)
new_host_labels_per_plugin[discovered_label.plugin_name] += 1

return return_host_labels, new_host_labels_per_plugin


def _discover_host_labels(
hostname: HostName,
ipaddress: Optional[HostAddress],
Expand Down Expand Up @@ -1183,6 +1183,19 @@ def _discover_host_labels_for_source_type(
return discovered_host_labels


#.
# .--Discovery-----------------------------------------------------------.
# | ____ _ |
# | | _ \(_)___ ___ _____ _____ _ __ _ _ |
# | | | | | / __|/ __/ _ \ \ / / _ \ '__| | | | |
# | | |_| | \__ \ (_| (_) \ V / __/ | | |_| | |
# | |____/|_|___/\___\___/ \_/ \___|_| \__, | |
# | |___/ |
# +----------------------------------------------------------------------+
# | Core code of actual service discovery |
# '----------------------------------------------------------------------'


def _find_candidates(
mhs: MultiHostSections,
selected_check_plugins: Optional[Set[CheckPluginName]],
Expand Down

0 comments on commit abf7ad5

Please sign in to comment.