Add narrow OpenClaw MeshCentral read-only plugin
This commit is contained in:
@@ -122,3 +122,51 @@ export class UpstreamMeshTransport {
|
||||
await this.close();
|
||||
}
|
||||
}
|
||||
|
||||
/** Parse and normalize MeshCentral's native grouped node response. */
|
||||
export function normalizeGroupedNodes(response: MeshCtrlResponse): Array<{
|
||||
id: string;
|
||||
name: string;
|
||||
meshid: string;
|
||||
online: boolean;
|
||||
device?: { os?: string; ip?: string[]; uptime?: number; lastseen?: number; agentver?: string };
|
||||
}> {
|
||||
const grouped = (response.nodes ?? {}) as Record<string, Array<{
|
||||
id?: string;
|
||||
_id?: string;
|
||||
name: string;
|
||||
meshid?: string;
|
||||
online?: boolean;
|
||||
conn?: number;
|
||||
osdesc?: string;
|
||||
ip?: string[];
|
||||
device?: { os?: string; ip?: string[]; uptime?: number; lastseen?: number; agentver?: string };
|
||||
}>>;
|
||||
|
||||
return Object.entries(grouped).flatMap(([groupId, nodes]) => nodes.map((node) => ({
|
||||
id: node.id ?? node._id ?? '',
|
||||
name: node.name,
|
||||
meshid: node.meshid ?? groupId,
|
||||
online: node.online ?? node.conn === 1,
|
||||
device: node.device ?? { os: node.osdesc, ip: node.ip },
|
||||
}))).filter((node) => node.id !== '');
|
||||
}
|
||||
|
||||
/** Normalize MeshCentral's native mesh identifiers and description field. */
|
||||
export function normalizeMeshes(response: MeshCtrlResponse): Array<{
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
}> {
|
||||
return ((response.meshes ?? []) as Array<{
|
||||
id?: string;
|
||||
_id?: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
desc?: string;
|
||||
}>).map((mesh) => ({
|
||||
id: mesh.id ?? mesh._id ?? '',
|
||||
name: mesh.name,
|
||||
description: mesh.description ?? mesh.desc,
|
||||
})).filter((mesh) => mesh.id !== '');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user