netbox-ping 0.3__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.3/MANIFEST.in +5 -0
  2. netbox_ping-0.3/PKG-INFO +180 -0
  3. netbox_ping-0.3/README.md +158 -0
  4. netbox_ping-0.3/netbox_ping/__init__.py +23 -0
  5. netbox_ping-0.3/netbox_ping/config.py +43 -0
  6. netbox_ping-0.3/netbox_ping/forms.py +13 -0
  7. netbox_ping-0.3/netbox_ping/hooks.py +6 -0
  8. netbox_ping-0.3/netbox_ping/migrations/0001_initial.py +30 -0
  9. netbox_ping-0.3/netbox_ping/migrations/__init__.py +0 -0
  10. netbox_ping-0.3/netbox_ping/migrations/__pycache__/0001_initial.cpython-312.pyc +0 -0
  11. netbox_ping-0.3/netbox_ping/migrations/__pycache__/__init__.cpython-312.pyc +0 -0
  12. netbox_ping-0.3/netbox_ping/models.py +42 -0
  13. netbox_ping-0.3/netbox_ping/navigation.py +17 -0
  14. netbox_ping-0.3/netbox_ping/plugin.py +83 -0
  15. netbox_ping-0.3/netbox_ping/signals.py +48 -0
  16. netbox_ping-0.3/netbox_ping/tables.py +22 -0
  17. netbox_ping-0.3/netbox_ping/template_content.py +15 -0
  18. netbox_ping-0.3/netbox_ping/template_extensions.py +15 -0
  19. netbox_ping-0.3/netbox_ping/templates/netbox_ping/compare_interfaces_button.html +4 -0
  20. netbox_ping-0.3/netbox_ping/templates/netbox_ping/interface_comparison.html +161 -0
  21. netbox_ping-0.3/netbox_ping/templates/netbox_ping/number_of_interfaces_panel.html +21 -0
  22. netbox_ping-0.3/netbox_ping/templates/netbox_ping/ping_home.html +169 -0
  23. netbox_ping-0.3/netbox_ping/templates/netbox_ping/ping_subnet_button.html +11 -0
  24. netbox_ping-0.3/netbox_ping/templates/netbox_ping/prefix_button.html +4 -0
  25. netbox_ping-0.3/netbox_ping/templates/netbox_ping/prefix_content.html +11 -0
  26. netbox_ping-0.3/netbox_ping/urls.py +16 -0
  27. netbox_ping-0.3/netbox_ping/utils.py +37 -0
  28. netbox_ping-0.3/netbox_ping/views.py +466 -0
  29. netbox_ping-0.3/netbox_ping.egg-info/PKG-INFO +180 -0
  30. netbox_ping-0.3/netbox_ping.egg-info/SOURCES.txt +34 -0
  31. netbox_ping-0.3/netbox_ping.egg-info/dependency_links.txt +1 -0
  32. netbox_ping-0.3/netbox_ping.egg-info/not-zip-safe +1 -0
  33. netbox_ping-0.3/netbox_ping.egg-info/top_level.txt +1 -0
  34. netbox_ping-0.3/pyproject.toml +3 -0
  35. netbox_ping-0.3/setup.cfg +4 -0
  36. netbox_ping-0.3/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,180 @@
