Initial commit: Clean OpenClaw Jarvis Open-Source Template
This commit is contained in:
commit
ac4601b257
28 files changed
+7718
No files matched your search
@@ -0,0 +1,110 @@
|
||||
#!/usr/bin/env node
|
||||
"use strict";
|
||||
|
||||
const http = require("node:http");
|
||||
|
||||
const GLANCES_URL = process.env.GLANCES_URL || "http://YOUR_SERVER_IP:61208";
|
||||
|
||||
function request(pathStr) {
|
||||
return new Promise((resolve) => {
|
||||
const url = GLANCES_URL + pathStr;
|
||||
const req = http.get(url, { timeout: 8000 }, (res) => {
|
||||
let body = "";
|
||||
res.on("data", (chunk) => { body += chunk; });
|
||||
res.on("end", () => {
|
||||
try {
|
||||
resolve({ status: res.statusCode, data: JSON.parse(body) });
|
||||
} catch {
|
||||
resolve({ status: res.statusCode, raw: body });
|
||||
}
|
||||
});
|
||||
});
|
||||
req.on("error", (err) => resolve({ status: 0, error: err.message }));
|
||||
req.on("timeout", () => { req.destroy(); resolve({ status: 0, error: "Timeout" }); });
|
||||
});
|
||||
}
|
||||
|
||||
function result(text, error = false) {
|
||||
return { text: typeof text === "string" ? text : JSON.stringify(text, null, 2), error };
|
||||
}
|
||||
|
||||
async function dockerContainerList() {
|
||||
const res = await request("/api/4/containers");
|
||||
if (res.status === 200 && Array.isArray(res.data)) {
|
||||
const list = res.data.map(c => ({
|
||||
name: c.name,
|
||||
status: c.status,
|
||||
image: c.image,
|
||||
cpu_percent: c.cpu?.total !== undefined ? c.cpu.total : c.cpu_percent,
|
||||
memory_usage_mb: c.memory?.usage ? Math.round(c.memory.usage / 1024 / 1024) : undefined,
|
||||
uptime: c.uptime
|
||||
}));
|
||||
return result(list);
|
||||
}
|
||||
return result(`Container-Liste nicht verfuegbar (${res.status}): ${res.error || res.raw}`, true);
|
||||
}
|
||||
|
||||
async function dockerContainerInspect(args) {
|
||||
const target = String(args.name || "").trim().toLowerCase();
|
||||
if (!target) return result("Container-Name erforderlich.", true);
|
||||
const res = await request("/api/4/containers");
|
||||
if (res.status === 200 && Array.isArray(res.data)) {
|
||||
const found = res.data.find(c => String(c.name || "").toLowerCase() === target || String(c.id || "").startsWith(target));
|
||||
if (found) return result(found);
|
||||
return result(`Container "${target}" nicht gefunden.`, true);
|
||||
}
|
||||
return result(`Abfrage fehlgeschlagen: ${res.error || res.status}`, true);
|
||||
}
|
||||
|
||||
async function dockerContainerHealth() {
|
||||
const res = await request("/api/4/containers");
|
||||
if (res.status === 200 && Array.isArray(res.data)) {
|
||||
const total = res.data.length;
|
||||
const running = res.data.filter(c => String(c.status || "").toLowerCase().includes("running") || c.status === "OK" || c.status === "running").length;
|
||||
const stopped = total - running;
|
||||
return result({
|
||||
total_containers: total,
|
||||
running_containers: running,
|
||||
stopped_or_unhealthy: stopped,
|
||||
status: stopped === 0 ? "ALL_HEALTHY" : "DEGRADED"
|
||||
});
|
||||
}
|
||||
return result(`Health-Check fehlgeschlagen (${res.status}): ${res.error || res.raw}`, true);
|
||||
}
|
||||
|
||||
const TOOLS = [
|
||||
{ name: "docker_container_list", description: "Listet alle Docker-Container mit Status, CPU und RAM. Lesend.", inputSchema: { type: "object", properties: {}, additionalProperties: false } },
|
||||
{ name: "docker_container_inspect", description: "Zeigt Detailstatistiken eines einzelnen Docker-Containers. Lesend.", inputSchema: { type: "object", properties: { name: { type: "string" } }, required: ["name"], additionalProperties: false } },
|
||||
{ name: "docker_container_health", description: "Fuehrt ein zusammenfassendes Docker-Cluster-Health-Audit durch. Lesend.", inputSchema: { type: "object", properties: {}, additionalProperties: false } }
|
||||
];
|
||||
|
||||
async function call(name, args) {
|
||||
try {
|
||||
if (name === "docker_container_list") return await dockerContainerList();
|
||||
if (name === "docker_container_inspect") return await dockerContainerInspect(args);
|
||||
if (name === "docker_container_health") return await dockerContainerHealth();
|
||||
return result("Unbekanntes Werkzeug.", true);
|
||||
} catch (err) {
|
||||
return result(String(err.message || err), true);
|
||||
}
|
||||
}
|
||||
|
||||
function send(id, value) { process.stdout.write(JSON.stringify({ jsonrpc: "2.0", id, result: value }) + "\n"); }
|
||||
function reply(id, value) { send(id, { content: [{ type: "text", text: value.text }], isError: value.error }); }
|
||||
|
||||
let buffer = "";
|
||||
process.stdin.setEncoding("utf8");
|
||||
process.stdin.on("data", (chunk) => {
|
||||
buffer += chunk;
|
||||
let end;
|
||||
while ((end = buffer.indexOf("\n")) >= 0) {
|
||||
const line = buffer.slice(0, end).trim();
|
||||
buffer = buffer.slice(end + 1);
|
||||
if (!line) continue;
|
||||
let message;
|
||||
try { message = JSON.parse(line); } catch { continue; }
|
||||
if (message.method === "initialize") send(message.id, { protocolVersion: message.params?.protocolVersion || "2024-11-05", capabilities: { tools: {} }, serverInfo: { name: "docker-control", version: "1.0.0" } });
|
||||
else if (message.method === "tools/list") send(message.id, { tools: TOOLS });
|
||||
else if (message.method === "tools/call") call(message.params?.name, message.params?.arguments || {}).then(res => reply(message.id, res));
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user