release: r015 compact filtered Docker inventory

This commit is contained in:
Mikei386
2026-08-22 21:34:28 +02:00
parent 37de236f5a
commit c4c04ae7af
10 changed files with 136 additions and 34 deletions
+39 -9
View File
@@ -10,7 +10,7 @@
error_reporting(E_ALL);
ini_set('display_errors', 0); // Fehler werden als JSON-RPC-Error zurückgegeben, nicht als HTML
const MUA_VERSION = '2026.08.18.r005';
const MUA_VERSION = '2026.08.22.r015';
const MUA_SERVER_NAME = 'mua';
/**
@@ -235,35 +235,59 @@ function compact_container_inspect(string $raw): string {
/**
* Container-Runtime-Zusammenfassung (docker ps + docker stats).
*/
function container_runtime_summary(): string {
function container_runtime_summary(array $args = []): string {
$state_filter = $args['state'] ?? 'all';
$include_stats = ($args['include_stats'] ?? false) === true;
$detail = $args['detail'] ?? 'compact';
$allowed_states = ['all', 'running', 'stopped', 'created', 'exited'];
if (!in_array($state_filter, $allowed_states, true)) {
throw new InvalidArgumentException('state must be one of: ' . implode(', ', $allowed_states));
}
if (!in_array($detail, ['compact', 'full'], true)) {
throw new InvalidArgumentException('detail must be compact or full');
}
$ps = docker_exec("ps -a --format '{{json .}}'");
$containers = json_lines($ps);
// docker stats für laufende Container
$running_ids = array_filter(array_map(function ($c) {
return $c['ID'] ?? '';
return (($c['State'] ?? '') === 'running') ? ($c['ID'] ?? '') : '';
}, $containers));
$stats = [];
if (!empty($running_ids)) {
if ($include_stats && !empty($running_ids)) {
$stats_raw = docker_exec("stats --no-stream --format '{{json .}}'");
foreach (json_lines($stats_raw) as $s) {
$stats[$s['ID'] ?? ''] = $s;
}
}
$state_counts = [];
foreach ($containers as $c) {
$state = (string)($c['State'] ?? 'unknown');
$state_counts[$state] = ($state_counts[$state] ?? 0) + 1;
}
$result = [];
foreach ($containers as $c) {
$state = (string)($c['State'] ?? '');
$matches = $state_filter === 'all'
|| ($state_filter === 'stopped' && $state !== 'running')
|| $state === $state_filter;
if (!$matches) continue;
$id = $c['ID'] ?? '';
$entry = [
'id' => substr($id, 0, 12),
'name' => $c['Names'] ?? '',
'image' => $c['Image'] ?? '',
'status' => $c['Status'] ?? '',
'state' => $c['State'] ?? '',
'ports' => $c['Ports'] ?? '',
];
if (isset($stats[$id])) {
if ($detail === 'full') {
$entry['id'] = substr($id, 0, 12);
$entry['image'] = $c['Image'] ?? '';
$entry['ports'] = $c['Ports'] ?? '';
}
if ($include_stats && isset($stats[$id])) {
$entry['cpu_percent'] = $stats[$id]['CPUPerc'] ?? '';
$entry['mem_usage'] = $stats[$id]['MemUsage'] ?? '';
$entry['mem_percent'] = $stats[$id]['MemPerc'] ?? '';
@@ -274,8 +298,14 @@ function container_runtime_summary(): string {
}
return json_encode([
'schema_version' => '1.0',
'schema_version' => '1.1',
'container_count' => count($result),
'returned_count' => count($result),
'total_count' => count($containers),
'running_count' => $state_counts['running'] ?? 0,
'stopped_count' => count($containers) - ($state_counts['running'] ?? 0),
'state_counts' => $state_counts,
'filter' => ['state' => $state_filter, 'include_stats' => $include_stats, 'detail' => $detail],
'containers' => $result,
], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}
+2 -2
View File
@@ -21,7 +21,7 @@ const MUA_PORT = 3002;
const MUA_BIND = '0.0.0.0';
const MUA_SESSION_TTL = 3600; // Sekunden
const MUA_SERVER_NAME = 'mua';
const MUA_VERSION = '2026.08.18.r005';
const MUA_VERSION = '2026.08.22.r015';
// ── Session-Management (in-memory) ───────────────────────────────────────
$sessions = []; // session_id => ['created' => time, 'initialized' => bool]
@@ -91,7 +91,7 @@ function call_tool(string $name, array $args): string {
switch ($name) {
// ── Docker ──────────────────────────────────────────────────────
case 'unraid_docker_list':
return container_runtime_summary();
return container_runtime_summary($args);
case 'unraid_docker_inspect':
$container = validate_name($args['container'] ?? null, 'container');
+10 -2
View File
@@ -14,8 +14,16 @@ function mua_tools(): array {
// ── Docker (14) ──────────────────────────────────────────────────
[
'name' => 'unraid_docker_list',
'description' => 'List all Docker containers with runtime stats (CPU, memory, network I/O). Returns a compact JSON summary.',
'inputSchema' => ['type' => 'object', 'properties' => new stdClass(), 'additionalProperties' => false],
'description' => "List Docker containers with authoritative server-side counts. For active containers always use state='running'. Stats are optional to keep output compact.",
'inputSchema' => [
'type' => 'object',
'properties' => [
'state' => ['type' => 'string', 'enum' => ['all', 'running', 'stopped', 'created', 'exited'], 'description' => "Use 'running' for active containers. Default: all."],
'include_stats' => ['type' => 'boolean', 'description' => 'Include live CPU, RAM and I/O statistics. Default: false.'],
'detail' => ['type' => 'string', 'enum' => ['compact', 'full'], 'description' => 'compact returns name/status/state; full also returns ID/image/ports.'],
],
'additionalProperties' => false,
],
],
[
'name' => 'unraid_docker_inspect',