Module: check_mk
Branch: master
Commit: a54733190078ae1ae36b22535b37205075818a97
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a54733190078ae…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Wed Sep 28 10:51:32 2016 +0200
3904 Now inventory shows age of sections provided by check_mk_agent
---
.werks/3904 | 9 +++++++++
ChangeLog | 1 +
modules/inventory.py | 40 ++++++++++++++++++++++++++++++++++++++++
web/plugins/views/inventory.py | 25 +++++++++++++++++++++----
4 files changed, 71 insertions(+), 4 deletions(-)
diff --git a/.werks/3904 b/.werks/3904
new file mode 100644
index 0000000..2239c03
--- /dev/null
+++ b/.werks/3904
@@ -0,0 +1,9 @@
+Title: Now inventory shows age of sections provided by check_mk_agent
+Level: 1
+Component: inv
+Compatible: compat
+Version: 1.4.0i1
+Date: 1475052515
+Class: feature
+
+
diff --git a/ChangeLog b/ChangeLog
index 3b1e408..f9f68e0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -731,6 +731,7 @@
* 3585 Implemented API for exporting the full host inventory...
* 3591 mssql_clusters: Added information about nodes to MSSQL instance inventory
* 3550 HW/SW inventory: Now able to raise an alert when SW packages info is
missing...
+ * 3904 Now inventory shows age of sections provided by check_mk_agent
* 3219 FIX: lnx_distro: Now detecting Oracle VM Server correctly
* 3229 FIX: lnx_distro: SLES based systems have now an OS name inventorized\
* 3265 FIX: mk_inventory.solaris: fix problem on Solaris 10, do prtdiag and prtpicl
only in global zone
diff --git a/modules/inventory.py b/modules/inventory.py
index 04cab8a..5998191 100644
--- a/modules/inventory.py
+++ b/modules/inventory.py
@@ -292,6 +292,8 @@ def do_inv_for(hostname):
else:
inv_function(info)
+ extend_tree_with_check_mk_inventory_info(hostname)
+
# Remove empty paths
inv_cleanup_tree(g_inv_tree)
old_timestamp = save_inv_tree(hostname)
@@ -303,6 +305,44 @@ def do_inv_for(hostname):
run_inv_export_hooks(hostname, g_inv_tree)
return g_inv_tree, old_timestamp
+
+def extend_tree_with_check_mk_inventory_info(hostname):
+ persisted_file = cmk.paths.omd_root + "/var/check_mk/persisted/%s" %
hostname
+ try:
+ persisted_data = eval(file(persisted_file).read()).items()
+
+ except IOError, e:
+ if e.errno == 2: # IOError: [Errno 2] No such file or directory
+ return
+ else:
+ raise
+
+ except Exception, e:
+ raise MKGeneralException(_("Cannot parse persisted file of %s: %s") %
(hostname, e))
+
+ add_check_mk_inventory_info_to_tree(persisted_data)
+ if opt_verbose:
+ sys.stdout.write(tty.green + tty.bold + "check_mk_sections" + "
" + tty.normal)
+ sys.stdout.flush()
+
+
+def add_check_mk_inventory_info_to_tree(persisted_data):
+ node = inv_tree_list("software.applications.check_mk.inventory.sections:")
+ section_ages = []
+ for section, sectiondata in persisted_data:
+ when, until, info = sectiondata
+ section_ages.append(when)
+
+ node.append({
+ "section" : section,
+ "age" : when,
+ "until" : until,
+ })
+
+ node = inv_tree("software.applications.check_mk.inventory.")
+ node["oldest_section"] = min(section_ages)
+
+
def get_inv_params(hostname, info_type):
return host_extra_conf_merged(hostname, inv_parameters.get(info_type, []))
diff --git a/web/plugins/views/inventory.py b/web/plugins/views/inventory.py
index 0b25dd3..d0b9a03 100644
--- a/web/plugins/views/inventory.py
+++ b/web/plugins/views/inventory.py
@@ -512,9 +512,16 @@ def inv_paint_volt(volt):
else:
return "", ""
-def inv_paint_date(stamp):
- if stamp:
- date_painted = time.strftime("%Y-%m-%d", time.localtime(stamp))
+def inv_paint_date(timestamp):
+ if timestamp:
+ date_painted = time.strftime("%Y-%m-%d", time.localtime(timestamp))
+ return "date", "%s" % date_painted
+ else:
+ return "", ""
+
+def inv_paint_date_and_time(timestamp):
+ if timestamp:
+ date_painted = time.strftime("%Y-%m-%d %H:%M:%S",
time.localtime(timestamp))
return "date", "%s" % date_painted
else:
return "", ""
@@ -691,7 +698,17 @@ inventory_displayhints.update({
".software.packages:*.size" : { "title" :
_("Size"), "paint" : "count" },
".software.packages:*.path" : { "title" :
_("Path"), },
- "software.applications." : { "title" :
_("Applications"), },
+ ".software.applications." : { "title" :
_("Applications"), },
+
+ ".software.applications.check_mk." : {
"title" : _("Check_MK"), },
+ ".software.applications.check_mk.inventory." : {
"title" : _("Hardware/Software Inventory"), },
+ ".software.applications.check_mk.inventory.oldest_section" : {
"title" : _("Oldest agent section"), "paint" :
"timestamp_as_age" },
+ ".software.applications.check_mk.inventory.sections:" : {
"title" : _("Agent sections"),
+ "render" :
render_inv_dicttable,
+ "keyorder" :
[ "section", "age", "until" ] },
+ ".software.applications.check_mk.inventory.sections:*.section" : {
"title" : _("Section") },
+ ".software.applications.check_mk.inventory.sections:*.age" : {
"title" : _("Age"), "paint" : "timestamp_as_age"
},
+ ".software.applications.check_mk.inventory.sections:*.until" : {
"title" : _("Valid until"), "paint" :
"date_and_time" },
".software.applications.citrix." : {
"title" : _("Citrix") },
".software.applications.citrix.controller." : {
"title" : _("Controller") },