Skip to main content
Glama

get_alarm_history

Retrieve historical state changes and transitions for Oracle Cloud Infrastructure alarms to analyze monitoring patterns and troubleshoot issues.

Instructions

Get alarm state history.

Args:
    alarm_id: OCID of the alarm
    alarm_historytype: Type of history (STATE_TRANSITION_HISTORY, STATE_HISTORY, RULE_HISTORY)

Returns:
    List of alarm history entries with timestamps and state changes

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
alarm_idYes
alarm_historytypeNoSTATE_TRANSITION_HISTORY

Implementation Reference

  • The core handler function implementing the get_alarm_history tool. It uses the OCI MonitoringClient to fetch all alarm history entries via pagination, processes them into a list of dictionaries with summary, timestamp, and optional timestamp_triggered, and handles exceptions.
    def get_alarm_history(monitoring_client: oci.monitoring.MonitoringClient,
                          alarm_id: str,
                          alarm_historytype: str = "STATE_TRANSITION_HISTORY") -> List[Dict[str, Any]]:
        """
        Get alarm state history.
    
        Args:
            monitoring_client: OCI Monitoring client
            alarm_id: OCID of the alarm
            alarm_historytype: Type of history (STATE_TRANSITION_HISTORY, STATE_HISTORY, RULE_HISTORY)
    
        Returns:
            List of alarm history entries
        """
        try:
            history_response = oci.pagination.list_call_get_all_results(
                monitoring_client.get_alarm_history,
                alarm_id,
                alarm_historytype=alarm_historytype
            )
    
            history = []
            for entry in history_response.data:
                history.append({
                    "summary": entry.summary,
                    "timestamp": str(entry.timestamp),
                    "timestamp_triggered": str(entry.timestamp_triggered) if hasattr(entry, 'timestamp_triggered') and entry.timestamp_triggered else None,
                })
    
            logger.info(f"Retrieved {len(history)} history entries for alarm {alarm_id}")
            return history
    
        except Exception as e:
            logger.exception(f"Error getting alarm history: {e}")
            raise
  • The MCP tool registration for 'get_alarm_history'. This wrapper function is decorated with @mcp.tool and @mcp_tool_wrapper, receives MCP Context and parameters, and delegates to the core handler function using the shared oci_clients["monitoring"] instance.
    @mcp.tool(name="get_alarm_history")
    @mcp_tool_wrapper(
        start_msg="Getting alarm history for {alarm_id}...",
        error_prefix="Error getting alarm history"
    )
    async def mcp_get_alarm_history(ctx: Context, alarm_id: str,
                                    alarm_historytype: str = "STATE_TRANSITION_HISTORY") -> List[Dict[str, Any]]:
        """
        Get alarm state history.
    
        Args:
            alarm_id: OCID of the alarm
            alarm_historytype: Type of history (STATE_TRANSITION_HISTORY, STATE_HISTORY, RULE_HISTORY)
    
        Returns:
            List of alarm history entries with timestamps and state changes
        """
        return get_alarm_history(oci_clients["monitoring"], alarm_id, alarm_historytype)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jopsis/mcp-server-oci'

If you have feedback or need assistance with the MCP directory API, please join our Discord server