Skip to content

Commit

Permalink
fix(snmp): limit SNMP communities
Browse files Browse the repository at this point in the history
As Sonic devices do not accept more than one SNMP community, we prefer to limit to the lowest
common denominator.
  • Loading branch information
cpaillet committed Jul 10, 2024
1 parent d808393 commit 4b1b4dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions netbox_cmdb/netbox_cmdb/constants.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
BGP_MIN_ASN = 1
BGP_MAX_ASN = 4294967294

# As Sonic device don't support more than 1 community
MAX_COMMUNITY_PER_DEVICE = 1
9 changes: 9 additions & 0 deletions netbox_cmdb/netbox_cmdb/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.utils.translation import gettext as _
from extras.models import Tag
from netbox_cmdb.models.snmp import SNMP, SNMPCommunity
from netbox_cmdb.constants import MAX_COMMUNITY_PER_DEVICE
from utilities.forms import DynamicModelMultipleChoiceField
from utilities.forms.fields import DynamicModelChoiceField, MultipleChoiceField

Expand Down Expand Up @@ -93,6 +94,14 @@ class Meta:
model = SNMP
fields = ["device", "community_list", "location", "contact"]

def clean_community_list(self):
community_list = self.cleaned_data.get("community_list")
if len(community_list) > MAX_COMMUNITY_PER_DEVICE:
raise forms.ValidationError(
f"You cannot select more than {MAX_COMMUNITY_PER_DEVICE} SNMP Communities."
)
return community_list


class SNMPCommunityGroupForm(NetBoxModelForm):
class Meta:
Expand Down

0 comments on commit 4b1b4dd

Please sign in to comment.