Skip to content

Commit

Permalink
For shinken-monitoring#726, improve check_command rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
mohierf committed Dec 22, 2019
1 parent b49b16c commit eae0717
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
1 change: 1 addition & 0 deletions etc/modules/webui2.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ define module {

# Database name where to fetch the logs/availability collections
#database shinken

# User authentication for database access
#username
#password
Expand Down
36 changes: 36 additions & 0 deletions module/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,42 @@ def get_timeperiod_html(self, timeperiod):

return content

def get_check_command_html(self, item, command_line):
if not item or not item.check_command:
return ''

c_line = getattr(item.check_command, "command_line",
getattr(item.check_command, "command_name", "None"))

checks_data = [item, item.host] if item.my_type == 'service' else [item]
mr = MacroResolver()
if ALIGNAK:
expanded = mr.resolve_simple_macros_in_string(command_line, checks_data, [], [],
item.check_command.args)
expanded2 = mr.resolve_simple_macros_in_string(c_line, checks_data, [], [],
item.check_command.args)
else:
expanded = mr.resolve_simple_macros_in_string(command_line, checks_data,
item.check_command.args)
expanded2 = mr.resolve_simple_macros_in_string(c_line, checks_data,
item.check_command.args)

html_content = '<u>Command line:</u>' \
'<br>' \
'<div style="max-width: 320px; overflow-wrap: break-word;">%s</div>' \
% c_line
html_content += '<br>' \
'<u>Command line with macro expansion:</u>' \
'<br>' \
'<div style="max-width: 320px; overflow-wrap: break-word;">%s</div>' \
% expanded
html_content += '<br>' \
'Arguments:' \
'<br>%s' % ("<br>&nbsp;&nbsp;".join(item.check_command.args)
if item.check_command.args else "None")

return html_content, expanded, expanded2

def get_contact_avatar(self, contact, size=24, with_name=True, with_link=True):
name = contact
title = name
Expand Down
22 changes: 14 additions & 8 deletions module/plugins/eltdetail/views/_eltdetail_information.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,21 @@
%end
<tr>
<td><strong>Check command:</strong></td>
<td>
%if elt.check_command:
<a href="/commands#{{elt.get_check_command()}}">{{elt.get_check_command()}}</a>
%else:
<strong>No check command</strong>
%end
</td>
<td>
%if elt.check_command:
%cmd = app.datamgr.get_command(elt.get_check_command())
%html_content, expanded, expanded2 = helper.get_check_command_html(elt, cmd.command_line)

<td name="check_command" class="popover-dismiss" data-html="true" data-toggle="popover" data-placement="top"
data-title='<code>{{ getattr(elt.check_command, "command_name", "None") }}</code>'
data-content='{{ html_content }}'>
<a href="/commands#{{ elt.get_check_command() }}">
{{ getattr(elt.check_command, "command_name", "None") }}
</a>
<br><code>{{ expanded2 }}</code>
</td>
%else:
<strong>No check command</strong>
%end
</tr>
%enabled = app.datamgr.get_configuration_parameter('execute_host_checks' if elt_type == 'host' else 'execute_service_checks')
<tr>
Expand Down
4 changes: 4 additions & 0 deletions module/views/header_element.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@
%if app.logs_module.is_available():
<li> <a href="{{ app.get_url('History') }}"> <i class="fas fa-fw fa-th-list sidebar-icon"></i>
&nbsp;Logs </a> </li>
%if alignak:
<li> <a href="{{ app.get_url('AlignakStats') }}"> <i class="fas fa-fw fa-bell sidebar-icon"></i>
&nbsp;Alignak alerts </a> </li>
%end
<li> <a href="{{ app.get_url('GlobalStats') }}"> <i class="fas fa-fw fa-bell sidebar-icon"></i>
&nbsp;Alerts </a> </li>
%end
Expand Down

0 comments on commit eae0717

Please sign in to comment.