Skip to content

Commit

Permalink
handle Pending hosts and services correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
VerosK committed Mar 22, 2019
1 parent f64e033 commit 0130f88
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
12 changes: 8 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,21 @@


@app.template_filter('icinga_status')
def status_filter(value):
def status_filter(check_result):
if check_result is None:
return 'N/A'
try:
return State(int(value)).name
return State(int(check_result['state'])).name
except ValueError:
return 'N/A'


@app.template_filter('icinga_status_css_class')
def status_css_class_filter(value):
def status_css_class_filter(check_result):
if check_result is None:
return ''
try:
return getattr(StateCssClass, State(int(value)).name).value
return getattr(StateCssClass, State(int(check_result['state'])).name).value
except ValueError:
return ''

Expand Down
4 changes: 4 additions & 0 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,15 @@ def state_priority(self):
@property
def check_output_long(self):
"Get full check command output"
if not self._data['attrs']['last_check_result']:
return 'Pending'
return self._data['attrs']['last_check_result']['output']

@property
def check_output(self):
"Return short check command output"
if not self._data['attrs']['last_check_result']:
return 'Pending'
return self._data['attrs']['last_check_result']['output'].split('\n')[0]

def __getitem__(self, item):
Expand Down
22 changes: 11 additions & 11 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ <h2>Hosts</h2>
<td>
{{ item.host_address }}
</td>
<td class="{{ item.check_result.state|icinga_status_css_class }}">
{{ item.check_result.state|icinga_status }}
<td class="{{ item.check_result|icinga_status_css_class }}">
{{ item.check_result|icinga_status }}
</td>
<td class="{{ item.check_result.state|icinga_status_css_class }}">
<td class="{{ item.check_result|icinga_status_css_class }}">
{{ item.duration|humanize() }}
</td>
<td class="{{ item.check_result.state|icinga_status_css_class }}">
<td class="{{ item.check_result|icinga_status_css_class }}">
{{ check_attempts(item) }}
</td>
<td class="{{ item.check_result.state|icinga_status_css_class }} plugin-output">
<td class="{{ item.check_result|icinga_status_css_class }} plugin-output">
{{ item.check_output }}
</td>
</tr>
Expand Down Expand Up @@ -138,19 +138,19 @@ <h2>Problem services</h2>
{% else %}
<td class="empty"></td>
{% endif %}
<td class="{{ item.check_result.state|icinga_status_css_class }}">
<td class="{{ item.check_result|icinga_status_css_class }}">
{{ item.service_name }}
</td>
<td class="{{ item.check_result.state|icinga_status_css_class }}">
{{ item.check_result.state|icinga_status }}
<td class="{{ item.check_result|icinga_status_css_class }}">
{{ item.check_result|icinga_status }}
</td>
<td class="{{ item.check_result.state|icinga_status_css_class }}">
<td class="{{ item.check_result|icinga_status_css_class }}">
{{ item.duration|humanize() }}
</td>
<td class="{{ item.check_result.state|icinga_status_css_class }}">
<td class="{{ item.check_result|icinga_status_css_class }}">
{{ check_attempts(item) }}
</td>
<td class="{{ item.check_result.state|icinga_status_css_class }} plugin-output">
<td class="{{ item.check_result|icinga_status_css_class }} plugin-output">
{{ item.check_output }}
</td>
</tr>
Expand Down

0 comments on commit 0130f88

Please sign in to comment.