fix: client software overview shows client roles only

The overview is always limited to devices whose role is listed in
software_device_roles, now "Client" and "Windows Client" by default and
matched by name or slug (windows-client from the Windows agent). The role
filter offers only these roles as checkboxes; none ticked means all client
roles, so servers can no longer appear by clearing the filter.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
MrBlakeandClaude Opus 5.5 committed 2026-11-18 14:25:12 +01:00
1 parent e24a12164c
commit 7d267ec05d
7 files changed
+59 -20

No files matched your search

+4 -3
View File
@@ -227,7 +227,7 @@ sudo systemctl restart netbox netbox-rq
| `switch_ports_enabled` | `True` | Front panel and **Export switch port usage** button for switches | | `switch_ports_enabled` | `True` | Front panel and **Export switch port usage** button for switches |
| `switch_device_roles` | `["Switch"]` | Device roles (case-insensitive) that get the front panel and export button | | `switch_device_roles` | `["Switch"]` | Device roles (case-insensitive) that get the front panel and export button |
| `software_enabled` | `True` | Client software overview and **Software** device tab (requires netbox-slm) | | `software_enabled` | `True` | Client software overview and **Software** device tab (requires netbox-slm) |
| `software_device_roles` | `["Clients"]` | Device roles (case-insensitive) that show the **Software** tab and are pre-selected in the overview | | `software_device_roles` | `["Client", "Windows Client"]` | Device roles (name or slug, case-insensitive) shown in the client software overview and given the **Software** tab |
| `wireless_trace_enabled` | `True` | Cable trace continues across wireless links (radio bridges) to the cabled port of the peer radio | | `wireless_trace_enabled` | `True` | Cable trace continues across wireless links (radio bridges) to the cabled port of the peer radio |
## Usage ## Usage
@@ -526,8 +526,9 @@ Software Übersicht* (in the menu of netbox-inventory, otherwise in the
Clicking a product shows how many clients run each version and the list of Clicking a product shows how many clients run each version and the list of
clients; clicking a version filters that list. The current selection can be clients; clicking a version filters that list. The current selection can be
exported as CSV. Without an own selection the global tenant filter applies. exported as CSV. Without an own selection the global tenant filter applies.
The device role filter is pre-set to `software_device_roles`; clearing it Only devices with a role from `software_device_roles` (name or slug, e.g.
includes all devices. `Windows Client` / `windows-client`) are included; servers and other devices
never appear. The role checkboxes narrow the selection to single client roles.
Software lists of the **NetBox Windows Agent** (mode `netbox`) and the Software lists of the **NetBox Windows Agent** (mode `netbox`) and the
**NetBox Synchronizer** desktop app (agent scan) arrive as an inventory report **NetBox Synchronizer** desktop app (agent scan) arrive as an inventory report
+2 -2
View File
@@ -1,6 +1,6 @@
from netbox.plugins import PluginConfig, get_plugin_config from netbox.plugins import PluginConfig, get_plugin_config
__version__ = "0.29.0" __version__ = "0.29.1"
class NetBoxUtilitiesConfig(PluginConfig): class NetBoxUtilitiesConfig(PluginConfig):
@@ -33,7 +33,7 @@ class NetBoxUtilitiesConfig(PluginConfig):
"switch_device_roles": ["Switch"], "switch_device_roles": ["Switch"],
"wireless_trace_enabled": True, "wireless_trace_enabled": True,
"software_enabled": True, "software_enabled": True,
"software_device_roles": ["Clients"], "software_device_roles": ["Client", "Windows Client"],
} }
middleware = [ middleware = [
"netbox_utilities.middleware.GlobalTenantFilterMiddleware", "netbox_utilities.middleware.GlobalTenantFilterMiddleware",
+14 -3
View File
@@ -4,7 +4,7 @@ import re
from dataclasses import dataclass, field from dataclasses import dataclass, field
from datetime import date from datetime import date
DEFAULT_SOFTWARE_DEVICE_ROLES = ("Clients",) DEFAULT_SOFTWARE_DEVICE_ROLES = ("Client", "Windows Client")
# Number of products in the "top products" chart. # Number of products in the "top products" chart.
TOP_PRODUCTS = 10 TOP_PRODUCTS = 10
@@ -20,10 +20,21 @@ def configured_roles(roles=None):
return {str(role).casefold() for role in (roles if roles is not None else DEFAULT_SOFTWARE_DEVICE_ROLES)} return {str(role).casefold() for role in (roles if roles is not None else DEFAULT_SOFTWARE_DEVICE_ROLES)}
def is_client_role(role, roles=None):
"""A role counts as client role if its name or slug is configured ("Windows Client" or "windows-client")."""
if role is None:
return False
configured = configured_roles(roles)
slugs = {name.replace(" ", "-") for name in configured}
return (
str(getattr(role, "name", "")).casefold() in configured
or str(getattr(role, "slug", "")).casefold() in configured | slugs
)
def supports_software(device, roles=None): def supports_software(device, roles=None):
"""Devices with a configured client role get the "Software" tab.""" """Devices with a configured client role get the "Software" tab."""
role = getattr(device, "role", None) return is_client_role(getattr(device, "role", None), roles)
return bool(role and str(getattr(role, "name", "")).casefold() in configured_roles(roles))
def version_key(name): def version_key(name):
+19 -9
View File
@@ -39,8 +39,11 @@ def installation_model():
def client_role_ids(): def client_role_ids():
roles = software.configured_roles() return [role.pk for role in DeviceRole.objects.all() if software.is_client_role(role)]
return [role.pk for role in DeviceRole.objects.all() if role.name.casefold() in roles]
def client_roles():
return DeviceRole.objects.filter(pk__in=client_role_ids()).order_by("name")
class SoftwareOverviewFilterForm(forms.Form): class SoftwareOverviewFilterForm(forms.Form):
@@ -53,9 +56,19 @@ class SoftwareOverviewFilterForm(forms.Form):
label="Mandant", label="Mandant",
query_params={"group_id": "$tenant_group_id"}, query_params={"group_id": "$tenant_group_id"},
) )
role_id = DynamicModelMultipleChoiceField(queryset=DeviceRole.objects.all(), required=False, label="Gerätrolle") # Only client roles: servers and other devices never appear in the overview.
role_id = forms.ModelMultipleChoiceField(
queryset=DeviceRole.objects.none(),
required=False,
label="Gerätrolle",
widget=forms.CheckboxSelectMultiple(attrs={"class": "form-check-input"}),
)
q = forms.CharField(required=False, label="Software suchen") q = forms.CharField(required=False, label="Software suchen")
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["role_id"].queryset = client_roles()
def group_tenant_ids(groups): def group_tenant_ids(groups):
group_ids = set() group_ids = set()
@@ -74,10 +87,7 @@ class SoftwareOverviewView(ContentTypePermissionRequiredMixin, View):
def get(self, request): def get(self, request):
params = request.GET.copy() params = request.GET.copy()
submitted = params.pop("submitted", None) is not None params.pop("submitted", None)
if not submitted and "role_id" not in params:
# First visit: clients only. An emptied role field afterwards means all roles.
params.setlist("role_id", [str(pk) for pk in client_role_ids()])
form = SoftwareOverviewFilterForm(params) form = SoftwareOverviewFilterForm(params)
form.is_valid() form.is_valid()
data = getattr(form, "cleaned_data", {}) data = getattr(form, "cleaned_data", {})
@@ -86,8 +96,8 @@ class SoftwareOverviewView(ContentTypePermissionRequiredMixin, View):
tenant_ids, scope_label = self.selected_tenant_ids(request, data) tenant_ids, scope_label = self.selected_tenant_ids(request, data)
if tenant_ids is not None: if tenant_ids is not None:
devices = devices.filter(tenant_id__in=tenant_ids) devices = devices.filter(tenant_id__in=tenant_ids)
if roles := data.get("role_id"): # Always clients only; no role ticked means all client roles.
devices = devices.filter(role__in=roles) devices = devices.filter(role__in=data.get("role_id") or client_role_ids())
installations = ( installations = (
installation_model() installation_model()
@@ -33,8 +33,15 @@
{{ form.tenant_id }} {{ form.tenant_id }}
</div> </div>
<div class="col-12 col-md-6 col-xl-2"> <div class="col-12 col-md-6 col-xl-2">
<label class="form-label" for="{{ form.role_id.id_for_label }}">Gerätrolle</label> <span class="form-label d-block">Gerätrolle</span>
{{ form.role_id }} {% for choice in form.role_id %}
<div class="form-check form-check-inline">
{{ choice.tag }}
<label class="form-check-label" for="{{ choice.id_for_label }}">{{ choice.choice_label }}</label>
</div>
{% empty %}
<div class="text-danger small">Keine Client-Rolle gefunden (<code>software_device_roles</code>)</div>
{% endfor %}
</div> </div>
<div class="col-12 col-md-6 col-xl-2"> <div class="col-12 col-md-6 col-xl-2">
<label class="form-label" for="id_q">Software suchen</label> <label class="form-label" for="id_q">Software suchen</label>
+10
View File
@@ -73,3 +73,13 @@ class SoftwareSummaryTest(SimpleTestCase):
self.assertTrue(software.supports_software(client, roles=["Clients"])) self.assertTrue(software.supports_software(client, roles=["Clients"]))
self.assertFalse(software.supports_software(server, roles=["Clients"])) self.assertFalse(software.supports_software(server, roles=["Clients"]))
self.assertFalse(software.supports_software(SimpleNamespace(role=None), roles=["Clients"])) self.assertFalse(software.supports_software(SimpleNamespace(role=None), roles=["Clients"]))
def test_default_client_roles_match_name_or_slug_but_not_servers(self):
def role(name, slug):
return SimpleNamespace(name=name, slug=slug)
roles = software.DEFAULT_SOFTWARE_DEVICE_ROLES
self.assertTrue(software.is_client_role(role("Client", "client"), roles))
self.assertTrue(software.is_client_role(role("Windows Client", "windows-client"), roles))
self.assertTrue(software.is_client_role(role("Windows-Clients", "windows-client"), roles))
self.assertFalse(software.is_client_role(role("Server", "server"), roles))
+1 -1
View File
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project] [project]
name = "netbox-utilities" name = "netbox-utilities"
version = "0.29.0" version = "0.29.1"
description = "Navigation, tenant utilities, connection VLANs, partial-width racks, disks, CPU & RAM, switch port export and bulk operations for NetBox 4.6/4.7" description = "Navigation, tenant utilities, connection VLANs, partial-width racks, disks, CPU & RAM, switch port export and bulk operations for NetBox 4.6/4.7"
readme = "README.md" readme = "README.md"
requires-python = ">=3.12" requires-python = ">=3.12"