Skip to content

Extend interface discovery to allow discovery of multiple service labels #798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions cmk/gui/plugins/wato/check_parameters/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,47 @@ def _vs_item_appearance(title, help_txt):
)


def _vs_labels_conditions():
return ListOf(
title=_("Generate service labels for discovered matching interfaces"),
help=_(
"Generate service labels based on matching conditions. All matching entries will add to the list of service labels."
),
valuespec=Dictionary(
elements=[
(
"conditions",
Dictionary(
title=_("Matching conditions"),
elements=[
(
"match_index",
_vs_regex_matching("index"),
),
(
"match_alias",
_vs_regex_matching("alias"),
),
(
"match_desc",
_vs_regex_matching("description"),
),
],
),
),
(
"labels",
Labels(
world=Labels.World.CONFIG,
label_source=Labels.Source.RULESET,
title=_("Generate service labels"),
),
),
],
),
)


def _vs_single_discovery():
return CascadingDropdown(
title=_("Configure discovery of single interfaces"),
Expand Down Expand Up @@ -114,6 +155,10 @@ def _vs_single_discovery():
title=_("Generate service labels for discovered interfaces"),
),
),
(
"labels_conditions",
_vs_labels_conditions(),
)
],
optional_keys=["labels"],
),
Expand Down
22 changes: 21 additions & 1 deletion cmk/plugins/lib/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,13 +1212,33 @@ def discover_interfaces(
except (TypeError, ValueError):
index_as_item = False

labels = {}
if labels_conditions := single_interface_settings.get("labels_conditions"):
for labels_condition in labels_conditions:
conditions = labels_condition.get("conditions", {})
if (
check_regex_match_conditions(
interface.attributes.index, conditions.get("match_index")
)
and check_regex_match_conditions(
interface.attributes.alias, conditions.get("match_alias")
)
and check_regex_match_conditions(
interface.attributes.descr, conditions.get("match_desc")
)
):
for k, v in labels_condition.get("labels").items():
labels[k] = v
for k, v in single_interface_settings.get("labels", {}).items():
labels[k] = v

pre_inventory.append(
(
item,
discovered_params_single,
int(interface.attributes.index),
index_as_item,
single_interface_settings.get("labels"),
labels,
)
)
seen_indices.add(interface.attributes.index)
Expand Down