使用说明
Splunk MCP服务器
A. 模型上下文协议(MCP)服务器 Splunk,让您用简单的英语查询Splunk。
它会自动发现索引、数据模型和已安装的应用程序,并将其作为MCP资源和工具提供。
适用于ChatGPT桌面、Claude桌面和任何兼容MCP的客户端。
特性
- 使用查询Splunk 浅显易懂的英语
- 自动发现 索引、数据模型和应用程序 启动时
- 将元数据作为MCP资源公开
- 提供的工具:
askSplunk–用英语提问,获得翻译的SPL+结果describeEnvironment–总结索引、应用程序、数据模型splunk://metadata–原始环境元数据
设置
1) 克隆仓库
git clone https://github.com/gaurdiansphere/splunk-mcp.git
cd splunk-mcp
2) 创建虚拟环境并安装依赖项
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
3) 配置Splunk连接
创建一个 .env 项目根目录中的文件:
SPLUNK_URL=https://splunk.example.com:8089
SPLUNK_TOKEN=YOUR_SPLUNK_TOKEN
- 使用Splunk服务帐户 只读/搜索 权限
- 做 不 提交
.env转到GitHub
运行服务器
python3 splunk_mcp.py
如果成功,您将看到以下日志:
[MCP] Loaded indexes: ['wineventlog', 'auth', 'okta']
[MCP] Loaded datamodels: ['Authentication', 'Endpoint']
[MCP] Loaded apps: ['Splunk_TA_windows', 'Splunk_TA_okta']
MCP集成
将此服务器添加到MCP客户端配置中(例如。 ~/.config/openai/mcp.json):
{
"servers": {
"splunk": {
"command": "python3",
"args": ["/absolute/path/to/splunk_mcp.py"]
}
}
}
更新后重新启动MCP客户端(ChatGPT Desktop、Claude Desktop等)。
示例用法
描述环境
/tool splunk.describeEnvironment {}
示例响应:
{
"applications": ["Splunk_TA_windows", "Splunk_TA_okta"],
"indexes": ["wineventlog", "auth", "okta"],
"datamodels": ["Authentication", "Endpoint"]
}
用英语提问
/tool splunk.askSplunk {"question": "Show me failed logins in the last 24 hours"}
示例响应:
{
"Translated SPL": "| tstats count from datamodel=Authentication.Authentication where Authentication.action=\"failure\" earliest=-24h by Authentication.user",
"results": [
{"Authentication.user": "bob", "count": "12"},
{"Authentication.user": "alice", "count": "7"}
]
}
安全说明
- 将凭据保存在
.env永远不要泄露秘密 - 将令牌限制为 只读的 权限
- 定期轮换凭据
路线图
- 更好的英语→ 使用发现的元数据进行SPL翻译
- 支持已保存的搜索和警报
- 大型结果集的流式传输