netbox-plugin-prometheus-sd 2.1.0__tar.gz → 2.2.0__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 (17) hide show
  1. {netbox_plugin_prometheus_sd-2.1.0 → netbox_plugin_prometheus_sd-2.2.0}/PKG-INFO +4 -3
  2. {netbox_plugin_prometheus_sd-2.1.0 → netbox_plugin_prometheus_sd-2.2.0}/README.md +3 -2
  3. {netbox_plugin_prometheus_sd-2.1.0 → netbox_plugin_prometheus_sd-2.2.0}/netbox_prometheus_sd/__init__.py +1 -1
  4. {netbox_plugin_prometheus_sd-2.1.0 → netbox_plugin_prometheus_sd-2.2.0}/netbox_prometheus_sd/filtersets.py +24 -3
  5. {netbox_plugin_prometheus_sd-2.1.0 → netbox_plugin_prometheus_sd-2.2.0}/netbox_prometheus_sd/tests/test_filtersets.py +21 -0
  6. {netbox_plugin_prometheus_sd-2.1.0 → netbox_plugin_prometheus_sd-2.2.0}/netbox_prometheus_sd/tests/utils.py +4 -0
  7. {netbox_plugin_prometheus_sd-2.1.0 → netbox_plugin_prometheus_sd-2.2.0}/pyproject.toml +1 -1
  8. {netbox_plugin_prometheus_sd-2.1.0 → netbox_plugin_prometheus_sd-2.2.0}/LICENSE +0 -0
  9. {netbox_plugin_prometheus_sd-2.1.0 → netbox_plugin_prometheus_sd-2.2.0}/netbox_prometheus_sd/api/__init__.py +0 -0
  10. {netbox_plugin_prometheus_sd-2.1.0 → netbox_plugin_prometheus_sd-2.2.0}/netbox_prometheus_sd/api/serializers.py +0 -0
  11. {netbox_plugin_prometheus_sd-2.1.0 → netbox_plugin_prometheus_sd-2.2.0}/netbox_prometheus_sd/api/urls.py +0 -0
  12. {netbox_plugin_prometheus_sd-2.1.0 → netbox_plugin_prometheus_sd-2.2.0}/netbox_prometheus_sd/api/utils.py +0 -0
  13. {netbox_plugin_prometheus_sd-2.1.0 → netbox_plugin_prometheus_sd-2.2.0}/netbox_prometheus_sd/api/views.py +0 -0
  14. {netbox_plugin_prometheus_sd-2.1.0 → netbox_plugin_prometheus_sd-2.2.0}/netbox_prometheus_sd/tests/__init__.py +0 -0
  15. {netbox_plugin_prometheus_sd-2.1.0 → netbox_plugin_prometheus_sd-2.2.0}/netbox_prometheus_sd/tests/test_api.py +0 -0
  16. {netbox_plugin_prometheus_sd-2.1.0 → netbox_plugin_prometheus_sd-2.2.0}/netbox_prometheus_sd/tests/test_serializers.py +0 -0
  17. {netbox_plugin_prometheus_sd-2.1.0 → netbox_plugin_prometheus_sd-2.2.0}/netbox_prometheus_sd/tests/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: netbox-plugin-prometheus-sd
3
- Version: 2.1.0
3
+ Version: 2.2.0
4
4
  Summary: A Netbox plugin to provide Netbox entires to Prometheus HTTP service discovery
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -84,8 +84,9 @@ GET /api/plugins/prometheus-sd/ip-addresses/ Get a list of ip in
84
84
 
85
85
  #### Extended services filters
86
86
 
87
- Apart from standard Netbox filters, services endpoint also supports `tenant=<slug>` or `tenant_id=<id>` parameters.
88
- The lookup is only executed against the `tenant` attribute of the object associated with the service.
87
+ Apart from standard Netbox filters, services endpoint also supports `tenant=<slug>` or `tenant_id=<id>`, and
88
+ `site=<slug>` or `site_id=<id>` parameters. The lookup is only executed against the `tenant`/`site` attribute of the
89
+ object associated with the service.
89
90
 
90
91
  #### Filtering and response size
91
92
 
@@ -66,8 +66,9 @@ GET /api/plugins/prometheus-sd/ip-addresses/ Get a list of ip in
66
66
 
67
67
  #### Extended services filters
68
68
 
69
- Apart from standard Netbox filters, services endpoint also supports `tenant=<slug>` or `tenant_id=<id>` parameters.
70
- The lookup is only executed against the `tenant` attribute of the object associated with the service.
69
+ Apart from standard Netbox filters, services endpoint also supports `tenant=<slug>` or `tenant_id=<id>`, and
70
+ `site=<slug>` or `site_id=<id>` parameters. The lookup is only executed against the `tenant`/`site` attribute of the
71
+ object associated with the service.
71
72
 
72
73
  #### Filtering and response size
73
74
 
@@ -1,7 +1,7 @@
1
1
  from netbox.plugins import PluginConfig
2
2
 
3
3
  # Placeholder for semantic release
4
- __VERSION__ = "2.1.0"
4
+ __VERSION__ = "2.2.0"
5
5
 
6
6
 
