netbox-ping 0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. netbox_ping-0.2/MANIFEST.in +5 -0
  2. netbox_ping-0.2/PKG-INFO +176 -0
  3. netbox_ping-0.2/README.md +154 -0
  4. netbox_ping-0.2/netbox_ping/__init__.py +23 -0
  5. netbox_ping-0.2/netbox_ping/config.py +43 -0
  6. netbox_ping-0.2/netbox_ping/forms.py +13 -0
  7. netbox_ping-0.2/netbox_ping/hooks.py +6 -0
  8. netbox_ping-0.2/netbox_ping/migrations/0001_initial.py +30 -0
  9. netbox_ping-0.2/netbox_ping/migrations/__init__.py +0 -0
  10. netbox_ping-0.2/netbox_ping/migrations/__pycache__/0001_initial.cpython-312.pyc +0 -0
  11. netbox_ping-0.2/netbox_ping/migrations/__pycache__/__init__.cpython-312.pyc +0 -0
  12. netbox_ping-0.2/netbox_ping/models.py +42 -0
  13. netbox_ping-0.2/netbox_ping/navigation.py +17 -0
  14. netbox_ping-0.2/netbox_ping/plugin.py +83 -0
  15. netbox_ping-0.2/netbox_ping/signals.py +48 -0
  16. netbox_ping-0.2/netbox_ping/tables.py +22 -0
  17. netbox_ping-0.2/netbox_ping/template_content.py +15 -0
  18. netbox_ping-0.2/netbox_ping/template_extensions.py +15 -0
  19. netbox_ping-0.2/netbox_ping/templates/netbox_ping/compare_interfaces_button.html +4 -0
  20. netbox_ping-0.2/netbox_ping/templates/netbox_ping/interface_comparison.html +161 -0
  21. netbox_ping-0.2/netbox_ping/templates/netbox_ping/number_of_interfaces_panel.html +21 -0
  22. netbox_ping-0.2/netbox_ping/templates/netbox_ping/ping_home.html +169 -0
  23. netbox_ping-0.2/netbox_ping/templates/netbox_ping/ping_subnet_button.html +11 -0
  24. netbox_ping-0.2/netbox_ping/templates/netbox_ping/prefix_button.html +4 -0
  25. netbox_ping-0.2/netbox_ping/templates/netbox_ping/prefix_content.html +11 -0
  26. netbox_ping-0.2/netbox_ping/urls.py +16 -0
  27. netbox_ping-0.2/netbox_ping/utils.py +37 -0
  28. netbox_ping-0.2/netbox_ping/views.py +466 -0
  29. netbox_ping-0.2/netbox_ping.egg-info/PKG-INFO +176 -0
  30. netbox_ping-0.2/netbox_ping.egg-info/SOURCES.txt +34 -0
  31. netbox_ping-0.2/netbox_ping.egg-info/dependency_links.txt +1 -0
  32. netbox_ping-0.2/netbox_ping.egg-info/not-zip-safe +1 -0
  33. netbox_ping-0.2/netbox_ping.egg-info/top_level.txt +1 -0
  34. netbox_ping-0.2/pyproject.toml +3 -0
  35. netbox_ping-0.2/setup.cfg +4 -0
  36. netbox_ping-0.2/setup.py +24 -0
