告警管理服务

Prometheus Alertmanager的MCP服务器,支持通过Claude Code查询告警和管理静默。

  • by bborbe
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 bborbe/alertmanager-mcp

使用说明

警报管理器MCP服务器

普罗米修斯警报管理器的MCP服务器。允许通过Claude Code查询警报和管理静音。

设置

  1. 安装依赖项:

    uv venv
    uv sync --all-extras
    
  2. 配置环境: 设置以下环境变量:

    ALERTMANAGER_URL=https://alertmanager.example.com
    ALERTMANAGER_USERNAME=your_username  # Optional - for HTTP basic auth
    ALERTMANAGER_PASSWORD=your_password  # Optional - for HTTP basic auth
    ALERTMANAGER_TIMEOUT=30              # Optional - request timeout in seconds (default: 30)
    ALERTMANAGER_CREATED_BY=alertmanager-mcp  # Optional - identity for silence creation
    

    注: 身份验证(用户名/密码)是可选的。如果没有提供,将在没有身份验证的情况下提出请求。

用法

直接执行

使用环境变量运行服务器:

ALERTMANAGER_URL=https://alertmanager.example.com \
ALERTMANAGER_USERNAME=monitoring \
ALERTMANAGER_PASSWORD=your_password \
uv run alertmanager-mcp

使用.env文件

创建 .env 文件:

ALERTMANAGER_URL=https://alertmanager.example.com
ALERTMANAGER_USERNAME=monitoring
ALERTMANAGER_PASSWORD=your_password

然后运行:

uv run alertmanager-mcp

Claude代码配置

基本配置

添加到您的Claude Code MCP设置中(~/.claude/mcp.json):

{
  "mcpServers": {
    "alertmanager": {
      "type": "stdio",
      "command": "uv",
      "args": ["run", "--directory", "/path/to/alertmanager-mcp", "alertmanager-mcp"],
      "env": {
        "ALERTMANAGER_URL": "https://alertmanager.example.com",
        "ALERTMANAGER_USERNAME": "monitoring",
        "ALERTMANAGER_PASSWORD": "your_password"
      }
    }
  }
}

对于没有身份验证的Alertmanager实例:

{
  "mcpServers": {
    "alertmanager": {
      "type": "stdio",
      "command": "uv",
      "args": ["run", "--directory", "/path/to/alertmanager-mcp", "alertmanager-mcp"],
      "env": {
        "ALERTMANAGER_URL": "https://alertmanager.example.com"
      }
    }
  }
}

多个环境

对于多个Alertmanager实例(prod、staging、dev):

{
  "mcpServers": {
    "alertmanager-prod": {
      "type": "stdio",
      "command": "uv",
      "args": ["run", "--directory", "/path/to/alertmanager-mcp", "alertmanager-mcp"],
      "env": {
        "ALERTMANAGER_URL": "https://alertmanager.prod.example.com",
        "ALERTMANAGER_USERNAME": "monitoring",
        "ALERTMANAGER_PASSWORD": "prod_password"
      }
    },
    "alertmanager-staging": {
      "type": "stdio",
      "command": "uv",
      "args": ["run", "--directory", "/path/to/alertmanager-mcp", "alertmanager-mcp"],
      "env": {
        "ALERTMANAGER_URL": "https://alertmanager.staging.example.com",
        "ALERTMANAGER_USERNAME": "monitoring",
        "ALERTMANAGER_PASSWORD": "staging_password"
      }
    }
  }
}

使用GitHub安装

直接从GitHub安装(发布后):

{
  "mcpServers": {
    "alertmanager": {
      "type": "stdio",
      "command": "uvx",
      "args": ["--from", "git+https://github.com/yourusername/alertmanager-mcp", "alertmanager-mcp"],
      "env": {
        "ALERTMANAGER_URL": "https://alertmanager.example.com",
        "ALERTMANAGER_USERNAME": "monitoring",
        "ALERTMANAGER_PASSWORD": "your_password"
      }
    }
  }
}

MCP工具

get_alerts

从Alertmanager获取警报。

参数:

  • active_only (布尔值,可选):仅获取活动警报。默认为 true.
  • filter (string,可选):警报管理器筛选器查询字符串。

例子:

{
  "name": "get_alerts",
  "arguments": {
    "active_only": true,
    "filter": "severity=\"critical\""
  }
}

silence_alert

为警报设置静音。

参数:

  • fingerprint (string):指纹提示静音。
  • duration (string):静默的持续时间(例如,“2h”、“1d”、“1w”)。
  • comment (string):解释沉默原因的评论。

例子:

{
  "name": "silence_alert",
  "arguments": {
    "fingerprint": "abc123def456",
    "duration": "2h",
    "comment": "Maintenance window - upgrading service"
  }
}

list_silences

列出来自Alertmanager的现有静音。

例子:

{
  "name": "list_silences",
  "arguments": {}
}

测试

运行单元测试:

uv run pytest

许可证

本项目根据BSD-2条款许可证获得许可-请参阅 许可证 文件以获取详细信息。