We use cookies to ensure that we give you the best experience on our website.  Visit our Privacy Policy to learn more. If you continue to use this site, we will assume that you are okay with it.

Your choices regarding cookies on this site.
Your preferences have been updated.
In order for the changes to take effect completely please clear your browser cookies and cache. Then reload the page.

Werk #10836: HW/SW Inventory views: Declared inventory views can be joined

ComponentHW/SW-Inventory
TitleHW/SW Inventory views: Declared inventory views can be joined
Date2020-03-06 09:35:08
Checkmk EditionCheckmk Raw Edition (CRE)
Checkmk Version1.7.0i1
LevelTrivial Change
ClassNew Feature
CompatibilityCompatible - no manual interaction needed

HW/SW inventory views can be declared with declare_invtable_view in local/share/check_mk/web/plugins/views/MY_FILE_NAME.py. After this declaration a new view with sorters and filters is available.

Example:

declare_invtable_view(
"invinterface",
".networking.interfaces:",
_("Network interface"),
_("Network interfaces"),
)

generates the view Search Network interfaces in the views sidebar below Inventory.

Some of these tables may have common columns like ID but have different data sources. A new function is introduced in order to join some table-based views:

declare_joined_inventory_table_view(
tablename = "invMYMULTITABLE",
title_singular = _("TITLE SINGULAR"),
title_plural = _("TITLE PLURAL"),
tables = [
"invTABLE1",
"invTABLE2",
...
],
match_by = [
"KEY1",
"KEY2",
...
],
)

In order to join some table-based views you have to

  • extend the display hints for each table path and
  • declare own views for each table

Display hints:

inventory_displayhints.update({
".PATH.TO.TABLE1:": {
"title": _("TITLE TABLE1"),
"keyorder": [
"id",
"value_1_1",
"value_1_2",
...
],
"view": "invTABLE1_of_host",
},
".PATH.TO.TABLE1:*.id": {"title": _("ID")},
".PATH.TO.TABLE1:*.value_1_1": {"title": _("Value 1 1")},
".PATH.TO.TABLE1:*.value_1_2": {"title": _("Value 1 2")},
...

".PATH.TO.TABLE2:": {
"title": _("TITLE TABLE2"),
"keyorder": [
"id",
"value_2_1",
"value_2_2",
...
],
"view": "invTABLE2_of_host",
},
".PATH.TO.TABLE2:*.id": {"title": _("ID")},
".PATH.TO.TABLE2:*.value_2_1": {"title": _("Value 2 1")},
".PATH.TO.TABLE2:*.value_2_2": {"title": _("Value 2 2")},
...
})

Declarations:

declare_invtable_view(
"invTABLE1",
".PATH.TO.TABLE1:"
_("TITLE TABLE1 SINGULAR"),
_("TITLE TABLE1 PLURAL"),
)

declare_invtable_view(
"invTABLE2",
".PATH.TO.TABLE2:"
_("TITLE TABLE2 SINGULAR"),
_("TITLE TABLE2 PLURAL"),
)

declare_joined_inventory_table_view(
tablename = "invMULTITABLE",
title_singular = _("TITLE MULTITABLE SINGULAR"),
title_plural = _("TITLE MULTITABLE PLURAL"),
tables = [
"invTABLE1",
"invTABLE2",
...
],
match_by = [
"id",
...
],
)

The keys in match_by must be part of each table. Otherwise Checkmk does not known which rows belong together. Now all stated tables are merged into one and all columns of both are visible in the new view.