feat: transfer client software lists from inventory reports into netbox-slm
The NetBox Windows Agent and the NetBox Synchronizer write the installed software as a report into the device comments. On every device save the report is parsed (agent bullet list and synchronizer table) and the device's netbox-slm installations are brought in line: missing products, versions and installations are created, installations that left the report are removed. Installations entered by hand are never touched. Deleting a device removes its automatic installations first, since netbox-slm protects devices with installations. The command netbox_utilities_sync_software transfers existing reports once. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
63b3b31763
commit
e24a12164c
7 files changed
+379
-2
No files matched your search
@@ -0,0 +1,41 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = (
|
||||
"Transfer the software lists of inventory reports (NetBox Windows Agent, NetBox Synchronizer) "
|
||||
"in device comments into netbox-slm installations."
|
||||
)
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument("--device", type=int, action="append", help="Only this device ID (repeatable)")
|
||||
|
||||
def handle(self, *args, **options):
|
||||
from dcim.models import Device
|
||||
from django.db.models import Q
|
||||
|
||||
from netbox_utilities.software_sync import sync_device_software
|
||||
|
||||
devices = Device.objects.filter(
|
||||
Q(comments__icontains="installed software") | Q(comments__icontains="installierte software")
|
||||
)
|
||||
if options.get("device"):
|
||||
devices = devices.filter(pk__in=options["device"])
|
||||
|
||||
total_created = total_removed = synced = 0
|
||||
for device in devices.iterator():
|
||||
try:
|
||||
created, removed = sync_device_software(device)
|
||||
except Exception as error: # noqa: BLE001 - report the device and continue with the next one
|
||||
self.stderr.write(f"{device} (#{device.pk}): {error}")
|
||||
continue
|
||||
synced += 1
|
||||
total_created += created
|
||||
total_removed += removed
|
||||
if created or removed:
|
||||
self.stdout.write(f"{device}: +{created} / -{removed}")
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(
|
||||
f"{synced} Geräte abgeglichen, {total_created} Installationen angelegt, {total_removed} entfernt."
|
||||
)
|
||||
)
|
||||
Reference in new issue
Block a user