vmware-log-insight 1.6.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. vmware_log_insight-1.6.1/.gitignore +23 -0
  2. vmware_log_insight-1.6.1/Dockerfile +14 -0
  3. vmware_log_insight-1.6.1/PKG-INFO +88 -0
  4. vmware_log_insight-1.6.1/README-CN.md +51 -0
  5. vmware_log_insight-1.6.1/README.md +66 -0
  6. vmware_log_insight-1.6.1/RELEASE_NOTES.md +31 -0
  7. vmware_log_insight-1.6.1/SECURITY.md +55 -0
  8. vmware_log_insight-1.6.1/config.example.yaml +25 -0
  9. vmware_log_insight-1.6.1/docker-compose.yml +8 -0
  10. vmware_log_insight-1.6.1/examples/mcp-configs/claude-code.json +11 -0
  11. vmware_log_insight-1.6.1/mcp_server/__init__.py +1 -0
  12. vmware_log_insight-1.6.1/mcp_server/_shared.py +61 -0
  13. vmware_log_insight-1.6.1/mcp_server/server.py +86 -0
  14. vmware_log_insight-1.6.1/mcp_server/tools/__init__.py +1 -0
  15. vmware_log_insight-1.6.1/mcp_server/tools/alerts.py +62 -0
  16. vmware_log_insight-1.6.1/mcp_server/tools/logs.py +121 -0
  17. vmware_log_insight-1.6.1/pyproject.toml +47 -0
  18. vmware_log_insight-1.6.1/server.json +21 -0
  19. vmware_log_insight-1.6.1/skills/vmware-log-insight/SKILL.md +143 -0
  20. vmware_log_insight-1.6.1/skills/vmware-log-insight/references/capabilities.md +39 -0
  21. vmware_log_insight-1.6.1/skills/vmware-log-insight/references/cli-reference.md +70 -0
  22. vmware_log_insight-1.6.1/skills/vmware-log-insight/references/setup-guide.md +97 -0
  23. vmware_log_insight-1.6.1/tests/__init__.py +0 -0
  24. vmware_log_insight-1.6.1/tests/eval/__init__.py +0 -0
  25. vmware_log_insight-1.6.1/tests/eval/regression/__init__.py +0 -0
  26. vmware_log_insight-1.6.1/tests/eval/regression/test_env_secret_obfuscation.py +102 -0
  27. vmware_log_insight-1.6.1/tests/eval/regression/test_loginsight_regressions.py +41 -0
  28. vmware_log_insight-1.6.1/tests/eval/spec/__init__.py +0 -0
  29. vmware_log_insight-1.6.1/tests/eval/spec/api_index.py +62 -0
  30. vmware_log_insight-1.6.1/tests/eval/spec/test_spec_conformance.py +102 -0
  31. vmware_log_insight-1.6.1/tests/test_connection_errors.py +91 -0
  32. vmware_log_insight-1.6.1/tests/test_constraints.py +57 -0
  33. vmware_log_insight-1.6.1/tests/test_ops_shapes.py +97 -0
  34. vmware_log_insight-1.6.1/vmware_log_insight/__init__.py +9 -0
  35. vmware_log_insight-1.6.1/vmware_log_insight/cli.py +228 -0
  36. vmware_log_insight-1.6.1/vmware_log_insight/config.py +207 -0
  37. vmware_log_insight-1.6.1/vmware_log_insight/connection.py +337 -0
  38. vmware_log_insight-1.6.1/vmware_log_insight/constraints.py +116 -0
  39. vmware_log_insight-1.6.1/vmware_log_insight/doctor.py +113 -0
  40. vmware_log_insight-1.6.1/vmware_log_insight/ops/__init__.py +1 -0
  41. vmware_log_insight-1.6.1/vmware_log_insight/ops/aggregate.py +111 -0
  42. vmware_log_insight-1.6.1/vmware_log_insight/ops/alerts.py +101 -0
  43. vmware_log_insight-1.6.1/vmware_log_insight/ops/fields.py +45 -0
  44. vmware_log_insight-1.6.1/vmware_log_insight/ops/search.py +95 -0
