Version 0.5.5.94: field type conversion, exclusion filters and value lists
- Change the data type of custom fields with stored values via a preview: values that cannot be converted need an explicit decision, the conversion runs in one transaction with row locks and a stale-preview check, old values are saved to data/backups and recorded in history. - Table filters: "!value" excludes rows, "=value" compares exactly; Excel-like value list (▾) per column in all tables. The software job list computes its value list on the server over the full job history. - Bulk edit offers custom fields with type-specific input and validation. - MeshCentral mappings: optional "value if empty" with a guard path; fallbacks are skipped when only basic data was delivered. - Deleting a field removes its translations (same name can be reused); one confirmation with the value count replaces the checkbox. - Job list filters recognize the "reinstall" action and the "software deployment" job type. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
261b4f2029
commit
40cd88871f
20 files changed
+1400
-187
No files matched your search
+47
-2
@@ -392,7 +392,13 @@ def fetch_device_summaries_for_linking() -> list[dict[str, str]]:
|
||||
raise RuntimeError("MeshCentral-Geräteliste konnte nicht geladen werden: " + detail)
|
||||
|
||||
|
||||
# False when the last fetch_devices() fell back to basic data although details were requested.
|
||||
LAST_FETCH_DETAILS_COMPLETE = True
|
||||
|
||||
|
||||
def fetch_devices(log: Callable[[str, str], None] | None = None) -> list[dict[str, Any]]:
|
||||
global LAST_FETCH_DETAILS_COMPLETE
|
||||
LAST_FETCH_DETAILS_COMPLETE = True
|
||||
log = log or (lambda level, message: None)
|
||||
cfg = load_config()["meshcentral"]
|
||||
if not cfg.get("enabled"):
|
||||
@@ -422,6 +428,8 @@ def fetch_devices(log: Callable[[str, str], None] | None = None) -> list[dict[st
|
||||
else:
|
||||
devices = _extract_devices(_parse_json_output(result.stdout))
|
||||
log("success", f"{len(devices)} Gerät(e) aus MeshCentral gelesen.")
|
||||
if use_details and not include_details:
|
||||
LAST_FETCH_DETAILS_COMPLETE = False
|
||||
return devices
|
||||
except (ValueError, json.JSONDecodeError, RuntimeError) as exc:
|
||||
attempts.append(("mit Details: " if include_details else "ohne Details: ") + str(exc))
|
||||
@@ -649,6 +657,29 @@ def _convert_mapping_value(values: list[Any], transform: str, separator: str) ->
|
||||
return None
|
||||
|
||||
|
||||
def _parent_path(path: str) -> str:
|
||||
"""Parent of every alternative of a source path: 'a.b.c|x.y' -> 'a.b|x'."""
|
||||
parents = []
|
||||
for alternative in [item.strip() for item in str(path or '').split('|') if item.strip()]:
|
||||
if '.' in alternative:
|
||||
parents.append(alternative.rsplit('.', 1)[0])
|
||||
else:
|
||||
return '' # top-level key: the device itself is the parent
|
||||
return '|'.join(parents)
|
||||
|
||||
|
||||
def _empty_value_allowed(raw: dict[str, Any], mapping: dict[str, Any]) -> bool:
|
||||
"""Only use the fallback when the device really delivered the surrounding data.
|
||||
|
||||
Otherwise a device without detail data (new agent, failed detail query)
|
||||
would be reported as e.g. 'BitLocker off'.
|
||||
"""
|
||||
guard = str(mapping.get('empty_value_guard') or '').strip() or _parent_path(str(mapping.get('source_path') or ''))
|
||||
if not guard:
|
||||
return True
|
||||
return bool(_path_values(raw, guard))
|
||||
|
||||
|
||||
def _mapped_value(raw: dict[str, Any], mapping: dict[str, Any]) -> Any:
|
||||
values = _path_values(raw, str(mapping.get('source_path') or ''))
|
||||
mode = str(mapping.get('multi_value_mode') or 'first')
|
||||
@@ -661,7 +692,10 @@ def _mapped_value(raw: dict[str, Any], mapping: dict[str, Any]) -> Any:
|
||||
'gpu_names', 'active_antivirus'
|
||||
}
|
||||
if transform in special:
|
||||
return _convert_mapping_value(values, transform, separator)
|
||||
result = _convert_mapping_value(values, transform, separator)
|
||||
if result in (None, '', [], {}) and mapping.get('empty_value') not in (None, '') and _empty_value_allowed(raw, mapping):
|
||||
return str(mapping.get('empty_value'))
|
||||
return result
|
||||
|
||||
def convert(value: Any) -> Any:
|
||||
if transform == 'integer':
|
||||
@@ -680,7 +714,12 @@ def _mapped_value(raw: dict[str, Any], mapping: dict[str, Any]) -> Any:
|
||||
converted = [convert(value) for value in values if value not in (None, '', [], {})]
|
||||
converted = [value for value in converted if value is not None]
|
||||
if not converted:
|
||||
return None
|
||||
# Optional fallback, e.g. BitLocker: the key only exists when enabled,
|
||||
# so an empty source means "off" instead of "leave the field untouched".
|
||||
empty_value = mapping.get('empty_value')
|
||||
if empty_value in (None, '') or not _empty_value_allowed(raw, mapping):
|
||||
return None
|
||||
return convert(str(empty_value))
|
||||
if mode == 'json': return converted if len(converted) > 1 else converted[0]
|
||||
if mode == 'count': return len(converted)
|
||||
if mode == 'join':
|
||||
@@ -1068,6 +1107,7 @@ def synchronize(db: Session, log: Callable[[str, str], None] | None = None, *, d
|
||||
"source_path": row.source_path, "target_field": row.target_field_name,
|
||||
"transform": row.transform, "multi_value_mode": row.multi_value_mode,
|
||||
"separator": row.separator, "enabled": row.enabled, "update_rule": row.update_rule,
|
||||
"empty_value": row.empty_value, "empty_value_guard": row.empty_value_guard,
|
||||
} for row in mapping_rows]
|
||||
mapping_rules = {row.target_field_name: row.update_rule for row in mapping_rows}
|
||||
field_definitions = {
|
||||
@@ -1112,6 +1152,11 @@ def synchronize(db: Session, log: Callable[[str, str], None] | None = None, *, d
|
||||
log("info", f"Dummy-Seriennummernfilter aktiv: {invalid_global_count} globale Werte, {invalid_manufacturer_count} Herstellerregel(n). Node-ID bleibt die stabile Geräteidentität.")
|
||||
devices = fetch_devices(log)
|
||||
run.devices_found = len(devices)
|
||||
if not LAST_FETCH_DETAILS_COMPLETE and any(item.get("empty_value") not in (None, "") for item in field_mappings):
|
||||
# Without detail data every device would look like 'value missing'.
|
||||
for item in field_mappings:
|
||||
item["empty_value"] = None
|
||||
log("warning", "MeshCentral hat nur Basisdaten geliefert: 'Wert, wenn leer' wird in diesem Lauf nicht angewendet, bestehende Werte bleiben unverändert.")
|
||||
log("info", f"Verarbeite {len(devices)} Gerät(e).")
|
||||
|
||||
# Determine serial numbers that are already ambiguous within the current
|
||||
|
||||
Reference in new issue
Block a user