@@ -0,0 +1,5 @@
1
+ include LICENSE
2
+ include README.md
3
+ recursive-include netbox_ping/templates *
4
+ recursive-include netbox_ping/static *
5
+ recursive-include netbox_ping/migrations *
@@ -0,0 +1,176 @@
1
+ Metadata-Version: 2.2
2
+ Name: netbox-ping
3
+ Version: 0.2
4
+ Summary: A NetBox plugin for pinging and discovering IPs
5
+ Home-page: https://github.com/yourusername/netbox-ping
6
+ Author: Christian Rose
7
+ License: Apache 2.0
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Framework :: Django
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.8
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Description-Content-Type: text/markdown
15
+ Dynamic: author
16
+ Dynamic: classifier
17
+ Dynamic: description
18
+ Dynamic: description-content-type
19
+ Dynamic: home-page
20
+ Dynamic: license
21
+ Dynamic: summary
22
+
23
+ # NetBox Ping Plugin
24
+
25
+ A NetBox plugin for pinging and discovering IPs in your network.
26
+
27
+ ## Features
28
+ - Ping IPs and subnets directly from NetBox
29
+ - Auto-discover new IPs
30
+ - Track IP status with custom fields and tags
31
+ - Bulk scan operations
32
+ - Dark mode compatible UI
33
+
34
+ ## Installation
35
+ ```bash
36
+ pip install netbox-ping
37
+ ```
38
+
39
+ ## Configuration
40
+ Add to your `configuration.py`:
41
+ ```python
42
+ PLUGINS = ['netbox_ping']
43
+
44
+ PLUGINS_CONFIG = {
45
+ 'netbox_ping': {
46
+ 'exclude_virtual_interfaces': True
47
+ }
48
+ }
49
+ ```
50
+
51
+ ## Usage
52
+ 1. Install the plugin
53
+ 2. Navigate to Plugins > NetBox Ping
54
+ 3. Click "Create Required Fields & Tags"
55
+ 4. Start scanning your networks!
56
+
57
+ ## Requirements
58
+
59
+ - NetBox 4.0 or later
60
+ - Python 3.8 or later
61
+ - `ping` command available on the system
62
+
63
+ ## Installation
64
+
65
+ ### Package Installation
66
+
67
+ 1. Install the package from your NetBox installation path:
68
+ ```bash
69
+ source /opt/netbox/venv/bin/activate
70
+ cd /opt/netbox
71
+ pip install git+https://github.com/DenDanskeMine/netbox-prefix-pinger.git
72
+ ```
73
+
74
+ ### Enable the Plugin
75
+
76
+ 2. Add the plugin to `PLUGINS` in `/opt/netbox/netbox/netbox/configuration.py`:
77
+ ```python
78
+ PLUGINS = [
79
+ 'netbox_ping',
80
+ ]
81
+ ```
82
+
83
+ ### Run Migrations
84
+
85
+ 3. Apply database migrations:
86
+ ```bash
87
+ cd /opt/netbox
88
+ python3 manage.py migrate
89
+ ```
90
+
91
+ ### Collect Static Files
92
+
93
+ 4. Collect static files:
94
+ ```bash
95
+ python3 manage.py collectstatic
96
+ ```
97
+
98
+ ### Restart NetBox
99
+
100
+ 5. Restart the NetBox service:
101
+ ```bash
102
+ sudo systemctl restart netbox
103
+ ```
104
+
105
+ ## Usage
106
+
107
+ 1. Navigate to the "Plugins" menu in NetBox
108
+ 2. Select "Network Tools" from the dropdown
109
+ 3. You'll see a list of all prefixes in your NetBox instance
110
+ 4. Two actions are available for each prefix:
111
+ - **Check Status**: Checks all existing IPs in the prefix
112
+ - **Scan Subnet**: Discovers and adds new active IPs
113
+
114
+ ### Status Indicators
115
+
116
+ - 🟢 Online Tag: IP is responding to ping
117
+ - 🔴 Offline Tag: IP is not responding
118
+ - Custom Field "Up_Down": Boolean indicator of IP status
119
+
120
+ ## Configuration
121
+
122
+ No additional configuration is required. The plugin will automatically:
123
+ - Create required custom fields
124
+ - Create online/offline tags
125
+ - Set up necessary permissions
126
+
127
+ ## Permissions
128
+
129
+ Users need the following permissions to use the plugin:
130
+ - `ipam.view_prefix`
131
+ - `ipam.view_ipaddress`
132
+
133
+ ## Development
134
+
135
+ To set up a development environment:
136
+
137
+ 1. Clone the repository:
138
+ ```bash
139
+ git clone https://github.com/yourusername/netbox-ping.git
140
+ cd netbox-ping
141
+ ```
142
+
143
+ 2. Create a virtual environment:
144
+ ```bash
145
+ python3 -m venv venv
146
+ source venv/bin/activate
147
+ ```
148
+
149
+ 3. Install development dependencies:
150
+ ```bash
151
+ pip install -e .
152
+ ```
153
+
154
+ ## Contributing
155
+
156
+ Contributions are welcome! Please feel free to submit a Pull Request.
157
+
158
+ ## License
159
+
160
+ This project is licensed under the MIT License - see the LICENSE file for details.
161
+
162
+ ## Support
163
+
164
+ If you have any questions or need help, please:
165
+ 1. Open an issue on GitHub
166
+ 2. Check existing issues for answers
167
+ 3. Contact the maintainer
168
+
169
+ ## Acknowledgments
170
+
171
+ - Built for NetBox (https://github.com/netbox-community/netbox)
172
+ - Inspired by the need for simple IP status tracking, this is my first plugin for NetBox.
173
+ - I'm not a good python developer, so this is probably not the best way to do this.
174
+ - The plugin `netbox-interface-synchronization` gave me a lot of inspiration, code wise, as the offical NetBox development repo had some issues, i couldn't get around.
175
+ - The plugin [netbox-interface-synchronization](https://github.com/NetTech2001/netbox-interface-synchronization/tree/main) is a great plugin, and i recommend using it if you need to synchronize interfaces.
176
+
@@ -0,0 +1,154 @@
1
+ # NetBox Ping Plugin
2
+
3
+ A NetBox plugin for pinging and discovering IPs in your network.
4
+
5
+ ## Features
6
+ - Ping IPs and subnets directly from NetBox
7
+ - Auto-discover new IPs
8
+ - Track IP status with custom fields and tags
9
+ - Bulk scan operations
10
+ - Dark mode compatible UI
11
+
12
+ ## Installation
13
+ ```bash
14
+ pip install netbox-ping
15
+ ```
16
+
17
+ ## Configuration
18
+ Add to your `configuration.py`:
19
+ ```python
20
+ PLUGINS = ['netbox_ping']
21
+
22
+ PLUGINS_CONFIG = {
23
+ 'netbox_ping': {
24
+ 'exclude_virtual_interfaces': True
25
+ }
26
+ }
27
+ ```
28
+
29
+ ## Usage
30
+ 1. Install the plugin
31
+ 2. Navigate to Plugins > NetBox Ping
32
+ 3. Click "Create Required Fields & Tags"
33
+ 4. Start scanning your networks!
34
+
35
+ ## Requirements
36
+
37
+ - NetBox 4.0 or later
38
+ - Python 3.8 or later
39
+ - `ping` command available on the system
40
+
41
+ ## Installation
42
+
43
+ ### Package Installation
44
+
45
+ 1. Install the package from your NetBox installation path:
46
+ ```bash
47
+ source /opt/netbox/venv/bin/activate
48
+ cd /opt/netbox
49
+ pip install git+https://github.com/DenDanskeMine/netbox-prefix-pinger.git
50
+ ```
51
+
52
+ ### Enable the Plugin
53
+
54
+ 2. Add the plugin to `PLUGINS` in `/opt/netbox/netbox/netbox/configuration.py`:
55
+ ```python
56
+ PLUGINS = [
57
+ 'netbox_ping',
58
+ ]
59
+ ```
60
+
61
+ ### Run Migrations
62
+
63
+ 3. Apply database migrations:
64
+ ```bash
65
+ cd /opt/netbox
66
+ python3 manage.py migrate
67
+ ```
68
+
69
+ ### Collect Static Files
70
+
71
+ 4. Collect static files:
72
+ ```bash
73
+ python3 manage.py collectstatic
74
+ ```
75
+
76
+ ### Restart NetBox
77
+
78
+ 5. Restart the NetBox service:
79
+ ```bash
80
+ sudo systemctl restart netbox
81
+ ```
82
+
83
+ ## Usage
84
+
85
+ 1. Navigate to the "Plugins" menu in NetBox
86
+ 2. Select "Network Tools" from the dropdown
87
+ 3. You'll see a list of all prefixes in your NetBox instance
88
+ 4. Two actions are available for each prefix:
89
+ - **Check Status**: Checks all existing IPs in the prefix
90
+ - **Scan Subnet**: Discovers and adds new active IPs
91
+
92
+ ### Status Indicators
93
+
94
+ - 🟢 Online Tag: IP is responding to ping
95
+ - 🔴 Offline Tag: IP is not responding
96
+ - Custom Field "Up_Down": Boolean indicator of IP status
97
+
98
+ ## Configuration
99
+
100
+ No additional configuration is required. The plugin will automatically:
101
+ - Create required custom fields
102
+ - Create online/offline tags
103
+ - Set up necessary permissions
104
+
105
+ ## Permissions
106
+
107
+ Users need the following permissions to use the plugin:
108
+ - `ipam.view_prefix`
109
+ - `ipam.view_ipaddress`
110
+
111
+ ## Development
112
+
113
+ To set up a development environment:
114
+
115
+ 1. Clone the repository:
116
+ ```bash
117
+ git clone https://github.com/yourusername/netbox-ping.git
118
+ cd netbox-ping
119
+ ```
120
+
121
+ 2. Create a virtual environment:
122
+ ```bash
123
+ python3 -m venv venv
124
+ source venv/bin/activate
125
+ ```
126
+
127
+ 3. Install development dependencies:
128
+ ```bash
129
+ pip install -e .
130
+ ```
131
+
132
+ ## Contributing
133
+
134
+ Contributions are welcome! Please feel free to submit a Pull Request.
135
+
136
+ ## License
137
+
138
+ This project is licensed under the MIT License - see the LICENSE file for details.
139
+
140
+ ## Support
141
+
142
+ If you have any questions or need help, please:
143
+ 1. Open an issue on GitHub
144
+ 2. Check existing issues for answers
145
+ 3. Contact the maintainer
146
+
147
+ ## Acknowledgments
148
+
149
+ - Built for NetBox (https://github.com/netbox-community/netbox)
150
+ - Inspired by the need for simple IP status tracking, this is my first plugin for NetBox.
151
+ - I'm not a good python developer, so this is probably not the best way to do this.
152
+ - The plugin `netbox-interface-synchronization` gave me a lot of inspiration, code wise, as the offical NetBox development repo had some issues, i couldn't get around.
153
+ - The plugin [netbox-interface-synchronization](https://github.com/NetTech2001/netbox-interface-synchronization/tree/main) is a great plugin, and i recommend using it if you need to synchronize interfaces.
154
+
@@ -0,0 +1,23 @@
1
+ from netbox.plugins import PluginConfig
2
+
3
+ class Config(PluginConfig):
4
+ name = 'netbox_ping'
5
+ verbose_name = 'NetBox Ping'
6
+ description = 'Ping IPs and subnets'
7
+ version = '0.2'
8
+ author = 'Christian Rose'
9
+ default_settings = {
10
+ 'exclude_virtual_interfaces': True
11
+ }
12
+
13
+ # Register the custom table
14
+ ipaddress_table = 'netbox_ping.tables.CustomIPAddressTable'
15
+
16
+ # Define which models support custom fields
17
+ custom_field_models = ['ipaddress']
18
+
19
+ # API settings
20
+ base_url = 'netbox-ping'
21
+ default_app_config = 'netbox_ping.apps.NetBoxPingConfig'
22
+
23
+ config = Config
@@ -0,0 +1,43 @@
1
+ from extras.choices import CustomFieldTypeChoices
2
+ from extras.models import CustomField, Tag
3
+ from django.db.models import Q
4
+
5
+ def create_custom_fields_and_tags():
6
+ """Create custom fields and tags needed by the plugin"""
7
+
8
+ # Create Up_Down custom field
9
+ custom_field, created = CustomField.objects.get_or_create(
10
+ name='Up_Down',
11
+ defaults={
12
+ 'type': CustomFieldTypeChoices.TYPE_BOOLEAN,
13
+ 'label': 'Up/Down Status',
14
+ 'description': 'Indicates if the IP is responding to ping',
15
+ 'required': False,
16
+ 'filter_logic': 'exact'
17
+ }
18
+ )
19
+
20
+ # Add the custom field to IPAddress content type if not already added
21
+ if created:
22
+ custom_field.content_types.add(
23
+ ContentType.objects.get(app_label='ipam', model='ipaddress')
24
+ )
25
+
26
+ # Create online/offline tags
27
+ Tag.objects.get_or_create(
28
+ name='online',
29
+ slug='online',
30
+ defaults={
31
+ 'description': 'IP is responding to ping',
32
+ 'color': '4CAF50' # Green color
33
+ }
34
+ )
35
+
36
+ Tag.objects.get_or_create(
37
+ name='offline',
38
+ slug='offline',
39
+ defaults={
40
+ 'description': 'IP is not responding to ping',
41
+ 'color': 'F44336' # Red color
42
+ }
43
+ )
@@ -0,0 +1,13 @@
1
+ from django import forms
2
+ from netbox.forms import NetBoxModelForm
3
+ from .models import PluginSettingsModel
4
+
5
+
6
+ class InterfaceComparisonForm(forms.Form):
7
+ add_to_device = forms.BooleanField(required=False)
8
+ remove_from_device = forms.BooleanField(required=False)
9
+
10
+ class PluginSettingsForm(NetBoxModelForm):
11
+ class Meta:
12
+ model = PluginSettingsModel
13
+ fields = ('update_tags',)
@@ -0,0 +1,6 @@
1
+ from extras.plugins import PluginTemplateExtension
2
+ from . import tables
3
+
4
+ def override_ipaddress_table():
5
+ """Override the default IP address table to include Up_Down status"""
6
+ return tables.CustomIPAddressTable
@@ -0,0 +1,30 @@
1
+ from django.db import migrations, models
2
+ import django.db.models.deletion
3
+ import netbox.models.features
4
+
5
+
6
+ class Migration(migrations.Migration):
7
+ initial = True
8
+
9
+ dependencies = [
10
+ ('extras', '0001_initial'), # Base NetBox dependency
11
+ ]
12
+
13
+ operations = [
14
+ migrations.CreateModel(
15
+ name='PluginSettingsModel',
16
+ fields=[
17
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
18
+ ('created', models.DateTimeField(auto_now_add=True)),
19
+ ('last_updated', models.DateTimeField(auto_now=True)),
20
+ ('custom_field_data', models.JSONField(blank=True, default=dict, null=True)),
21
+ ('update_tags', models.BooleanField(default=True, help_text='Whether to update tags when scanning IPs', verbose_name='Update Tags')),
22
+ ],
23
+ options={
24
+ 'verbose_name': 'Plugin Settings',
25
+ 'verbose_name_plural': 'Plugin Settings',
26
+ 'ordering': ['pk'],
27
+ },
28
+ bases=(netbox.models.features.ChangeLoggingMixin, models.Model),
29
+ ),
30
+ ]
File without changes
@@ -0,0 +1,42 @@
1
+ from django.db import models
2
+ from netbox.models import NetBoxModel
3
+ from utilities.choices import ChoiceSet
4
+
5
+ class PluginSettingsModel(NetBoxModel):
6
+ """Store plugin settings"""
7
+ class Meta:
8
+ verbose_name = 'Plugin Settings'
9
+ verbose_name_plural = 'Plugin Settings'
10
+ ordering = ['pk']
11
+
12
+ # Required fields from NetBoxModel
13
+ id = models.BigAutoField(
14
+ primary_key=True
15
+ )
16
+ created = models.DateTimeField(
17
+ auto_now_add=True
18
+ )
19
+ last_updated = models.DateTimeField(
20
+ auto_now=True
21
+ )
22
+ custom_field_data = models.JSONField(
23
+ blank=True,
24
+ null=True,
25
+ default=dict
26
+ )
27
+
28
+ # Our custom fields
29
+ update_tags = models.BooleanField(
30
+ default=True,
31
+ verbose_name='Update Tags',
32
+ help_text='Whether to update tags when scanning IPs'
33
+ )
34
+
35
+ def __str__(self):
36
+ return "NetBox Ping Settings"
37
+
38
+ @classmethod
39
+ def get_settings(cls):
40
+ """Get or create settings"""
41
+ settings, _ = cls.objects.get_or_create(pk=1)
42
+ return settings
@@ -0,0 +1,17 @@
1
+ from netbox.plugins import PluginMenuItem, PluginMenuButton
2
+
3
+ menu_items = (
4
+ PluginMenuItem(
5
+ link='plugins:netbox_ping:ping_home',
6
+ link_text='Network Tools',
7
+ permissions=('ipam.view_prefix',),
8
+ buttons=(
9
+ PluginMenuButton(
10
+ link='plugins:netbox_ping:ping_home',
11
+ title='Network Tools',
12
+ icon_class='mdi mdi-lan',
13
+ permissions=('ipam.view_prefix',),
14
+ ),
15
+ ),
16
+ ),
17
+ )
@@ -0,0 +1,83 @@
1
+ from django.contrib.contenttypes.models import ContentType
2
+ from extras.api.serializers import CustomFieldSerializer, TagSerializer
3
+ from extras.models import CustomField, Tag
4
+ from ipam.models import IPAddress
5
+ from rest_framework.exceptions import ValidationError
6
+
7
+ def initialize_plugin():
8
+ """Initialize plugin custom fields and tags using the API"""
9
+
10
+ # Get ContentType ID for IPAddress
11
+ ipaddress_ct_id = ContentType.objects.get_for_model(IPAddress).id
12
+
13
+ # Create Up_Down custom field
14
+ up_down_data = {
15
+ 'name': 'Up_Down',
16
+ 'type': 'boolean',
17
+ 'label': 'Up/Down Status',
18
+ 'description': 'Indicates if the IP is responding to ping',
19
+ 'required': False,
20
+ 'filter_logic': 'exact',
21
+ 'ui_visible': 'always',
22
+ 'ui_editable': 'yes',
23
+ 'is_cloneable': True,
24
+ 'weight': 100,
25
+ }
26
+
27
+ # Create Auto_discovered custom field
28
+ discovered_data = {
29
+ 'name': 'Auto_discovered',
30
+ 'type': 'date',
31
+ 'label': 'Auto Discovered',
32
+ 'description': 'Date when this IP was automatically discovered',
33
+ 'required': False,
34
+ 'filter_logic': 'exact',
35
+ 'ui_visible': 'always',
36
+ 'ui_editable': 'yes',
37
+ 'is_cloneable': True,
38
+ 'weight': 101,
39
+ }
40
+
41
+ # Create custom fields
42
+ for cf_data in [up_down_data, discovered_data]:
43
+ try:
44
+ custom_field = CustomField.objects.get(name=cf_data['name'])
45
+ except CustomField.DoesNotExist:
46
+ try:
47
+ custom_field = CustomField.objects.create(**cf_data)
48
+ custom_field.object_types.set([ipaddress_ct_id])
49
+ print(f"Created custom field: {custom_field.name}")
50
+ except Exception as e:
51
+ print(f"Failed to create custom field: {str(e)}")
52
+
53
+ # Create tags
54
+ tags_data = [
55
+ {
56
+ 'name': 'online',
57
+ 'slug': 'online',
58
+ 'description': 'IP is responding to ping',
59
+ 'color': '4CAF50'
60
+ },
61
+ {
62
+ 'name': 'offline',
63
+ 'slug': 'offline',
64
+ 'description': 'IP is not responding to ping',
65
+ 'color': 'F44336'
66
+ },
67
+ {
68
+ 'name': 'auto-discovered',
69
+ 'slug': 'auto-discovered',
70
+ 'description': 'IP was automatically discovered by scanning',
71
+ 'color': '2196F3' # Blue color
72
+ }
73
+ ]
74
+
75
+ for tag_data in tags_data:
76
+ try:
77
+ tag = Tag.objects.get(slug=tag_data['slug'])
78
+ except Tag.DoesNotExist:
79
+ try:
80
+ tag = Tag.objects.create(**tag_data)
81
+ print(f"Created tag: {tag.name}")
82
+ except Exception as e:
83
+ print(f"Failed to create tag: {str(e)}")
@@ -0,0 +1,48 @@
1
+ from django.contrib.contenttypes.models import ContentType
2
+ from django.apps import apps
3
+ from django.db.models.signals import post_migrate
4
+ from django.dispatch import receiver
5
+ from extras.choices import CustomFieldTypeChoices
6
+ from extras.models import CustomField, Tag
7
+
8
+ @receiver(post_migrate)
9
+ def create_custom_fields_and_tags(sender, **kwargs):
10
+ """
11
+ Create required custom fields and tags after database migrations complete
12
+ """
13
+ if sender.name == 'netbox_ping':
14
+ # Create Up_Down custom field
15
+ custom_field, _ = CustomField.objects.get_or_create(
16
+ name='Up_Down',
17
+ defaults={
18
+ 'type': CustomFieldTypeChoices.TYPE_BOOLEAN,
19
+ 'label': 'Up/Down Status',
20
+ 'description': 'Indicates if the IP is responding to ping',
21
+ 'required': False,
22
+ 'filter_logic': 'exact'
23
+ }
24
+ )
25
+
26
+ # Add the custom field to IPAddress content type
27
+ ipaddress_ct = ContentType.objects.get_for_model(apps.get_model('ipam', 'ipaddress'))
28
+ if ipaddress_ct not in custom_field.content_types.all():
29
+ custom_field.content_types.add(ipaddress_ct)
30
+
31
+ # Create online/offline tags
32
+ Tag.objects.get_or_create(
33
+ name='online',
34
+ slug='online',
35
+ defaults={
36
+ 'description': 'IP is responding to ping',
37
+ 'color': '4CAF50' # Green color
38
+ }
39
+ )
40
+
41
+ Tag.objects.get_or_create(
42
+ name='offline',
43
+ slug='offline',
44
+ defaults={
45
+ 'description': 'IP is not responding to ping',
46
+ 'color': 'F44336' # Red color
47
+ }
48
+ )
@@ -0,0 +1,22 @@
1
+ import django_tables2 as tables
2
+ from netbox.tables import NetBoxTable, columns
3
+ from ipam.models import IPAddress
4
+ from ipam.tables import IPAddressTable
5
+
6
+ class CustomIPAddressTable(IPAddressTable):
7
+ """Custom IP Address table that includes the Up_Down status"""
8
+
9
+ up_down = columns.BooleanColumn(
10
+ verbose_name='Ping Status',
11
+ accessor=tables.A('_custom_field_data__Up_Down'),
12
+ order_by='_custom_field_data__Up_Down',
13
+ )
14
+
15
+ online = columns.TagColumn(
16
+ verbose_name='Online/Offline'
17
+ )
18
+
19
+ class Meta(IPAddressTable.Meta):
20
+ model = IPAddress
21
+ fields = IPAddressTable.Meta.fields + ('up_down', 'online')
22
+ default_columns = ('address', 'status', 'up_down', 'online', 'tenant', 'assigned_object', 'description')