View for custom inventory data of all hosts

Hello,

I’ve written a client plugin which provides data for the inventory.
A script in ~/local/share/check_mk/inventory collects this data and feeds the inventory store.
When I look into the inventory tree of a host, the data is available there.

This is the inventory tree:

software.applications.snapshot_backup.version
software.applications.snapshot_backup.snapshot_version
software.applications.snapshot_backup.snapshot_version_info
software.applications.snapshot_backup.snapshot_build
software.applications.snapshot_backup.snapshot_date

Now I want to have a summary page to display this data across all hosts in a table.
Just like it is available with the builtin view Inventory\CPU Related Inventory of all Hosts page like this:

Host Version Snapshot Version
Host1 3.12 1.48
Host2 3.08 1.46
Host3 3.11 1.46

From the informations from this page I’ve tried to adapt an own script to get a own view.
~/local/share/check_mk/web/plugins/views/my_inventory.py

#!/usr/bin/python

inventory_displayhints.update({

  ".software.applications.snapshot_backup:"  : { "title" : _("Snapshot Inventory"),
                                                 "render" : render_inv_dicttable,
                                                 "view" : "invsnap_of_host",
                                                 "keyorder": ["version", "snapshot_version", "snapshot_build", "snapshot_date", "snapshot_version_info"]                                                                             },
  ".software.applications.snapshot_backup:*.version"                 : { "title" : _("Version") },
  ".software.applications.snapshot_backup:*.snapshot_version"        : { "title" : _("Snapshot Version") },
  ".software.applications.snapshot_backup:*.snapshot_build"          : { "title" : _("Snapshot Build") },
  ".software.applications.snapshot_backup:*.snapshot_date"           : { "title" : _("Snapshot Datum") },
  ".software.applications.snapshot_backup:*.snapshot_version_info"   : { "title" : _("Snapshot Info") },
})

declare_invtable_view("invsnap", ".software.applications.snapshot_backup:", _("Snapshot Inventory"), _("Snapshot Inventory"))

Then I’ve restarted the site using omd restart apache && cmk -v -R, but I cannot see any result in the UI.
What could I check? What did I possibly wrong?

Best regards,
Alexander

It looks like there are some import statements missing at the start of the file.
If you take a look at the “~/var/log/web.log” then you see there some entries about missing defenitions.

Hi Andreas,

thank you for this hint.
I added a suitable import found in this posting.

The effect is: no more error message in the log.
But there is no view also…

from cmk.gui.plugins.views.inventory import (
  declare_invtable_view,
  render_inv_dicttable,
)

Somehow the view seems to be registered although.
When I browse to https://cmk/site/check_mk/view.py?view_name=invsnap_of_host
the result is a error message telling me some kontext information of type host is missing.

When I add a typo like view_name=invsapxxx_of_host
the result is another error telling the element does not exist.

Is there any comprehensive documentation about how to use inventory_displayhints and declare_invtable_view ?

I am stuck again…
Alexander

This is correct as your view needs the hostname as context information.

Is your data visible inside the inventory view of your host?
This should already work without the working “declare_invtable_view”.
If your declaration is working you should see on your table in the top right the following.
image

1 Like

Hi Andreas,

this is the inventory view of one host, the data is rendered in a default way.
ScreenShot_2020-11-06_09-33-21_alex_Checkmk_Local_site_master_-_Inventory_of_host_jf-s10.jf-do2.local

This is completely okay for me as each host does only have a single set of values.
What I want to get is a list of this data across all hosts.
Just like is is available for CPU related data:

I want a list like the following, but for the snapshot data.
With a link in the left panel called [Snapshot Inventory of all Hosts]

Thanks for you help!
Alexander

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.