1
+ Metadata-Version: 2.2
2
+ Name: netbox-ping
3
+ Version: 0.3
4
+ Summary: A NetBox plugin for pinging and discovering IPs
5
+ Home-page: https://github.com/dendanskemine/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.12
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
+ ![Python](https://img.shields.io/badge/python-3.12.3-blue.svg)
25
+ ![NetBox](https://img.shields.io/badge/netbox-4.2.2-blue.svg)
26
+ [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
27
+
28
+ A NetBox plugin for pinging and discovering IPs in your network.
29
+
30
+
31
+ ## Features
32
+ - Ping IPs and subnets directly from NetBox
33
+ - Auto-discover new IPs
34
+ - Track IP status with custom fields and tags
35
+ - Bulk scan operations
36
+ - Dark mode compatible UI
37
+
38
+ ## Installation
39
+ ```bash
40
+ pip install netbox-ping
41
+ ```
42
+
43
+ ## Configuration
44
+ Add to your `configuration.py`:
45
+ ```python
46
+ PLUGINS = ['netbox_ping']
47
+
48
+ PLUGINS_CONFIG = {
49
+ 'netbox_ping': {
50
+ 'coming_soon': True
51
+ }
52
+ }
53
+ ```
54
+
55
+ ## Usage
56
+ 1. Install the plugin
57
+ 2. Navigate to Plugins > NetBox Ping
58
+ 3. Click "Create Required Fields & Tags"
59
+ 4. Start scanning your networks!
60
+
61
+ ## Requirements
62
+
63
+ - NetBox 4.0 or later
64
+ - Python 3.8 or later
65
+ - `ping` command available on the system
66
+
67
+ ## Installation
68
+
69
+ ### Package Installation
70
+
71
+ 1. Install the package from your NetBox installation path:
72
+ ```bash
73
+ source /opt/netbox/venv/bin/activate
74
+ cd /opt/netbox
75
+ pip install git+https://github.com/DenDanskeMine/netbox-prefix-pinger.git
76
+ ```
77
+
78
+ ### Enable the Plugin
79
+
80
+ 2. Add the plugin to `PLUGINS` in `/opt/netbox/netbox/netbox/configuration.py`:
81
+ ```python
82
+ PLUGINS = [
83
+ 'netbox_ping',
84
+ ]
85
+ ```
86
+
87
+ ### Run Migrations
88
+
89
+ 3. Apply database migrations:
90
+ ```bash
91
+ cd /opt/netbox
92
+ python3 manage.py migrate
93
+ ```
94
+
95
+ ### Collect Static Files
96
+
97
+ 4. Collect static files:
98
+ ```bash
99
+ python3 manage.py collectstatic
100
+ ```
101
+
102
+ ### Restart NetBox
103
+
104
+ 5. Restart the NetBox service:
105
+ ```bash
106
+ sudo systemctl restart netbox
107
+ ```
108
+
109
+ ## Usage
110
+
111
+ 1. Navigate to the "Plugins" menu in NetBox
112
+ 2. Select "Network Tools" from the dropdown
113
+ 3. You'll see a list of all prefixes in your NetBox instance
114
+ 4. Two actions are available for each prefix:
115
+ - **Check Status**: Checks all existing IPs in the prefix
116
+ - **Scan Subnet**: Discovers and adds new active IPs
117
+
118
+ ### Status Indicators
119
+
120
+ - 🟢 Online Tag: IP is responding to ping
121
+ - 🔴 Offline Tag: IP is not responding
122
+ - Custom Field "Up_Down": Boolean indicator of IP status
123
+
124
+ ## Configuration
125
+
126
+ No additional configuration is required. The plugin will automatically:
127
+ - Create required custom fields
128
+ - Create online/offline tags
129
+ - Set up necessary permissions
130
+
131
+ ## Permissions
132
+
133
+ Users need the following permissions to use the plugin:
134
+ - `ipam.view_prefix`
135
+ - `ipam.view_ipaddress`
136
+
137
+ ## Development
138
+
139
+ To set up a development environment:
140
+
141
+ 1. Clone the repository:
142
+ ```bash
143
+ git clone https://github.com/yourusername/netbox-ping.git
144
+ cd netbox-ping
145
+ ```
146
+
147
+ 2. Create a virtual environment:
148
+ ```bash
149
+ python3 -m venv venv
150
+ source venv/bin/activate
151
+ ```
152
+
153
+ 3. Install development dependencies:
154
+ ```bash
155
+ pip install -e .
156
+ ```
157
+
158
+ ## Contributing
159
+
160
+ Contributions are welcome! Please feel free to submit a Pull Request.
161
+
162
+ ## License
163
+
164
+ This project is licensed under the MIT License - see the LICENSE file for details.
165
+
166
+ ## Support
167
+
168
+ If you have any questions or need help, please:
169
+ 1. Open an issue on GitHub
170
+ 2. Check existing issues for answers
171
+ 3. Contact the maintainer
172
+
173
+ ## Acknowledgments
174
+
175
+ - Built for NetBox (https://github.com/netbox-community/netbox)
176
+ - Inspired by the need for simple IP status tracking, this is my first plugin for NetBox.
177
+ - I'm not a good python developer, so this is probably not the best way to do this.
178
+ - 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.
179
+ - 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.
180
+
@@ -0,0 +1,158 @@
1
+ # NetBox Ping Plugin
2
+ ![Python](https://img.shields.io/badge/python-3.12.3-blue.svg)
3
+ ![NetBox](https://img.shields.io/badge/netbox-4.2.2-blue.svg)
4
+ [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
5
+
6
+ A NetBox plugin for pinging and discovering IPs in your network.
7
+
8
+
9
+ ## Features
10
+ - Ping IPs and subnets directly from NetBox
11
+ - Auto-discover new IPs
12
+ - Track IP status with custom fields and tags
13
+ - Bulk scan operations
14
+ - Dark mode compatible UI
15
+
16
+ ## Installation
17
+ ```bash
18
+ pip install netbox-ping
19
+ ```
20
+
21
+ ## Configuration
22
+ Add to your `configuration.py`:
23
+ ```python
24
+ PLUGINS = ['netbox_ping']
25
+
26
+ PLUGINS_CONFIG = {
27
+ 'netbox_ping': {
28
+ 'coming_soon': True
29
+ }
30
+ }
31
+ ```
32
+
33
+ ## Usage
34
+ 1. Install the plugin
35
+ 2. Navigate to Plugins > NetBox Ping
36
+ 3. Click "Create Required Fields & Tags"
37
+ 4. Start scanning your networks!
38
+
39
+ ## Requirements
40
+
41
+ - NetBox 4.0 or later
42
+ - Python 3.8 or later
43
+ - `ping` command available on the system
44
+
45
+ ## Installation
46
+
47
+ ### Package Installation
48
+
49
+ 1. Install the package from your NetBox installation path:
50
+ ```bash
51
+ source /opt/netbox/venv/bin/activate
52
+ cd /opt/netbox
53
+ pip install git+https://github.com/DenDanskeMine/netbox-prefix-pinger.git
54
+ ```
55
+
56
+ ### Enable the Plugin
57
+
58
+ 2. Add the plugin to `PLUGINS` in `/opt/netbox/netbox/netbox/configuration.py`:
59
+ ```python
60
+ PLUGINS = [
61
+ 'netbox_ping',
62
+ ]
63
+ ```
64
+
65
+ ### Run Migrations
66
+
67
+ 3. Apply database migrations:
68
+ ```bash
69
+ cd /opt/netbox
70
+ python3 manage.py migrate
71
+ ```
72
+
73
+ ### Collect Static Files
74
+
75
+ 4. Collect static files:
76
+ ```bash
77
+ python3 manage.py collectstatic
78
+ ```
79
+
80
+ ### Restart NetBox
81
+
82
+ 5. Restart the NetBox service:
83
+ ```bash
84
+ sudo systemctl restart netbox
85
+ ```
86
+
87
+ ## Usage
88
+
89
+ 1. Navigate to the "Plugins" menu in NetBox
90
+ 2. Select "Network Tools" from the dropdown
91
+ 3. You'll see a list of all prefixes in your NetBox instance
92
+ 4. Two actions are available for each prefix:
93
+ - **Check Status**: Checks all existing IPs in the prefix
94
+ - **Scan Subnet**: Discovers and adds new active IPs
95
+
96
+ ### Status Indicators
97
+
98
+ - 🟢 Online Tag: IP is responding to ping
99
+ - 🔴 Offline Tag: IP is not responding
100
+ - Custom Field "Up_Down": Boolean indicator of IP status
101
+
102
+ ## Configuration
103
+
104
+ No additional configuration is required. The plugin will automatically:
105
+ - Create required custom fields
106
+ - Create online/offline tags
107
+ - Set up necessary permissions
108
+
109
+ ## Permissions
110
+
111
+ Users need the following permissions to use the plugin:
112
+ - `ipam.view_prefix`
113
+ - `ipam.view_ipaddress`
114
+
115
+ ## Development
116
+
117
+ To set up a development environment:
118
+
119
+ 1. Clone the repository:
120
+ ```bash
121
+ git clone https://github.com/yourusername/netbox-ping.git
122
+ cd netbox-ping
123
+ ```
124
+
125
+ 2. Create a virtual environment:
126
+ ```bash
127
+ python3 -m venv venv
128
+ source venv/bin/activate
129
+ ```
130
+
131
+ 3. Install development dependencies:
132
+ ```bash
133
+ pip install -e .
134
+ ```
135
+
136
+ ## Contributing
137
+
138
+ Contributions are welcome! Please feel free to submit a Pull Request.
139
+
140
+ ## License
141
+
142
+ This project is licensed under the MIT License - see the LICENSE file for details.
143
+
144
+ ## Support
145
+
146
+ If you have any questions or need help, please:
147
+ 1. Open an issue on GitHub
148
+ 2. Check existing issues for answers
149
+ 3. Contact the maintainer
150
+
151
+ ## Acknowledgments
152
+
153
+ - Built for NetBox (https://github.com/netbox-community/netbox)
154
+ - Inspired by the need for simple IP status tracking, this is my first plugin for NetBox.
155
+ - I'm not a good python developer, so this is probably not the best way to do this.
156
+ - 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.
157
+ - 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.
158
+
@@ -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.3'
8
+ author = 'Christian Rose'
9
+ default_settings = {
10
+ 'coming_soon': 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')