get_alerts_summary
Summarize Kubernetes alerts by severity and state to monitor and analyze alert status from the Karma dashboard.
Instructions
Get a summary of alerts grouped by severity and state
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/karma_mcp/server.py:352-383 (handler)Handler implementation for get_alerts_summary tool, which fetches Karma data and uses format_alert_summary utility to return the alert statistics.
async def get_alerts_summary() -> str: """Get a summary of alerts grouped by severity and state""" data, error = await fetch_karma_alerts() if error: return error # Use the centralized summary function summary = format_alert_summary(data, include_clusters=True) # Add top alert types section alert_type_counts = {} grids = data.get("grids", []) for grid in grids: for group in grid.get("alertGroups", []): alertname = extract_label_value( group.get("labels", []), "alertname", "Unknown" ) alert_count = len(group.get("alerts", [])) alert_type_counts[alertname] = ( alert_type_counts.get(alertname, 0) + alert_count ) # Add top alert types to summary if alert_type_counts: summary += "\nš Top Alert Types:\n" top_alerts = sorted( alert_type_counts.items(), key=lambda x: x[1], reverse=True )[:10] for alertname, count in top_alerts: summary += f" ⢠{alertname}: {count}\n" return summary - src/karma_mcp/server.py:169-223 (helper)Helper function that formats alert data into a readable summary, used by the get_alerts_summary tool.
def format_alert_summary(alerts_data, include_clusters=False): """Format alert data into a readable summary""" total_alerts = 0 severity_counts = {"critical": 0, "warning": 0, "info": 0, "none": 0} state_counts = {"active": 0, "suppressed": 0} cluster_counts = {} grids = alerts_data.get("grids", []) for grid in grids: for group in grid.get("alertGroups", []): alerts = group.get("alerts", []) total_alerts += len(alerts) for alert in alerts: metadata = extract_alert_metadata(group, alert) # Count by severity severity = metadata["severity"] if severity in severity_counts: severity_counts[severity] += 1 # Count by state state = metadata["state"] if state in state_counts: state_counts[state] += 1 # Count by cluster if needed if include_clusters: cluster = metadata["cluster"] cluster_counts[cluster] = cluster_counts.get(cluster, 0) + 1 # Format summary matching the expected test format summary = f"Total Alerts: {total_alerts}\n" # Severity breakdown summary += "\nBy Severity:\n" for severity, count in severity_counts.items(): if count > 0: summary += f" {severity.capitalize()}: {count}\n" summary += "\nBy State:\n" for state, count in state_counts.items(): if count > 0: summary += f" {state.capitalize()}: {count}\n" if include_clusters and cluster_counts: summary += "\nBy Cluster:\n" sorted_clusters = sorted( cluster_counts.items(), key=lambda x: x[1], reverse=True ) for cluster, count in sorted_clusters: summary += f" {cluster}: {count}\n" return summary - src/karma_mcp/http_server.py:345-348 (registration)Registration of the get_alerts_summary tool in the MCP server's tool list.
"name": "get_alerts_summary", "description": "Get alert statistics", "inputSchema": {"type": "object", "properties": {}, "required": []}, },