prom_alert_rules
View and monitor all Prometheus alert rules with their current status to manage infrastructure alerts effectively.
Instructions
List all Prometheus alert rules and their current state
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/prometheus/alerts.ts:26-53 (handler)The implementation of the `alertRules` function, which fetches and formats Prometheus alert rules.
export async function alertRules(): Promise<string> { const url = `${config.prometheusUrl}/api/v1/rules`; const res = await fetch(url); if (!res.ok) throw new Error(`Failed to fetch rules: ${res.status}`); const data = (await res.json()) as { data: { groups: Array<{ name: string; interval: string; rules: Array<{ type: string; name: string; state: string; labels: Record<string, string>; alerts: unknown[] }> }> } }; const groups = data.data?.groups || []; const lines: string[] = ["Alert rules:"]; for (const group of groups) { lines.push(`\nGroup: ${group.name} (interval: ${group.interval})`); const rules = (group.rules || []).filter((r: { type: string }) => r.type === "alerting"); if (rules.length === 0) continue; const headers = ["RULE", "STATE", "SEVERITY", "ACTIVE"]; const rows = rules.map((r: { name: string; state: string; labels: Record<string, string>; alerts: unknown[] }) => [ r.name, r.state, r.labels?.severity || "N/A", String(r.alerts?.length || 0), ]); lines.push(formatTable(headers, rows)); } return lines.join("\n"); } - src/tools/prometheus/index.ts:38-41 (registration)The registration definition for the "prom_alert_rules" tool.
name: "prom_alert_rules", description: "List all Prometheus alert rules and their current state", inputSchema: { type: "object" as const, properties: {} }, }, - src/tools/prometheus/index.ts:59-59 (handler)The switch case in handlePrometheusTool that calls the alertRules implementation.
case "prom_alert_rules": return alertRules();