@@ -0,0 +1,23 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ .eggs/
8
+ *.egg
9
+ .venv/
10
+ venv/
11
+ .env
12
+ *.log
13
+ .pytest_cache/
14
+ .ruff_cache/
15
+ htmlcov/
16
+ .coverage
17
+ config.yaml
18
+ .agents/
19
+ .claude/
20
+ .trae/
21
+ skills-lock.json
22
+ tests/fixtures/token_corpus/
23
+ .DS_Store
@@ -0,0 +1,14 @@
1
+ FROM python:3.12-slim
2
+
3
+ WORKDIR /app
4
+
5
+ RUN pip install --no-cache-dir uv
6
+
7
+ COPY pyproject.toml .
8
+ COPY README.md .
9
+ COPY vmware_log_insight/ vmware_log_insight/
10
+ COPY mcp_server/ mcp_server/
11
+
12
+ RUN uv pip install --system .
13
+
14
+ CMD ["vmware-log-insight", "mcp"]
@@ -0,0 +1,88 @@
1
+ Metadata-Version: 2.4
2
+ Name: vmware-log-insight
3
+ Version: 1.6.1
4
+ Summary: VMware Aria Operations for Logs (vRealize Log Insight) read-only log search, aggregation, and alert queries — MCP + CLI
5
+ Author-email: Wei Zhou <wei-wz.zhou@broadcom.com>
6
+ License-Expression: MIT
7
+ Keywords: ai-ops,aria,log-insight,logs,mcp,siem,vmware,vrealize
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Topic :: System :: Logging
12
+ Classifier: Topic :: System :: Monitoring
13
+ Requires-Python: >=3.10
14
+ Requires-Dist: httpx<1.0,>=0.27
15
+ Requires-Dist: mcp[cli]<2.0,>=1.10
16
+ Requires-Dist: python-dotenv<2.0,>=1.0
17
+ Requires-Dist: pyyaml<7.0,>=6.0
18
+ Requires-Dist: rich<15.0,>=13.0
19
+ Requires-Dist: typer<1.0,>=0.12
20
+ Requires-Dist: vmware-policy<2.0,>=1.0.0
21
+ Description-Content-Type: text/markdown
22
+
23
+ <!-- mcp-name: io.github.zw008/vmware-log-insight -->
24
+
25
+ # VMware Log Insight
26
+
27
+ > **Disclaimer**: Community-maintained open-source project, **not affiliated with,
28
+ > endorsed by, or sponsored by VMware, Inc. or Broadcom Inc.** "VMware", "vSphere",
29
+ > and "Aria" are trademarks of Broadcom. Source is publicly auditable under the MIT license.
30
+
31
+ Read-only log search and aggregation for **VMware Aria Operations for Logs**
32
+ (formerly vRealize Log Insight) — the appliance that collects syslog from ESXi
33
+ hosts, vCenter, and VMs. The centralized-log data source for the VMware skill
34
+ family. **Strictly non-destructive**: it queries, it never writes.
35
+
36
+ ## Companion Skills
37
+
38
+ | Need | Skill |
39
+ |---|---|
40
+ | Raw centralized logs + spikes | **vmware-log-insight** (this) |
41
+ | vCenter events & alarms | [vmware-monitor](https://github.com/zw008/VMware-Monitor) |
42
+ | Metrics, anomalies, capacity | [vmware-aria](https://github.com/zw008/VMware-Aria) |
43
+ | Incident correlation / root cause | [vmware-debug](https://github.com/zw008/VMware-Debug) — feed it `log_search` output |
44
+ | VM lifecycle / operations | [vmware-aiops](https://github.com/zw008/VMware-AIops) |
45
+
46
+ ## Install
47
+
48
+ ```bash
49
+ uv tool install vmware-log-insight
50
+ mkdir -p ~/.vmware-log-insight
51
+ cp config.example.yaml ~/.vmware-log-insight/config.yaml # edit host/username/provider
52
+ echo 'VMWARE_LOG_INSIGHT_PROD_PASSWORD=...' > ~/.vmware-log-insight/.env
53
+ chmod 600 ~/.vmware-log-insight/.env
54
+ vmware-log-insight doctor
55
+ ```
56
+
57
+ ## MCP Tools (7 — all read-only)
58
+
59
+ | Tool | What |
60
+ |---|---|
61
+ | `log_search` | Search events by time window + text + filters |
62
+ | `log_aggregate` | Count/aggregate over time bins, with z-score spike detection |
63
+ | `log_fields` | List extracted fields usable in filters |
64
+ | `log_version` | Appliance version/build |
65
+ | `alert_list` / `alert_get` / `alert_history` | Query defined alerts and their trigger history |
66
+
67
+ ## Workflows
68
+
69
+ - **Find errors fast** — `vmware-log-insight search -q error -l 1h`.
70
+ - **Where did logs burst?** — `vmware-log-insight aggregate -q error -l 6h --bin-ms 300000`, read `spikes[]`, then `search` the spike window.
71
+ - **Root cause** — pass `log_search` results (plus vCenter events from vmware-monitor and metrics from vmware-aria) to **vmware-debug** `incident_timeline`.
72
+
73
+ ## Troubleshooting
74
+
75
+ - `401 on /sessions` → check username/password/`provider` and the `VMWARE_LOG_INSIGHT_<TARGET>_PASSWORD` env var.
76
+ - `503 everywhere` → appliance starting up; `doctor` reports it as a status, not a crash.
77
+ - Empty results → widen `--last`; default API port is **9543** (set `port` if different).
78
+
79
+ ## Security
80
+
81
+ Read-only by construction. Credentials in `~/.vmware-log-insight/.env` (`chmod 600`);
82
+ plaintext passwords auto-obfuscated to grep-safe `b64:` (obfuscation, not
83
+ encryption — inject from a secret manager for real secrecy). TLS on by default.
84
+ See [SECURITY.md](SECURITY.md).
85
+
86
+ ## License
87
+
88
+ MIT.
@@ -0,0 +1,51 @@
1
+ <!-- mcp-name: io.github.zw008/vmware-log-insight -->
2
+
3
+ # VMware Log Insight(中文)
4
+
5
+ > **声明**:本项目为社区维护的开源项目,**与 VMware, Inc. 或 Broadcom Inc. 无任何隶属、
6
+ > 背书或赞助关系。** "VMware"、"vSphere"、"Aria" 为 Broadcom 商标。源码以 MIT 许可证公开可审计。
7
+
8
+ 面向 **VMware Aria Operations for Logs**(原 vRealize Log Insight,集中收集 ESXi / vCenter /
9
+ VM syslog 的日志平台)的**只读**日志检索与聚合。VMware skill 家族的集中日志数据源。
10
+ **严格无破坏性**:只查询,从不写入。
11
+
12
+ ## 配套 Skill
13
+
14
+ | 需求 | Skill |
15
+ |---|---|
16
+ | 原始集中日志 + 突刺 | **vmware-log-insight**(本项目) |
17
+ | vCenter 事件与告警 | vmware-monitor |
18
+ | 指标 / 异常 / 容量 | vmware-aria |
19
+ | 故障关联 / 根因 | vmware-debug(把 `log_search` 结果喂给它) |
20
+
21
+ ## 安装
22
+
23
+ ```bash
24
+ uv tool install vmware-log-insight
25
+ mkdir -p ~/.vmware-log-insight
26
+ cp config.example.yaml ~/.vmware-log-insight/config.yaml # 填写 host/username/provider
27
+ echo 'VMWARE_LOG_INSIGHT_PROD_PASSWORD=...' > ~/.vmware-log-insight/.env
28
+ chmod 600 ~/.vmware-log-insight/.env
29
+ vmware-log-insight doctor
30
+ ```
31
+
32
+ ## MCP 工具(7 个,全只读)
33
+
34
+ `log_search`(按时间窗 + 文本 + 字段过滤检索)、`log_aggregate`(按时间桶聚合 + z-score
35
+ 突刺检测)、`log_fields`、`log_version`、`alert_list` / `alert_get` / `alert_history`。
36
+
37
+ ## 常用工作流
38
+
39
+ - **快速找错**:`vmware-log-insight search -q error -l 1h`
40
+ - **日志何时突增**:`vmware-log-insight aggregate -q error -l 6h --bin-ms 300000`,看 `spikes[]`,再 `search` 突刺时间窗
41
+ - **根因定位**:把 `log_search` 结果(连同 vmware-monitor 的 vCenter 事件、vmware-aria 的指标)交给 **vmware-debug** 的 `incident_timeline`
42
+
43
+ ## 安全
44
+
45
+ 结构上只读。凭据存于 `~/.vmware-log-insight/.env`(`chmod 600`);明文密码首次加载自动
46
+ 转为 grep 不可见的 `b64:` 形式(**是混淆不是加密**——真合规请从 secret manager 注入)。
47
+ 默认开启 TLS 校验。详见 [SECURITY.md](SECURITY.md)。
48
+
49
+ ## 许可证
50
+
51
+ MIT。
@@ -0,0 +1,66 @@
1
+ <!-- mcp-name: io.github.zw008/vmware-log-insight -->
2
+
3
+ # VMware Log Insight
4
+
5
+ > **Disclaimer**: Community-maintained open-source project, **not affiliated with,
6
+ > endorsed by, or sponsored by VMware, Inc. or Broadcom Inc.** "VMware", "vSphere",
7
+ > and "Aria" are trademarks of Broadcom. Source is publicly auditable under the MIT license.
8
+
9
+ Read-only log search and aggregation for **VMware Aria Operations for Logs**
10
+ (formerly vRealize Log Insight) — the appliance that collects syslog from ESXi
11
+ hosts, vCenter, and VMs. The centralized-log data source for the VMware skill
12
+ family. **Strictly non-destructive**: it queries, it never writes.
13
+
14
+ ## Companion Skills
15
+
16
+ | Need | Skill |
17
+ |---|---|
18
+ | Raw centralized logs + spikes | **vmware-log-insight** (this) |
19
+ | vCenter events & alarms | [vmware-monitor](https://github.com/zw008/VMware-Monitor) |
20
+ | Metrics, anomalies, capacity | [vmware-aria](https://github.com/zw008/VMware-Aria) |
21
+ | Incident correlation / root cause | [vmware-debug](https://github.com/zw008/VMware-Debug) — feed it `log_search` output |
22
+ | VM lifecycle / operations | [vmware-aiops](https://github.com/zw008/VMware-AIops) |
23
+
24
+ ## Install
25
+
26
+ ```bash
27
+ uv tool install vmware-log-insight
28
+ mkdir -p ~/.vmware-log-insight
29
+ cp config.example.yaml ~/.vmware-log-insight/config.yaml # edit host/username/provider
30
+ echo 'VMWARE_LOG_INSIGHT_PROD_PASSWORD=...' > ~/.vmware-log-insight/.env
31
+ chmod 600 ~/.vmware-log-insight/.env
32
+ vmware-log-insight doctor
33
+ ```
34
+
35
+ ## MCP Tools (7 — all read-only)
36
+
37
+ | Tool | What |
38
+ |---|---|
39
+ | `log_search` | Search events by time window + text + filters |
40
+ | `log_aggregate` | Count/aggregate over time bins, with z-score spike detection |
41
+ | `log_fields` | List extracted fields usable in filters |
42
+ | `log_version` | Appliance version/build |
43
+ | `alert_list` / `alert_get` / `alert_history` | Query defined alerts and their trigger history |
44
+
45
+ ## Workflows
46
+
47
+ - **Find errors fast** — `vmware-log-insight search -q error -l 1h`.
48
+ - **Where did logs burst?** — `vmware-log-insight aggregate -q error -l 6h --bin-ms 300000`, read `spikes[]`, then `search` the spike window.
49
+ - **Root cause** — pass `log_search` results (plus vCenter events from vmware-monitor and metrics from vmware-aria) to **vmware-debug** `incident_timeline`.
50
+
51
+ ## Troubleshooting
52
+
53
+ - `401 on /sessions` → check username/password/`provider` and the `VMWARE_LOG_INSIGHT_<TARGET>_PASSWORD` env var.
54
+ - `503 everywhere` → appliance starting up; `doctor` reports it as a status, not a crash.
55
+ - Empty results → widen `--last`; default API port is **9543** (set `port` if different).
56
+
57
+ ## Security
58
+
59
+ Read-only by construction. Credentials in `~/.vmware-log-insight/.env` (`chmod 600`);
60
+ plaintext passwords auto-obfuscated to grep-safe `b64:` (obfuscation, not
61
+ encryption — inject from a secret manager for real secrecy). TLS on by default.
62
+ See [SECURITY.md](SECURITY.md).
63
+
64
+ ## License
65
+
66
+ MIT.
@@ -0,0 +1,31 @@
1
+ ## v1.6.1 (2026-06-24) — initial release
2
+
3
+ First release of **vmware-log-insight**: read-only log search and aggregation for
4
+ VMware Aria Operations for Logs (vRealize Log Insight). The centralized-log data
5
+ source for the VMware skill family.
6
+
7
+ ### Added
8
+ - **7 read-only MCP tools**: `log_search` (time-window + text + filter event
9
+ search), `log_aggregate` (COUNT/UCOUNT/AVG/… time series with z-score spike
10
+ detection), `log_fields`, `log_version`, `alert_list`, `alert_get`,
11
+ `alert_history`.
12
+ - **Typer CLI** mirroring the tools: `search`, `aggregate`, `fields`,
13
+ `alert list/get/history`, `doctor`, `mcp`, `version`.
14
+ - **Session auth** (`POST /api/v2/sessions`, Bearer token, TTL refresh) with
15
+ **centralized HTTP error translation** to teaching `LogInsightApiError`
16
+ (status + path + fix hint); transient 502/503/504 + transport errors retry once,
17
+ 401 re-auths once, 4xx are not retried (CLAUDE.md 错误恢复三层 / 踩坑 #37).
18
+ - **Path-encoded constraint builder** with human duration shorthand ("1h", "30m",
19
+ "7d") and URL-escaped values; never issues an unbounded query (defaults to last hour).
20
+ - **`.env` password obfuscation** built in from day one: plaintext `*_PASSWORD`
21
+ auto-rewritten to grep-safe `b64:` via python-dotenv's own parser (obfuscation,
22
+ not encryption; secret-manager injection documented). CLAUDE.md 踩坑 #38.
23
+ - **Spec-conformance test** (踩坑 #36): AST-scans every HTTP call against the
24
+ official API index in `tests/eval/spec/` so a hallucinated endpoint fails CI.
25
+ - Regression evals: MCP tool exposure (踩坑 #34), read-only invariant, b64 parity.
26
+
27
+ ### Notes
28
+ - Strictly **read-only** — no ingest/write tools.
29
+ - Exact v2 response schemas are parsed defensively across documented wire variants;
30
+ confirmation against a live appliance's `/rest-api` reference is tracked in BACKLOG
31
+ (same real-hardware-verification status as VKS `/wcp/login`).
@@ -0,0 +1,55 @@
1
+ # Security Policy
2
+
3
+ ## Disclaimer
4
+
5
+ This is a community-maintained open-source project and is **not affiliated with,
6
+ endorsed by, or sponsored by VMware, Inc. or Broadcom Inc.** "VMware", "vSphere",
7
+ and "Aria" are trademarks of Broadcom. Source code is publicly auditable at
8
+ [github.com/zw008/VMware-Log-Insight](https://github.com/zw008/VMware-Log-Insight)
9
+ under the MIT license.
10
+
11
+ ## Reporting Vulnerabilities
12
+
13
+ Report security issues via a GitHub private security advisory on the repository,
14
+ or by email to the maintainer. Please do not open public issues for security bugs.
15
+
16
+ ## Security Design
17
+
18
+ ### Read-only by construction
19
+ This skill exposes **no write tools**. It only queries the Log Insight appliance
20
+ (events, aggregations, fields, alerts); it cannot ingest, edit, or delete logs or
21
+ alerts. There is no destructive surface to gate.
22
+
23
+ ### Credential management
24
+ - Passwords are loaded from `~/.vmware-log-insight/.env` (`chmod 600`), never from
25
+ `config.yaml` and never via MCP messages.
26
+ - Per-target convention: `VMWARE_LOG_INSIGHT_<TARGET>_PASSWORD`.
27
+ - **At-rest obfuscation**: plaintext `*_PASSWORD` values in `.env` are auto-rewritten
28
+ to a grep-safe `b64:` form on first load (via python-dotenv's own parser, so the
29
+ stored value never drifts). This is **obfuscation, not encryption** — for real
30
+ secrecy, inject from a secret manager (Vault/CyberArk/AWS Secrets Manager/K8s
31
+ Secret) into the env var at process start instead of storing `.env`.
32
+
33
+ ### SSL/TLS verification
34
+ On by default (`verify_ssl: true`). Disable only for self-signed lab appliances.
35
+
36
+ ### Transitive dependencies
37
+ Depends on `vmware-policy` (shared audit + `@vmware_tool` decorator + `sanitize`).
38
+ Read-tool calls are recorded to the shared audit DB (`~/.vmware/audit.db`).
39
+
40
+ ### Prompt-injection protection
41
+ All text returned from the appliance passes through `sanitize()` (truncation +
42
+ C0/C1 control-character stripping) before reaching the agent.
43
+
44
+ ## Static Analysis
45
+
46
+ ```bash
47
+ uvx bandit -r vmware_log_insight/ mcp_server/
48
+ ```
49
+
50
+ Release bar: 0 Medium-or-higher severity findings.
51
+
52
+ ## Supported Versions
53
+
54
+ The latest released version receives security fixes. Versions are kept aligned
55
+ across the VMware skill family.
@@ -0,0 +1,25 @@
1
+ # VMware Log Insight (Aria Operations for Logs) Configuration
2
+ # Copy to ~/.vmware-log-insight/config.yaml and edit
3
+
4
+ targets:
5
+ prod:
6
+ host: loginsight.example.com
7
+ username: admin
8
+ port: 9543 # public API port (default 9543)
9
+ verify_ssl: true
10
+ provider: Local # Local | ActiveDirectory | <vIDM provider name>
11
+ lab:
12
+ host: 10.0.0.50
13
+ username: admin
14
+ port: 9543
15
+ verify_ssl: false
16
+ provider: Local
17
+
18
+ default_target: prod
19
+
20
+ # Passwords are loaded from environment variables (never stored here):
21
+ # VMWARE_LOG_INSIGHT_PROD_PASSWORD=xxx
22
+ # VMWARE_LOG_INSIGHT_LAB_PASSWORD=xxx
23
+ # Or from ~/.vmware-log-insight/.env (chmod 600). Plaintext passwords there are
24
+ # auto-rewritten to a grep-safe b64: form on first load (obfuscation, NOT
25
+ # encryption). For real at-rest secrecy, inject from a secret manager instead.
@@ -0,0 +1,8 @@
1
+ services:
2
+ vmware-log-insight-mcp:
3
+ build: .
4
+ volumes:
5
+ - ~/.vmware-log-insight:/root/.vmware-log-insight:ro
6
+ environment:
7
+ - VMWARE_LOG_INSIGHT_CONFIG=/root/.vmware-log-insight/config.yaml
8
+ stdin_open: true
@@ -0,0 +1,11 @@
1
+ {
2
+ "mcpServers": {
3
+ "vmware-log-insight": {
4
+ "command": "uvx",
5
+ "args": ["--from", "vmware-log-insight", "vmware-log-insight-mcp"],
6
+ "env": {
7
+ "VMWARE_LOG_INSIGHT_CONFIG": "~/.vmware-log-insight/config.yaml"
8
+ }
9
+ }
10
+ }
11
+ }
@@ -0,0 +1 @@
1
+ """stdio MCP server package for vmware-log-insight."""
@@ -0,0 +1,61 @@
1
+ """Shared MCP plumbing for the vmware-log-insight tool modules.
2
+
3
+ Tool functions live in ``mcp_server/tools/*.py`` and register onto the single
4
+ ``mcp`` instance defined here. This module imports nothing from the tool
5
+ packages (tools import *from* ``_shared``, never the reverse) to avoid a circular
6
+ import. ``mcp_server/server.py`` re-exports these so the historical import paths
7
+ keep resolving.
8
+ """
9
+
10
+ import logging
11
+ import os
12
+ from pathlib import Path
13
+ from typing import Any, Optional
14
+
15
+ from mcp.server.fastmcp import FastMCP
16
+ from vmware_policy import sanitize
17
+
18
+ from vmware_log_insight.config import load_config
19
+ from vmware_log_insight.connection import ConnectionManager, LogInsightApiError
20
+
21
+ logger = logging.getLogger("mcp_server")
22
+
23
+
24
+ def _safe_error(exc: Exception, tool: str) -> str:
25
+ """Return an agent-safe error string; log full detail server-side only.
26
+
27
+ LogInsightApiError (the connection layer's teaching errors) and intentional
28
+ validation errors pass through; anything else is masked so raw response
29
+ bodies / host:port pairs never reach the agent.
30
+ """
31
+ logger.error("Tool %s failed", tool, exc_info=True)
32
+ if isinstance(
33
+ exc,
34
+ (LogInsightApiError, ValueError, FileNotFoundError, KeyError, PermissionError, ConnectionError),
35
+ ):
36
+ return sanitize(str(exc), 300)
37
+ return f"{type(exc).__name__}: operation failed."
38
+
39
+
40
+ mcp = FastMCP(
41
+ "vmware-log-insight",
42
+ instructions=(
43
+ "VMware Aria Operations for Logs (vRealize Log Insight): read-only log "
44
+ "search, aggregation/spike detection, field discovery, and alert queries. "
45
+ "Feed results to vmware-debug's incident_timeline to correlate with events "
46
+ "from other sources. For vCenter events/alarms use vmware-monitor; for "
47
+ "metrics/anomalies use vmware-aria."
48
+ ),
49
+ )
50
+
51
+ _conn_mgr: Optional[ConnectionManager] = None
52
+
53
+
54
+ def _get_connection(target: Optional[str] = None) -> Any:
55
+ """Return a LogInsightClient, lazily initialising the connection manager."""
56
+ global _conn_mgr # noqa: PLW0603
57
+ if _conn_mgr is None:
58
+ config_path_str = os.environ.get("VMWARE_LOG_INSIGHT_CONFIG")
59
+ config_path = Path(config_path_str) if config_path_str else None
60
+ _conn_mgr = ConnectionManager(load_config(config_path))
61
+ return _conn_mgr.connect(target)
@@ -0,0 +1,86 @@
1
+ """MCP server for VMware Log Insight (Aria Operations for Logs) — read-only.
2
+
3
+ Thin entrypoint: importing the tool modules runs their ``@mcp.tool`` decorators
4
+ (registering the 7 read tools on the shared ``mcp`` instance), re-exports the
5
+ shared plumbing and every tool function so ``from mcp_server.server import mcp,
6
+ <fn>`` keeps resolving (踩坑 #17), and exposes ``main()``.
7
+
8
+ Tool categories
9
+ ---------------
10
+ * **Logs** (4, read-only): log_search, log_aggregate, log_fields, log_version
11
+ — ``mcp_server/tools/logs.py``
12
+ * **Alerts** (3, read-only): alert_list, alert_get, alert_history
13
+ — ``mcp_server/tools/alerts.py``
14
+
15
+ Security: stdio transport (local only, no listener); credentials come from
16
+ env/.env, never MCP messages; all API text passes through sanitize().
17
+ For vCenter events/alarms use vmware-monitor; for metrics use vmware-aria.
18
+ """
19
+
20
+ import logging
21
+ import sys
22
+
23
+ # Shared plumbing — re-exported so `from mcp_server.server import _safe_error,
24
+ # mcp, _get_connection` (and monkeypatch targets) keep resolving.
25
+ from mcp_server._shared import ( # noqa: F401
26
+ _get_connection,
27
+ _safe_error,
28
+ logger,
29
+ mcp,
30
+ )
31
+
32
+ # Importing the tool modules runs their @mcp.tool decorators (registration).
33
+ from mcp_server.tools import ( # noqa: F401
34
+ alerts,
35
+ logs,
36
+ )
37
+
38
+ # Re-export every tool function so `mcp_server.server.<tool>` resolves (tests
39
+ # call e.g. `server.log_search(...)` and patch `server._get_connection`).
40
+ from mcp_server.tools.alerts import ( # noqa: F401
41
+ alert_get,
42
+ alert_history,
43
+ alert_list,
44
+ )
45
+ from mcp_server.tools.logs import ( # noqa: F401
46
+ log_aggregate,
47
+ log_fields,
48
+ log_search,
49
+ log_version,
50
+ )
51
+
52
+ __all__ = [
53
+ "mcp",
54
+ "main",
55
+ "_safe_error",
56
+ "_get_connection",
57
+ "log_search",
58
+ "log_aggregate",
59
+ "log_fields",
60
+ "log_version",
61
+ "alert_list",
62
+ "alert_get",
63
+ "alert_history",
64
+ ]
65
+
66
+
67
+ def main() -> None:
68
+ """Start the MCP server using stdio transport.
69
+
70
+ Guards Python < 3.11: FastMCP schema reflection over tool signatures is
71
+ unreliable on 3.10 with older mcp/pydantic (踩坑 #33).
72
+ """
73
+ if sys.version_info < (3, 11):
74
+ sys.exit(
75
+ "vmware-log-insight MCP server requires Python >= 3.11. Reinstall: "
76
+ "uv tool install --python 3.11 --force vmware-log-insight"
77
+ )
78
+ logging.basicConfig(
79
+ level=logging.WARNING,
80
+ format="%(asctime)s %(name)s %(levelname)s %(message)s",
81
+ )
82
+ mcp.run()
83
+
84
+
85
+ if __name__ == "__main__":
86
+ main()
@@ -0,0 +1 @@
1
+ """MCP tool modules for vmware-log-insight (all read-only)."""
@@ -0,0 +1,62 @@
1
+ """ALERT tools (3, read-only): alert_list, alert_get, alert_history."""
2
+
3
+ from typing import Optional
4
+
5
+ from vmware_policy import vmware_tool
6
+
7
+ from mcp_server._shared import mcp
8
+
9
+ _READ = {"readOnlyHint": True, "destructiveHint": False, "idempotentHint": True, "openWorldHint": True}
10
+
11
+
12
+ @mcp.tool(annotations=_READ)
13
+ @vmware_tool(risk_level="low")
14
+ def alert_list(
15
+ name_filter: Optional[str] = None, limit: int = 50, target: Optional[str] = None
16
+ ) -> list[dict]:
17
+ """[READ] List defined Log Insight alerts.
18
+
19
+ name_filter = optional case-insensitive substring on alert name. limit = max
20
+ results (default 50). target = target name from config. Returns [{id, name,
21
+ enabled, info}]; pass an id to alert_get. Read-only — this skill never
22
+ creates/edits/deletes alerts."""
23
+ from mcp_server import server
24
+
25
+ try:
26
+ from vmware_log_insight.ops.alerts import list_alerts
27
+
28
+ return list_alerts(server._get_connection(target), name_filter=name_filter, limit=limit)
29
+ except Exception as e:
30
+ return [{"error": server._safe_error(e, "alert_list"), "hint": "Run 'vmware-log-insight doctor'."}]
31
+
32
+
33
+ @mcp.tool(annotations=_READ)
34
+ @vmware_tool(risk_level="low")
35
+ def alert_get(alert_id: str, target: Optional[str] = None) -> dict:
36
+ """[READ] Get full details for one alert by id (from alert_list). target =
37
+ target name from config. Returns the alert's sanitized detail. Read-only."""
38
+ from mcp_server import server
39
+
40
+ try:
41
+ from vmware_log_insight.ops.alerts import get_alert
42
+
43
+ return get_alert(server._get_connection(target), alert_id)
44
+ except Exception as e:
45
+ return {"error": server._safe_error(e, "alert_get"), "hint": "Run 'vmware-log-insight doctor'."}
46
+
47
+
48
+ @mcp.tool(annotations=_READ)
49
+ @vmware_tool(risk_level="low")
50
+ def alert_history(alert_id: str, limit: int = 50, target: Optional[str] = None) -> list[dict]:
51
+ """[READ] List recent trigger-history records for an alert.
52
+
53
+ alert_id = the alert id (from alert_list). limit = max records (default 50).
54
+ target = target name from config. Returns [{timestamp_ms, info}]. Read-only."""
55
+ from mcp_server import server
56
+
57
+ try:
58
+ from vmware_log_insight.ops.alerts import get_alert_history
59
+
60
+ return get_alert_history(server._get_connection(target), alert_id, limit=limit)
61
+ except Exception as e:
62
+ return [{"error": server._safe_error(e, "alert_history"), "hint": "Run 'vmware-log-insight doctor'."}]