Skip to main content
Glama
mpeirone

zabbix-mcp-server

event_get

Retrieve and filter events from Zabbix by event IDs, host groups, hosts, objects, or time range. Returns a JSON-formatted list of events for monitoring and analysis.

Instructions

Get events from Zabbix with optional filtering.

Args:
    eventids: List of event IDs to retrieve
    groupids: List of host group IDs to filter by
    hostids: List of host IDs to filter by
    objectids: List of object IDs to filter by
    output: Output format
    time_from: Start time (Unix timestamp)
    time_till: End time (Unix timestamp)
    limit: Maximum number of results
    
Returns:
    str: JSON formatted list of events

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
eventidsNo
groupidsNo
hostidsNo
limitNo
objectidsNo
outputNoextend
time_fromNo
time_tillNo

Implementation Reference

  • Handler function for the 'event_get' MCP tool. Decorated with @mcp.tool() for automatic registration. Fetches events from Zabbix API using the provided filters and returns JSON-formatted results.
    def event_get(eventids: Optional[List[str]] = None,
                  groupids: Optional[List[str]] = None,
                  hostids: Optional[List[str]] = None,
                  objectids: Optional[List[str]] = None,
                  output: Union[str, List[str]] = "extend",
                  time_from: Optional[int] = None,
                  time_till: Optional[int] = None,
                  limit: Optional[int] = None) -> str:
        """Get events from Zabbix with optional filtering.
        
        Args:
            eventids: List of event IDs to retrieve
            groupids: List of host group IDs to filter by
            hostids: List of host IDs to filter by
            objectids: List of object IDs to filter by
            output: Output format (extend or list of specific fields)
            time_from: Start time (Unix timestamp)
            time_till: End time (Unix timestamp)
            limit: Maximum number of results
            
        Returns:
            str: JSON formatted list of events
        """
        client = get_zabbix_client()
        params = {"output": output}
        
        if eventids:
            params["eventids"] = eventids
        if groupids:
            params["groupids"] = groupids
        if hostids:
            params["hostids"] = hostids
        if objectids:
            params["objectids"] = objectids
        if time_from:
            params["time_from"] = time_from
        if time_till:
            params["time_till"] = time_till
        if limit:
            params["limit"] = limit
        
        result = client.event.get(**params)
        return format_response(result)
  • Docstring defining the input parameters and return type for the event_get tool, used by FastMCP for schema generation.
    """Get events from Zabbix with optional filtering.
    
    Args:
        eventids: List of event IDs to retrieve
        groupids: List of host group IDs to filter by
        hostids: List of host IDs to filter by
        objectids: List of object IDs to filter by
        output: Output format (extend or list of specific fields)
        time_from: Start time (Unix timestamp)
        time_till: End time (Unix timestamp)
        limit: Maximum number of results
        
    Returns:
        str: JSON formatted list of events
    """
  • FastMCP decorator that registers the event_get function as a tool named 'event_get'.
    def event_get(eventids: Optional[List[str]] = None,
  • Helper function used by event_get to format the API response as indented JSON.
    def format_response(data: Any) -> str:
        """Format response data as JSON string.
        
        Args:
            data: Data to format
            
        Returns:
            str: JSON formatted string
        """
        return json.dumps(data, indent=2, default=str)
  • Helper function to obtain authenticated ZabbixAPI client instance, used by event_get.
    def get_zabbix_client() -> ZabbixAPI:
        """Get or create Zabbix API client with proper authentication.
        
        Returns:
            ZabbixAPI: Authenticated Zabbix API client
            
        Raises:
            ValueError: If required environment variables are missing
            Exception: If authentication fails
        """
        global zabbix_api
        
        if zabbix_api is None:
            url = os.getenv("ZABBIX_URL")
            if not url:
                raise ValueError("ZABBIX_URL environment variable is required")
            
            logger.info(f"Initializing Zabbix API client for {url}")
            
            # Configure SSL verification
            verify_ssl = os.getenv("VERIFY_SSL", "true").lower() in ("true", "1", "yes")
            logger.info(f"SSL certificate verification: {'enabled' if verify_ssl else 'disabled'}")
            
            # Initialize client
            zabbix_api = ZabbixAPI(url=url, validate_certs=verify_ssl)
    
            # Authenticate using token or username/password
            token = os.getenv("ZABBIX_TOKEN")
            if token:
                logger.info("Authenticating with API token")
                zabbix_api.login(token=token)
            else:
                user = os.getenv("ZABBIX_USER")
                password = os.getenv("ZABBIX_PASSWORD")
                if not user or not password:
                    raise ValueError("Either ZABBIX_TOKEN or ZABBIX_USER/ZABBIX_PASSWORD must be set")
                logger.info(f"Authenticating with username: {user}")
                zabbix_api.login(user=user, password=password)
            
            logger.info("Successfully authenticated with Zabbix API")
        
        return zabbix_api

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/mpeirone/zabbix-mcp-server'

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