Module: check_mk
Branch: master
Commit: e94cc003ab9abb662aac615a5f33cf7ee03820bb
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e94cc003ab9abb…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Dec 8 17:57:55 2014 +0100
#1715 Output icon information in CSV/JSON/Python export of views
When exporting views to JSON, Python or CSV the column with the icons
is now no longer empty but is a space separated list of all icon names
of the host/sevice in question - without path information or the suffixes
of the file type. That way you now can get additional information about
the objects.
---
.werks/1715 | 13 +++++++++++++
ChangeLog | 1 +
web/htdocs/htmllib.py | 10 +++++++---
web/plugins/icons/builtin.py | 2 +-
web/plugins/views/painters.py | 18 +++++++++++++++++-
5 files changed, 39 insertions(+), 5 deletions(-)
diff --git a/.werks/1715 b/.werks/1715
new file mode 100644
index 0000000..019e372
--- /dev/null
+++ b/.werks/1715
@@ -0,0 +1,13 @@
+Title: Output icon information in CSV/JSON/Python export of views
+Level: 1
+Component: multisite
+Compatible: compat
+Version: 1.2.5i7
+Date: 1418057797
+Class: feature
+
+When exporting views to JSON, Python or CSV the column with the icons
+is now no longer empty but is a space separated list of all icon names
+of the host/sevice in question - without path information or the suffixes
+of the file type. That way you now can get additional information about
+the objects.
diff --git a/ChangeLog b/ChangeLog
index 45bb972..a28ed89 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -146,6 +146,7 @@
* 1700 Enable icon for link to host/service parameters per default now...
* 1705 Better styling of dashboard designer
* 1714 Add support for jsonp export (next to json and python)...
+ * 1715 Output icon information in CSV/JSON/Python export of views...
* 1164 FIX: Fixed links from servicegroup overviews to single servicegroups
* 1166 FIX: Also prevting stylesheet update issues during version updates (just like
for JS files)
* 1481 FIX: Fix broken layout of Host-, Service- and Contactgroup filters
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 9d7740a..d0c0b16 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -328,10 +328,14 @@ class html:
def icon(self, help, icon):
self.write(self.render_icon(icon, help))
- def render_icon(self, icon, help, middle=True):
+ def render_icon(self, icon, help="", middle=True):
align = middle and ' align=absmiddle' or ''
- return '<img%s class=icon title="%s"
src="images/icon_%s.png" />' % \
- (align, self.attrencode(help), icon)
+ title = help and ' title="%s"' % self.attrencode(help) or
""
+ if "/" in icon:
+ src = "images/" + icon
+ else:
+ src = "images/icon_%s.png" % icon
+ return '<img src="%s" class=icon%s%s />' % (src, align,
title)
def empty_icon(self):
self.write('<img class=icon src="images/trans.png" />')
diff --git a/web/plugins/icons/builtin.py b/web/plugins/icons/builtin.py
index d25f979..1b4af8d 100644
--- a/web/plugins/icons/builtin.py
+++ b/web/plugins/icons/builtin.py
@@ -68,7 +68,7 @@
def paint_icon_image(what, row, tags, custom_vars):
if row[what + '_icon_image']:
- return '<img align=absmiddle class=icon
src="images/icons/%s">' % row[what + '_icon_image']
+ return html.render_icon("icons/" + row[what + '_icon_image'])
multisite_icons.append({
'columns': [ 'icon_image' ],
diff --git a/web/plugins/views/painters.py b/web/plugins/views/painters.py
index 448d033..fe896e2 100644
--- a/web/plugins/views/painters.py
+++ b/web/plugins/views/painters.py
@@ -151,7 +151,23 @@ def paint_icons(what, row):
except Exception, e:
output += 'Exception in icon plugin!<br />' +
traceback.format_exc()
- return "icons", output
+ if html.output_format == "html":
+ return "icons", output
+ else:
+ # Strip icon names out of HTML code that is generated by htmllib.render_icon()
+ icon_rename_regex = regex('<img
src="([^"]*)"[^>]*>')
+ icons = []
+ for n in icon_rename_regex.findall(output):
+ if n.startswith("images/"):
+ n = n[7:]
+ if n.startswith("icon_"):
+ n = n[5:]
+ if n.endswith(".png"):
+ n = n[:-4]
+ elif n.endswith(".gif"):
+ n = n[:-4]
+ icons.append(n.encode('utf-8'))
+ return "icons", " ".join(icons)
def iconpainter_columns(what):
cols = set(['site',