-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Configure SNMP contacts and locations - Assign SNMP communities to each device with read or read-write types
- Loading branch information
Showing
9 changed files
with
260 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
netbox_cmdb/netbox_cmdb/migrations/0040_snmpcommunity_snmp.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('dcim', '0161_cabling_cleanup'), | ||
('netbox_cmdb', '0039_logicalinterface'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='SNMPCommunity', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)), | ||
('created', models.DateTimeField(auto_now_add=True, null=True)), | ||
('last_updated', models.DateTimeField(auto_now=True, null=True)), | ||
('name', models.CharField(max_length=100, unique=True)), | ||
('community', models.CharField(max_length=31)), | ||
('type', models.CharField(default='Read-Only', max_length=10)), | ||
], | ||
options={ | ||
'verbose_name_plural': 'SNMP Communities', | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='SNMP', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)), | ||
('created', models.DateTimeField(auto_now_add=True, null=True)), | ||
('last_updated', models.DateTimeField(auto_now=True, null=True)), | ||
('location', models.CharField(max_length=31)), | ||
('contact', models.CharField(max_length=31)), | ||
('community_list', models.ManyToManyField(blank=True, default=None, related_name='%(class)s_community', to='netbox_cmdb.snmpcommunity')), | ||
('device', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='dcim.device')), | ||
], | ||
options={ | ||
'verbose_name_plural': 'SNMP', | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from django.db import models | ||
from netbox_cmdb.choices import SNMPCommunityType | ||
from netbox.models import ChangeLoggedModel | ||
from django.core.exceptions import ValidationError | ||
from django.contrib.postgres.fields import ArrayField | ||
|
||
|
||
class SNMPCommunity(ChangeLoggedModel): | ||
"""A Snmp Community""" | ||
|
||
name = models.CharField(max_length=100, unique=True) | ||
community = models.CharField(max_length=31) | ||
type = models.CharField( | ||
max_length=10, | ||
choices=SNMPCommunityType, | ||
default=SNMPCommunityType.RO, | ||
help_text="Defines the community string permissions of either read-only RO or read-write RW", | ||
) | ||
|
||
def __str__(self): | ||
return f"{self.name}" | ||
|
||
class Meta: | ||
verbose_name_plural = "SNMP Communities" | ||
|
||
|
||
class SNMP(ChangeLoggedModel): | ||
"""A Snmp configuration""" | ||
|
||
community_list = models.ManyToManyField( | ||
to=SNMPCommunity, related_name="%(class)s_community", blank=True, default=None | ||
) | ||
|
||
location = models.CharField(max_length=31) | ||
contact = models.CharField(max_length=31) | ||
|
||
device = models.OneToOneField( | ||
to="dcim.Device", | ||
on_delete=models.CASCADE, | ||
) | ||
|
||
class Meta: | ||
verbose_name_plural = "SNMP" | ||
|
||
def __str__(self): | ||
return f"SNMP configuration of {self.device.name}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters