1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Permit disabling utilization graph warning/danger thresholds

This commit is contained in:
jeremystretch
2021-05-11 14:52:27 -04:00
parent bf56145a09
commit ecf51406c5
4 changed files with 41 additions and 42 deletions

View File

@ -256,6 +256,21 @@ class RoleTable(BaseTable):
# Prefixes # Prefixes
# #
class PrefixUtilizationColumn(UtilizationColumn):
"""
Extend UtilizationColumn to allow disabling the warning & danger thresholds for prefixes
marked as fully utilized.
"""
template_code = """
{% load helpers %}
{% if record.pk and record.mark_utilized %}
{% utilization_graph value warning_threshold=0 danger_threshold=0 %}
{% elif record.pk %}
{% utilization_graph value %}
{% endif %}
"""
class PrefixTable(BaseTable): class PrefixTable(BaseTable):
pk = ToggleColumn() pk = ToggleColumn()
prefix = tables.TemplateColumn( prefix = tables.TemplateColumn(
@ -300,7 +315,7 @@ class PrefixTable(BaseTable):
class PrefixDetailTable(PrefixTable): class PrefixDetailTable(PrefixTable):
utilization = UtilizationColumn( utilization = PrefixUtilizationColumn(
accessor='get_utilization', accessor='get_utilization',
orderable=False orderable=False
) )

View File

@ -101,8 +101,9 @@
<tr> <tr>
<th scope="row">Utilization</th> <th scope="row">Utilization</th>
<td> <td>
{% if object.marked_utilized %} {% if object.mark_utilized %}
{% utilization_graph 100 %} {% utilization_graph 100 warning_threshold=0 danger_threshold=0 %}
<small>(Marked fully utilized)</small>
{% else %} {% else %}
{% utilization_graph object.get_utilization %} {% utilization_graph object.get_utilization %}
{% endif %} {% endif %}

View File

@ -1,42 +1,18 @@
{% if utilization == 0 %} {% if utilization == 0 %}
<div class="progress align-items-center justify-content-center"> <div class="progress align-items-center justify-content-center">
<span class="w-100 text-center">{{ utilization }}%</span> <span class="w-100 text-center">{{ utilization }}%</span>
</div> </div>
{% else %} {% else %}
<div class="progress"> <div class="progress">
{% if utilization >= danger_threshold %}
<div <div
aria-valuemin="0"
role="progressbar" role="progressbar"
aria-valuemin="0"
aria-valuemax="100" aria-valuemax="100"
class="progress-bar bg-danger"
aria-valuenow="{{ utilization }}" aria-valuenow="{{ utilization }}"
style="width: {{ utilization }}%;" class="progress-bar {{ bar_class }}"
style="min-width: 8%; width: {{ utilization }}%;"
> >
{{ utilization }}% {{ utilization }}%
</div> </div>
{% elif utilization >= warning_threshold %}
<div
aria-valuemin="0"
role="progressbar"
aria-valuemax="100"
aria-valuenow="{{ utilization }}"
style="width: {{ utilization }}%;"
class="progress-bar bg-warning"
>
{{ utilization }}%
</div> </div>
{% else %}
<div
aria-valuemin="0"
role="progressbar"
aria-valuemax="100"
class="progress-bar bg-success"
aria-valuenow="{{ utilization }}"
style="min-width: 8%;width: {{ utilization }}%;"
>
{{ utilization }}%
</div>
{% endif %}
</div>
{% endif %} {% endif %}

View File

@ -276,10 +276,17 @@ def utilization_graph(utilization, warning_threshold=75, danger_threshold=90):
""" """
Display a horizontal bar graph indicating a percentage of utilization. Display a horizontal bar graph indicating a percentage of utilization.
""" """
if danger_threshold and utilization >= danger_threshold:
bar_class = 'bg-danger'
elif warning_threshold and utilization >= warning_threshold:
bar_class = 'bg-warning'
elif warning_threshold or danger_threshold:
bar_class = 'bg-success'
else:
bar_class = 'bg-default'
return { return {
'utilization': utilization, 'utilization': utilization,
'warning_threshold': warning_threshold, 'bar_class': bar_class,
'danger_threshold': danger_threshold,
} }