Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d8fce752d2 | ||
|
|
7f04944343 | ||
|
|
894de49014 | ||
|
|
96d40b2005 |
No files matched your search
@@ -3,7 +3,7 @@
|
||||
|
||||
#define AppName "NetBox Synchronizer"
|
||||
#ifndef AppVersion
|
||||
#define AppVersion "4.23.0"
|
||||
#define AppVersion "4.24.1"
|
||||
#endif
|
||||
#define AppPublisher "Louis-Alexander Kerst"
|
||||
#define AppExeName "NetBoxSynchronizer.exe"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""NetBox Synchronizer – VMs, switches and clients from the field into NetBox."""
|
||||
|
||||
APP_NAME = "NetBox Synchronizer"
|
||||
APP_VERSION = "4.23.0"
|
||||
APP_VERSION = "4.24.1"
|
||||
APP_PUBLISHER = "Louis-Alexander Kerst"
|
||||
APP_USER_MODEL_ID = "Louis-AlexanderKerst.NetBoxSynchronizer"
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ def inventory_report(client):
|
||||
else "") if part)),
|
||||
("CPU", f"{client['cpu']} ({client.get('cores') or '?'} Kerne)" if client.get("cpu") else ""),
|
||||
("RAM", f"{client['memory'] / 1024 ** 3:.0f} GB" if client.get("memory") else ""),
|
||||
("Zuletzt angemeldet", (client.get("user") or "").strip()),
|
||||
("Erfasst", client.get("scanned_at") and time.strftime("%d.%m.%Y %H:%M", time.localtime(client["scanned_at"]))),
|
||||
):
|
||||
if value:
|
||||
@@ -56,6 +57,16 @@ def _cell(text):
|
||||
return str(text or "").replace("|", "/").replace("\n", " ").strip()
|
||||
|
||||
|
||||
def client_description(client):
|
||||
"""Short description for asset and device: UUID and the last signed-in user."""
|
||||
parts = ["Windows-Client"]
|
||||
if client.get("uuid"):
|
||||
parts.append(f"UUID {client['uuid']}")
|
||||
if (client.get("user") or "").strip():
|
||||
parts.append(f"Zuletzt angemeldet: {client['user'].strip()}")
|
||||
return "; ".join(parts)[:200]
|
||||
|
||||
|
||||
def merge_report(comments, report):
|
||||
"""Replace the managed report block in ``comments`` and keep everything written by hand."""
|
||||
comments = comments or ""
|
||||
@@ -263,7 +274,7 @@ class ClientSyncEngine:
|
||||
if len(assets) > 1:
|
||||
return [f"Asset übersprungen – {len(assets)} Assets mit der Seriennummer {serial}"]
|
||||
report_text = inventory_report(client)
|
||||
description = f"Windows-Client; UUID {client['uuid']}" if client.get("uuid") else "Windows-Client"
|
||||
description = client_description(client)
|
||||
if not assets:
|
||||
report["assets_created"] += 1
|
||||
if not dry_run:
|
||||
@@ -289,10 +300,10 @@ class ClientSyncEngine:
|
||||
updates["device"] = device.id
|
||||
if tenant_id and related_id(asset, "tenant") is None:
|
||||
updates["tenant"] = tenant_id
|
||||
if client.get("uuid") and (getattr(asset, "description", "") or "") != description:
|
||||
if (client.get("uuid") or client.get("user")) and (getattr(asset, "description", "") or "") != description:
|
||||
updates["description"] = description
|
||||
current = getattr(asset, "comments", "") or ""
|
||||
if report_text and _without_timestamp(_report_body(current)) != _without_timestamp(report_text):
|
||||
if report_text and (updates or _without_timestamp(_report_body(current)) != _without_timestamp(report_text)):
|
||||
updates["comments"] = merge_report(current, report_text)
|
||||
if not updates:
|
||||
return []
|
||||
@@ -300,7 +311,7 @@ class ClientSyncEngine:
|
||||
if not dry_run:
|
||||
asset.update(updates)
|
||||
labels = {"name": "Name", "status": "Status", "device_type": "Gerätetyp", "device": "Gerät", "tenant": "Mandant",
|
||||
"description": "UUID", "comments": "Inventarbericht"}
|
||||
"description": "Beschreibung", "comments": "Inventarbericht"}
|
||||
return ["Asset aktualisieren: " + ", ".join(labels[key] for key in updates)]
|
||||
|
||||
def software_sync(self):
|
||||
@@ -365,7 +376,8 @@ class ClientSyncEngine:
|
||||
if self.software:
|
||||
changes.extend(self._sync_software(client, None, dry_run, report))
|
||||
return changes
|
||||
payload = {"name": name, "device_type": type_id, "role": role_id, "site": site_id, "status": "active"}
|
||||
payload = {"name": name, "device_type": type_id, "role": role_id, "site": site_id, "status": "active",
|
||||
"description": client_description(client)}
|
||||
if platform_id:
|
||||
payload["platform"] = platform_id
|
||||
if serial:
|
||||
@@ -394,9 +406,13 @@ class ClientSyncEngine:
|
||||
if tenant_id and related_id(device, "tenant") is None:
|
||||
updates["tenant"] = tenant_id
|
||||
changes.append("Mandant setzen")
|
||||
description = client_description(client)
|
||||
if (client.get("uuid") or client.get("user")) and (getattr(device, "description", "") or "") != description:
|
||||
updates["description"] = description
|
||||
changes.append(f"Beschreibung → {description}")
|
||||
report_text = inventory_report(client)
|
||||
current = getattr(device, "comments", "") or ""
|
||||
if report_text and _without_timestamp(_report_body(current)) != _without_timestamp(report_text):
|
||||
if report_text and (updates or _without_timestamp(_report_body(current)) != _without_timestamp(report_text)):
|
||||
updates["comments"] = merge_report(current, report_text)
|
||||
changes.append(f"Inventarbericht aktualisieren ({len(client.get('software') or [])} Programme)")
|
||||
if updates:
|
||||
|
||||
@@ -241,9 +241,21 @@ def chassis_name(types):
|
||||
return ""
|
||||
|
||||
|
||||
def _strip_nul(value):
|
||||
"""Drop NUL characters (some installers pad registry strings with them; NetBox rejects them)."""
|
||||
if isinstance(value, str):
|
||||
return value.replace("\x00", "").strip() if "\x00" in value else value
|
||||
if isinstance(value, dict):
|
||||
return {key: _strip_nul(item) for key, item in value.items()}
|
||||
if isinstance(value, list):
|
||||
return [_strip_nul(item) for item in value]
|
||||
return value
|
||||
|
||||
|
||||
def apply_scan(row, raw, now=None):
|
||||
"""Merge the raw WinRM result into a result row."""
|
||||
row = dict(row)
|
||||
raw = _strip_nul(raw)
|
||||
row["scanned_at"] = now or time.time()
|
||||
if not raw.get("ok"):
|
||||
row["status"] = "error"
|
||||
|
||||
@@ -368,8 +368,9 @@ class ClientsPage(Page):
|
||||
self.agent_targets.setFixedHeight(52)
|
||||
grid.addWidget(label("Ziele"), 0, 0)
|
||||
grid.addWidget(self.agent_targets, 0, 1, 1, 5)
|
||||
self.agent_key = PasswordField("noch kein Schlüssel")
|
||||
self.agent_key.setReadOnly(True)
|
||||
self.agent_key = PasswordField("Schlüssel erzeugen oder vorhandenen einfügen")
|
||||
self.agent_key.setToolTip("Schlüssel bereits verteilter Agenten hier einfügen")
|
||||
self.agent_key.editingFinished.connect(self._agent_key_edited)
|
||||
grid.addWidget(label("Agent-Schlüssel"), 1, 0)
|
||||
grid.addWidget(self.agent_key, 1, 1)
|
||||
self.agent_key_new = button("Neu erzeugen", "refresh", on_click=self.new_agent_key,
|
||||
@@ -400,6 +401,17 @@ class ClientsPage(Page):
|
||||
self.agent_config.setEnabled(bool(key))
|
||||
self.agent_key_new.setText("Neu erzeugen" if key else "Schlüssel erzeugen")
|
||||
|
||||
def _agent_key_edited(self):
|
||||
if self.state.profile is None:
|
||||
return
|
||||
key = self.agent_key.text().strip()
|
||||
if key == self.state.profile.get("agent_key", ""):
|
||||
return
|
||||
self.state.edit_profile(agent_key=key)
|
||||
self._update_agent_key()
|
||||
if key:
|
||||
self.window.toast("Agent-Schlüssel übernommen.", "info")
|
||||
|
||||
def new_agent_key(self):
|
||||
if self.state.profile is None:
|
||||
return
|
||||
|
||||
+11
-1
@@ -285,7 +285,7 @@ def test_new_client_gets_an_asset_linked_to_the_device():
|
||||
device = nb.dcim.devices.records[0]
|
||||
asset = assets.created[0]
|
||||
assert asset["serial"] == "PW0K84A9" and asset["device"] == device.id and asset["status"] == "used"
|
||||
assert asset["device_type"] == device.device_type and asset["description"] == "Windows-Client; UUID 4C4C-1234"
|
||||
assert asset["device_type"] == device.device_type and asset["description"] == "Windows-Client; UUID 4C4C-1234; Zuletzt angemeldet: FIRMA\max"
|
||||
assert "| 7-Zip | 24 | |" in asset["comments"]
|
||||
|
||||
again = ClientSyncEngine(nb)
|
||||
@@ -338,3 +338,13 @@ def test_asset_gets_the_tenant_of_the_transfer_or_the_device():
|
||||
again.load_targets()
|
||||
report = again.sync([client2], 1, 2, dry_run=False)
|
||||
assert report["errors"] == [] and assets2.records[0].tenant == 9 and assets2.records[0].device == 300
|
||||
|
||||
|
||||
def test_nul_characters_are_stripped_and_user_is_in_the_report():
|
||||
from netbox_sync.core.client_sync import inventory_report
|
||||
from netbox_sync.core.clients import apply_scan
|
||||
raw = {"ok": True, "source": "agent", "name": "pc01", "user": "FIRMA\max",
|
||||
"software": [{"name": "Office", "version": "16", "publisher": "Microsoft\x00"}]}
|
||||
row = apply_scan({"name": "PC01"}, raw, now=0)
|
||||
assert row["software"][0]["publisher"] == "Microsoft"
|
||||
assert "- **Zuletzt angemeldet:** FIRMA\max" in inventory_report(row)
|
||||
Reference in new issue
Block a user