Skip to content

Commit

Permalink
Show Graphite unreachable label
Browse files Browse the repository at this point in the history
Instead of erroring out in netbox availability
  • Loading branch information
johannaengland committed Jul 1, 2022
1 parent 131c9e7 commit 4ba54c2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
15 changes: 12 additions & 3 deletions python/nav/web/info/netboxgroup/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from nav.web.utils import create_title
from nav.models.manage import NetboxGroup, Netbox, NetboxCategory
from nav.metrics.data import get_netboxes_availability
from nav.metrics.errors import GraphiteUnreachableError


class NetboxGroupForm(SearchForm):
Expand Down Expand Up @@ -95,9 +96,16 @@ def group_detail(request, groupid):
"""
group = get_object_or_404(NetboxGroup, pk=groupid)
netboxes = group.netbox_set.select_related('organization', 'category', 'type')
availabilities = get_netboxes_availability(
netboxes, data_sources=['availability'], time_frames=['week', 'month']
)
availabilities = {}
graphite_error = False

try:
availabilities = get_netboxes_availability(
netboxes, data_sources=['availability'], time_frames=['week', 'month']
)
except GraphiteUnreachableError:
graphite_error = True

navpath = get_netboxgroup_path([(group.pk,)])

return render(
Expand All @@ -109,6 +117,7 @@ def group_detail(request, groupid):
'availabilities': availabilities,
'navpath': navpath,
'title': create_title(navpath),
'graphite_error': graphite_error,
},
)

Expand Down
10 changes: 8 additions & 2 deletions python/nav/web/info/room/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,24 @@ def render_deviceinfo(request, roomid):
all_netboxes = room.netbox_set.select_related(
"type", "category", "organization"
).order_by("sysname")
availabilities = {}
graphite_error = False

try:
availabilities = get_netboxes_availability(
all_netboxes, data_sources=["availability"], time_frames=["week", "month"]
)
except GraphiteUnreachableError:
availabilities = None
graphite_error = True

return render(
request,
"info/room/roominfo_devices.html",
{"netboxes": all_netboxes, "availabilities": availabilities},
{
"netboxes": all_netboxes,
"availabilities": availabilities,
'graphite_error': graphite_error,
},
)


Expand Down
19 changes: 13 additions & 6 deletions python/nav/web/templates/info/fragments/netboxes.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,19 @@
<img src="{{ STATIC_URL }}images/lys/{% if netbox.up == 'y' %}green.png{% else %}red.png{% endif %}">
</td>

{% with data=availabilities|get_value:netbox.id %}
{% with availability=data|get_value:'availability' %}
<td class="numeric">{{ availability|get_value:'week'|floatformat:'2' }}%</td>
<td class="numeric">{{ availability|get_value:'month'|floatformat:'2' }}%</td>
{% endwith %}
{% endwith %}
{% if availabilities %}
{% with data=availabilities|get_value:netbox.id %}
{% with availability=data|get_value:'availability' %}
<td class="numeric">{{ availability|get_value:'week'|floatformat:'2' }}%</td>
<td class="numeric">{{ availability|get_value:'month'|floatformat:'2' }}%</td>
{% endwith %}
{% endwith %}
{% elif graphite_error %}
<td><span class="label alert">Graphite unreachable</span></td>
<td><span class="label alert">Graphite unreachable</span></td>
{% else %}
N/A
{% endif %}
</tr>
{% endfor %}
</tbody>
Expand Down

0 comments on commit 4ba54c2

Please sign in to comment.