Files
MrBlakeandClaude Opus 5.5 e24a12164c 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]>
2026-11-18 14:21:52 +01:00

71 lines
2.4 KiB
Python

from django.test import SimpleTestCase
from netbox_utilities.software_sync import (
UNKNOWN_VERSION,
SoftwareEntry,
clean_name,
has_software_report,
parse_software_report,
)
AGENT_REPORT = """Updated automatically by the NetBox Windows Agent.
## Hardware
- System: LENOVO 21MW
## Installed software (4)
- 7-Zip 23.01 (x64) 23.01 — Igor Pavlov
- Microsoft Visual C++ 2015-2022 Redistributable (x64) - 14.38.33130 14.38.33130.0 — Microsoft Corporation
- Microsoft Office Professional Plus 2024 — Microsoft Corporation
- Notepad++ (64-bit x64) 8.6.2
"""
SYNCHRONIZER_REPORT = """Handnotiz
<!-- netbox-sync:inventory -->
## Inventar (NetBox Windows Agent)
### Installierte Software (2)
| Programm | Version | Hersteller |
|---|---|---|
| Mozilla Firefox (x64 de) | 120.0 | Mozilla |
| Mozilla Firefox (x64 de) | 120.0 | Mozilla |
| Google Chrome | 119.0.6045.160 | Google LLC |
<!-- /netbox-sync:inventory -->
"""
class SoftwareReportParserTest(SimpleTestCase):
def test_agent_bullets(self):
self.assertEqual(
parse_software_report(AGENT_REPORT),
[
SoftwareEntry("7-Zip 23.01 (x64)", "23.01", "Igor Pavlov"),
SoftwareEntry(
"Microsoft Visual C++ 2015-2022 Redistributable (x64)", "14.38.33130.0", "Microsoft Corporation"
),
SoftwareEntry("Microsoft Office Professional Plus 2024", UNKNOWN_VERSION, "Microsoft Corporation"),
SoftwareEntry("Notepad++ (64-bit x64)", "8.6.2", ""),
],
)
def test_synchronizer_table_without_duplicates(self):
self.assertEqual(
parse_software_report(SYNCHRONIZER_REPORT),
[
SoftwareEntry("Mozilla Firefox (x64 de)", "120.0", "Mozilla"),
SoftwareEntry("Google Chrome", "119.0.6045.160", "Google LLC"),
],
)
def test_without_report(self):
self.assertFalse(has_software_report("Nur eine Notiz\n## Hardware"))
self.assertEqual(parse_software_report("## Hardware\n- CPU: x"), [])
self.assertTrue(has_software_report(AGENT_REPORT))
def test_clean_name_strips_appended_version_only(self):
self.assertEqual(clean_name("Foo Tool 1.2.3", "1.2.3"), "Foo Tool")
self.assertEqual(clean_name("Bar - 14.38", "14.38.1"), "Bar")
self.assertEqual(clean_name("Office 2024", "16.0"), "Office 2024")