Skip to content

Commit

Permalink
Added new treasure for creating customized Tactical Overview snapins
Browse files Browse the repository at this point in the history
  • Loading branch information
MathiasKettner committed Apr 20, 2016
1 parent fbb7004 commit 100bee7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 16 deletions.
29 changes: 29 additions & 0 deletions doc/treasures/sidebar_tactical_overview.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-

# Put this into local/share/check_mk/web/plugins/sidebar. And you will get
# additional versions of "Tactical Overview" for hosts having a certain
# tag.

def create_tactical_overview_snapin(title, tag_group, tag_name):
def create_render_function(tag_group, tag_name):
return lambda: render_tactical_overview(
extra_filter_headers = "Filter: host_custom_variables ~ TAGS (^|[ ])%s($|[ ])\n" % tag_name,
extra_url_variables = [
( "host_tag_0_grp", tag_group ),
( "host_tag_0_op", "is" ),
( "host_tag_0_val", tag_name ),
])

sidebar_snapins["tactical_overview_" + tag_name] = {
"title" : title,
"description" : _("Tactical overview of all hosts with the tag %s") % tag_name,
"refresh" : True,
"render" : create_render_function(tag_group, tag_name),
"allowed" : [ "user", "admin", "guest" ],
"styles" : snapin_tactical_overview_styles,
}

# Here you declare which copies of the snapin you wnat:
create_tactical_overview_snapin(u"München", "stadt", "muc")
create_tactical_overview_snapin(u"Göttingen", "stadt", "got")
37 changes: 21 additions & 16 deletions web/plugins/sidebar/shipped.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ def render_sitestatus():
# | |
# '----------------------------------------------------------------------'

def render_tactical_overview():
def render_tactical_overview(extra_filter_headers="", extra_url_variables=[]):
host_query = \
"GET hosts\n" \
"Stats: state >= 0\n" \
Expand All @@ -560,7 +560,8 @@ def render_tactical_overview():
"Stats: scheduled_downtime_depth = 0\n" \
"Stats: acknowledged = 0\n" \
"StatsAnd: 3\n" \
"Filter: custom_variable_names < _REALNAME\n"
"Filter: custom_variable_names < _REALNAME\n" + \
extra_filter_headers

service_query = \
"GET services\n" \
Expand All @@ -576,9 +577,8 @@ def render_tactical_overview():
"Stats: acknowledged = 0\n" \
"Stats: host_state = 0\n" \
"StatsAnd: 5\n" \
"Filter: host_custom_variable_names < _REALNAME\n"

# ACHTUNG: Stats-Filter so anpassen, dass jeder Host gezaehlt wird.
"Filter: host_custom_variable_names < _REALNAME\n" + \
extra_filter_headers

try:
hstdata = sites.live().query_summed_stats(host_query)
Expand All @@ -594,25 +594,21 @@ def render_tactical_overview():
html.write("<tr><th>%s</th><th>%s</th><th>%s</th></tr>\n" % (title, _('Problems'), _('Unhandled')))
html.write("<tr>")

html.write('<td class=total><a target="main" href="view.py?view_name=all%ss">%d</a></td>' % (what, data[0]))
url = html.makeuri_contextless([("view_name", "all" + what + "s")] + extra_url_variables, filename="view.py")
html.write('<td class=total><a target="main" href="%s">%d</a></td>' % (url, data[0]))
unhandled = False
for value in data[1:]:
href = "view.py?view_name=" + view
url = html.makeuri_contextless([("view_name", view)] + extra_url_variables, filename="view.py")
if unhandled:
href += "&is_%s_acknowledged=0" % what
text = link(str(value), href)
url += "&is_%s_acknowledged=0" % what
text = link(str(value), url)
html.write('<td class="%s">%s</td>' % (value == 0 and " " or "states prob", text))
unhandled = True
html.write("</tr>\n")
html.write("</table>\n")

sidebar_snapins["tactical_overview"] = {
"title" : _("Tactical Overview"),
"description" : _("The total number of hosts and service with and without problems"),
"refresh" : True,
"render" : render_tactical_overview,
"allowed" : [ "user", "admin", "guest" ],
"styles" : """

snapin_tactical_overview_styles = """
table.tacticaloverview {
border-collapse: separate;
/**
Expand Down Expand Up @@ -647,6 +643,15 @@ def render_tactical_overview():
}
table.tacticaloverview a { display: block; margin-right: 2px; }
""" % snapin_width


sidebar_snapins["tactical_overview"] = {
"title" : _("Tactical Overview"),
"description" : _("The total number of hosts and service with and without problems"),
"refresh" : True,
"render" : render_tactical_overview,
"allowed" : [ "user", "admin", "guest" ],
"styles" : snapin_tactical_overview_styles,
}

#.
Expand Down

0 comments on commit 100bee7

Please sign in to comment.