get-alert-groups
Retrieve and filter alert groups from Prometheus Alertmanager to monitor active, silenced, and inhibited alerts for system monitoring and incident management.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| active | No | Include active alerts (default: true) | |
| silenced | No | Include silenced alerts | |
| inhibited | No | Include inhibited alerts |
Implementation Reference
- src/index.ts:357-386 (handler)The main handler function for the 'get-alert-groups' tool. It constructs query parameters based on input options, fetches alert groups from the Alertmanager API endpoint '/api/v2/alerts/groups', and returns the JSON-formatted response or an error message.async ({ active = true, silenced = false, inhibited = false }) => { try { // Build query parameters const params = new URLSearchParams(); if (!active) params.append("active", "false"); if (silenced) params.append("silenced", "true"); if (inhibited) params.append("inhibited", "true"); // Fetch alert groups const queryString = params.toString(); const path = `alerts/groups${queryString ? '?' + queryString : ''}`; const groups = await fetchFromAlertmanager(path); return { content: [{ type: "text", text: JSON.stringify(groups, null, 2) }] }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [{ type: "text", text: `Error fetching alert groups: ${errorMessage}` }], isError: true }; } }
- src/index.ts:352-356 (schema)Zod input schema defining optional boolean parameters for filtering alert groups by active, silenced, and inhibited status.{ active: z.boolean().optional().describe("Include active alerts (default: true)"), silenced: z.boolean().optional().describe("Include silenced alerts"), inhibited: z.boolean().optional().describe("Include inhibited alerts"), },
- src/index.ts:350-387 (registration)Registration of the 'get-alert-groups' tool using server.tool(), including the tool name, input schema, and handler function.server.tool( "get-alert-groups", { active: z.boolean().optional().describe("Include active alerts (default: true)"), silenced: z.boolean().optional().describe("Include silenced alerts"), inhibited: z.boolean().optional().describe("Include inhibited alerts"), }, async ({ active = true, silenced = false, inhibited = false }) => { try { // Build query parameters const params = new URLSearchParams(); if (!active) params.append("active", "false"); if (silenced) params.append("silenced", "true"); if (inhibited) params.append("inhibited", "true"); // Fetch alert groups const queryString = params.toString(); const path = `alerts/groups${queryString ? '?' + queryString : ''}`; const groups = await fetchFromAlertmanager(path); return { content: [{ type: "text", text: JSON.stringify(groups, null, 2) }] }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [{ type: "text", text: `Error fetching alert groups: ${errorMessage}` }], isError: true }; } } );
- src/index.ts:16-41 (helper)Helper function used by the tool to make HTTP requests to the Alertmanager API with timeout handling and error management.async function fetchFromAlertmanager(path: string, options: RequestInit = {}): Promise<any> { const baseUrl = process.env.ALERTMANAGER_URL || DEFAULT_ALERTMANAGER_URL; const url = `${baseUrl}/api/v2/${path}`; try { const controller = new AbortController(); const timeoutId = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT); const response = await fetch(url, { ...options, signal: controller.signal }); clearTimeout(timeoutId); if (!response.ok) { throw new Error(`Alertmanager API error: ${response.status} ${response.statusText}`); } return await response.json(); } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); console.error(`Error fetching from Alertmanager: ${errorMessage}`); throw error; } }