7
7
  class PrometheusSD(PluginConfig):
@@ -16,11 +16,11 @@ SERVICE_HAS_PORTS_FIELD = any(f.name == "ports" for f in Service._meta.get_field
16
16
 
17
17
 
18
18
  class ServiceFilterSet(NetboxServiceFilterSet):
19
- """Filter set to support tenancy over the device/VM foreign key.
19
+ """Filter set to support tenancy and site filtering over the device/VM foreign key.
20
20
 
21
- Tenancy in Netbox is very incosistent and the relationship on its own is defined across many different models. This
21
+ Tenancy in Netbox is very inconsistent and the relationship on its own is defined across many different models. This
22
22
  means that supporting all layers is nearly impossible without a stronger upstream support. For this reason only the
23
- "first level" tenancy is supported by this filter set.
23
+ "first level" tenancy is supported by the tenant filter set.
24
24
  """
25
25
 
26
26
  tenant_id = MultiValueNumberFilter(
@@ -33,6 +33,16 @@ class ServiceFilterSet(NetboxServiceFilterSet):
33
33
  label=_("Tenant (slug)"),
34
34
  )
35
35
 
36
+ site_id = MultiValueNumberFilter(
37
+ method="filter_by_site_id",
38
+ label=_("Site (ID)"),
39
+ )
40
+
41
+ site = MultiValueCharFilter(
42
+ method="filter_by_site_slug",
43
+ label=_("Site (slug)"),
44
+ )
45
+
36
46
  # Netbox < 4.7 only exposes the ports array as `port`, but Netbox's
37
47
  # test_missing_filters wants a filter named after the model field.
38
48
  # see: https://github.com/netbox-community/netbox/blob/master/netbox/utilities/testing/filtersets.py#L98
@@ -61,3 +71,14 @@ class ServiceFilterSet(NetboxServiceFilterSet):
61
71
  Q(device__tenant__slug__in=value)
62
72
  | Q(virtual_machine__tenant__slug__in=value)
63
73
  )
74
+
75
+ def filter_by_site_id(self, queryset, name, value):
76
+ return queryset.filter(
77
+ Q(device__site_id__in=value) | Q(virtual_machine__site_id__in=value)
78
+ )
79
+
80
+ def filter_by_site_slug(self, queryset, name, value):
81
+ return queryset.filter(
82
+ Q(device__site__slug__in=value)
83
+ | Q(virtual_machine__site__slug__in=value)
84
+ )
@@ -1,5 +1,6 @@
1
1
  from django.test import TestCase
2
2
 
3
+ from dcim.models.sites import Site
3
4
  from ipam.models import Service
4
5
  from tenancy.models import Tenant
5
6
 
@@ -40,3 +41,23 @@ class ServiceTestCase(TestCase, ChangeLoggedFilterSetTestMixin):
40
41
  self.assertEqual(self.filterset(params, self.queryset).qs.count(), 6)
41
42
  params = {"tenant": [tenant.slug]}
42
43
  self.assertEqual(self.filterset(params, self.queryset).qs.count(), 6)
44
+
45
+ def test_device_site(self):
46
+ # build_device_full() assigns devices directly to the "site" site.
47
+ site = Site.objects.get(slug="site")
48
+
49
+ params = {"site_id": [site.pk]}
50
+ self.assertEqual(self.filterset(params, self.queryset).qs.count(), 3)
51
+ params = {"site": [site.slug]}
52
+ self.assertEqual(self.filterset(params, self.queryset).qs.count(), 3)
53
+
54
+ def test_vm_site(self):
55
+ # build_vm_full() assigns VMs directly to the "campus-a" site, distinct
56
+ # from the devices' site, so this also verifies the filter doesn't match
57
+ # across device/VM boundaries.
58
+ site = Site.objects.get(slug="campus-a")
59
+
60
+ params = {"site_id": [site.pk]}
61
+ self.assertEqual(self.filterset(params, self.queryset).qs.count(), 3)
62
+ params = {"site": [site.slug]}
63
+ self.assertEqual(self.filterset(params, self.queryset).qs.count(), 3)
@@ -119,6 +119,10 @@ def build_vm_full(name, ip_octet=1):
119
119
  )[0]
120
120
 
121
121
  vm.tenant = build_tenant()
122
+ # Direct site assignment, independent of the cluster's own site/scope -- Netbox
123
+ # supports both, and the plugin's ServiceFilterSet only filters on this direct
124
+ # relation (see filtersets.py).
125
+ vm.site = Site.objects.get_or_create(name="Campus A", slug="campus-a")[0]
122
126
  vm.custom_field_data = build_custom_fields()
123
127
  vm.role = DeviceRole.objects.get_or_create(name="VM", slug="vm", vm_role=True)[0]
124
128
  vm.primary_ip4 = IPAddress.objects.get_or_create(
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "netbox-plugin-prometheus-sd"
3
- version = "2.1.0" # placeholder
3
+ version = "2.2.0" # placeholder
4
4
  description = "A Netbox plugin to provide Netbox entires to Prometheus HTTP service discovery"
5
5
  authors = ["Felix Peters <felix.peters@breuninger.de>"]
6
6
  license = "MIT"