get_alerts
Retrieve a list of alerts from the alertmanager-mcp-server by applying filters for silenced, inhibited, or active statuses to streamline monitoring and incident management.
Instructions
Get a list of alerts
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| active | No | ||
| filter | No | ||
| inhibited | No | ||
| silenced | No |
Implementation Reference
- The main handler function for the 'get_alerts' tool. It is decorated with @mcp.tool, which also serves as the registration mechanism in FastMCP. The function builds query parameters based on optional inputs (filter, silenced, inhibited, active) and fetches alerts from the Alertmanager API endpoint '/api/v2/alerts' using the helper make_request.@mcp.tool(description="Get a list of alerts") async def get_alerts(filter: Optional[str] = None, silenced: Optional[bool] = None, inhibited: Optional[bool] = None, active: Optional[bool] = None): """Get a list of alerts currently in Alertmanager. Params ------ filter Filtering query (e.g. alertname=~'.*CPU.*')"), silenced If true, include silenced alerts. inhibited If true, include inhibited alerts. active If true, include active alerts. Returns ------- list Return a list of Alert objects from Alertmanager instance. """ params = {"active": True} if filter: params = {"filter": filter} if silenced is not None: params["silenced"] = silenced if inhibited is not None: params["inhibited"] = inhibited if active is not None: params["active"] = active return make_request(method="GET", route="/api/v2/alerts", params=params)
- Helper function used by get_alerts (and other tools) to make authenticated HTTP requests to the Alertmanager API.def make_request(method="GET", route="/", **kwargs): """Make HTTP request and return a requests.Response object. Parameters ---------- method : str HTTP method to use for the request. route : str (Default value = "/") This is the url we are making our request to. **kwargs : dict Arbitrary keyword arguments. Returns ------- dict: The response from the Alertmanager API. This is a dictionary containing the response data. """ route = urljoin(config.url, route) auth = ( requests.auth.HTTPBasicAuth(config.username, config.password) if config.username and config.password else None ) response = requests.request( method=method.upper(), url=route, auth=auth, timeout=60, **kwargs ) response.raise_for_status() return response.json()