Add narrow OpenClaw MeshCentral read-only plugin

This commit is contained in:
Clawdia
2026-09-03 19:00:52 -04:00
parent ad03d23150
commit eb833dc990
11 changed files with 5480 additions and 0 deletions
@@ -0,0 +1,32 @@
import { MeshCtrlAction } from '../meshctrl-client';
import { normalizeGroupedNodes, normalizeMeshes } from '../upstream-transport';
describe('upstream MeshCentral response normalization', () => {
it('normalizes native mesh identifiers and descriptions', () => {
expect(normalizeMeshes({
action: MeshCtrlAction.Meshes,
meshes: [{ _id: 'mesh-servers', name: 'Servers', desc: 'Managed servers' }],
})).toEqual([{ id: 'mesh-servers', name: 'Servers', description: 'Managed servers' }]);
});
it('flattens grouped nodes and maps native node fields', () => {
expect(normalizeGroupedNodes({
action: MeshCtrlAction.Nodes,
nodes: {
'mesh-servers': [{
_id: 'node-pve3',
name: 'PVE3',
conn: 1,
osdesc: 'Ubuntu',
ip: ['10.10.10.13'],
}],
},
})).toEqual([{
id: 'node-pve3',
name: 'PVE3',
meshid: 'mesh-servers',
online: true,
device: { os: 'Ubuntu', ip: ['10.10.10.13'] },
}]);
});
});
+48
View File
@@ -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 !== '');
}