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
| Name | Required | Description | Default |
|---|---|---|---|
| eventids | No | ||
| groupids | No | ||
| hostids | No | ||
| limit | No | ||
| objectids | No | ||
| output | No | extend | |
| time_from | No | ||
| time_till | No |
Input Schema (JSON Schema)
{
"properties": {
"eventids": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "null"
}
],
"default": null,
"title": "Eventids"
},
"groupids": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "null"
}
],
"default": null,
"title": "Groupids"
},
"hostids": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "null"
}
],
"default": null,
"title": "Hostids"
},
"limit": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"default": null,
"title": "Limit"
},
"objectids": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "null"
}
],
"default": null,
"title": "Objectids"
},
"output": {
"default": "extend",
"title": "Output",
"type": "string"
},
"time_from": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"default": null,
"title": "Time From"
},
"time_till": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"default": null,
"title": "Time Till"
}
},
"type": "object"
}
Implementation Reference
- src/zabbix_mcp_server.py:767-810 (handler)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)
- src/zabbix_mcp_server.py:775-789 (schema)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 """
- src/zabbix_mcp_server.py:767-767 (registration)FastMCP decorator that registers the event_get function as a tool named 'event_get'.def event_get(eventids: Optional[List[str]] = None,
- src/zabbix_mcp_server.py:91-100 (helper)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)
- src/zabbix_mcp_server.py:38-80 (helper)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