Skip to content

Commit

Permalink
feat(snmp): add device search
Browse files Browse the repository at this point in the history
- Added device name filtering in classic view and admin view.

This enhancement improves the usability of SNMP management by enabling searches.
  • Loading branch information
cpaillet committed Jul 12, 2024
1 parent be064c4 commit 70ea24d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions netbox_cmdb/netbox_cmdb/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ class SNMPAdmin(BaseAdmin):
"contact",
)

search_fields = ("device__name", "location")

def community_list_display(self, obj):
return ", ".join([str(community) for community in obj.community_list.all()])

Expand Down
19 changes: 19 additions & 0 deletions netbox_cmdb/netbox_cmdb/filtersets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import django_filters
from django.db.models import Q
from netbox_cmdb.models.snmp import SNMP
from tenancy.filtersets import TenancyFilterSet
from utilities.filters import MultiValueCharFilter

Expand Down Expand Up @@ -179,3 +180,21 @@ def search(self, queryset, name, value):
return queryset.filter(
Q(device__name__icontains=value) | Q(name__icontains=value)
).distinct()


class SNMPFilterSet(ChangeLoggedModelFilterSet):
"""AS number filterset."""

q = django_filters.CharFilter(
method="search",
label="Search",
)

class Meta:
model = SNMP
fields = ["device"]

def search(self, queryset, name, value):
if not value.strip():
return queryset
return queryset.filter(Q(device__name__icontains=value)).distinct()
2 changes: 2 additions & 0 deletions netbox_cmdb/netbox_cmdb/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
ASNFilterSet,
BGPPeerGroupFilterSet,
BGPSessionFilterSet,
SNMPFilterSet,
)
from netbox_cmdb.forms import (
ASNForm,
Expand Down Expand Up @@ -124,6 +125,7 @@ class BGPPeerGroupView(ObjectView):
## Snmp groups views
class SNMPListView(ObjectListView):
queryset = SNMP.objects.all()
filterset = SNMPFilterSet
table = SNMPTable


Expand Down

0 comments on commit 70ea24d

Please sign in to comment.