Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ICS Control System Infrastructure
Netbox
Commits
ecf51406
Commit
ecf51406
authored
May 11, 2021
by
jeremystretch
Browse files
Permit disabling utilization graph warning/danger thresholds
parent
bf56145a
Changes
4
Hide whitespace changes
Inline
Side-by-side
netbox/ipam/tables.py
View file @
ecf51406
...
...
@@ -256,6 +256,21 @@ class RoleTable(BaseTable):
# 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
):
pk
=
ToggleColumn
()
prefix
=
tables
.
TemplateColumn
(
...
...
@@ -300,7 +315,7 @@ class PrefixTable(BaseTable):
class
PrefixDetailTable
(
PrefixTable
):
utilization
=
UtilizationColumn
(
utilization
=
Prefix
UtilizationColumn
(
accessor
=
'get_utilization'
,
orderable
=
False
)
...
...
netbox/templates/ipam/prefix.html
View file @
ecf51406
...
...
@@ -101,8 +101,9 @@
<tr>
<th
scope=
"row"
>
Utilization
</th>
<td>
{% if object.marked_utilized %}
{% utilization_graph 100 %}
{% if object.mark_utilized %}
{% utilization_graph 100 warning_threshold=0 danger_threshold=0 %}
<small>
(Marked fully utilized)
</small>
{% else %}
{% utilization_graph object.get_utilization %}
{% endif %}
...
...
netbox/templates/utilities/templatetags/utilization_graph.html
View file @
ecf51406
{% 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>
</div>
</div>
{% else %}
<div
class=
"progress"
>
{% if utilization >= danger_threshold %}
<div
aria-valuemin=
"0"
role=
"progressbar"
aria-valuemax=
"100"
class=
"progress-bar bg-danger"
aria-valuenow=
"{{ utilization }}"
style=
"width: {{ utilization }}%;"
<div
class=
"progress"
>
<div
role=
"progressbar"
aria-valuemin=
"0"
aria-valuemax=
"100"
aria-valuenow=
"{{ utilization }}"
class=
"progress-bar {{ bar_class }}"
style=
"min-width: 8%; width: {{ utilization }}%;"
>
{{ utilization }}%
{{ utilization }}%
</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>
{% 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 %}
\ No newline at end of file
</div>
{% endif %}
netbox/utilities/templatetags/helpers.py
View file @
ecf51406
...
...
@@ -276,10 +276,17 @@ def utilization_graph(utilization, warning_threshold=75, danger_threshold=90):
"""
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
{
'utilization'
:
utilization
,
'warning_threshold'
:
warning_threshold
,
'danger_threshold'
:
danger_threshold
,
'bar_class'
:
bar_class
,
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment