Ask Your Question
0

How can Zabbix API be utilized with a Python script for obtaining all triggers?

asked 2023-05-28 02:48:25 +0000

qstack gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-05-28 03:03:01 +0000

devzero gravatar image

Here is an example Python script that utilizes Zabbix API to obtain all triggers:

import requests
import json

# API access parameters
url = "https://yourzabbixserver.com/api_jsonrpc.php"
username = "yourusername"
password = "yourpassword"

# Zabbix API request to obtain authentication token
auth_request = {
    "jsonrpc": "2.0",
    "method": "user.login",
    "params": {
        "user": username,
        "password": password
    },
    "id": 1
}
response = requests.post(url, data=json.dumps(auth_request))
auth_result = json.loads(response.text)
auth_token = auth_result["result"]

# Zabbix API request to obtain all triggers
triggers_request = {
    "jsonrpc": "2.0",
    "method": "trigger.get",
    "params": {
        "output": ["triggerid", "description", "priority"],
        "filter": {
            "value": 1,
            "status": 0
        },
        "sortfield": "priority",
        "sortorder": "DESC"
    },
    "auth": auth_token,
    "id": 1
}
response = requests.post(url, data=json.dumps(triggers_request))
triggers_result = json.loads(response.text)
triggers = triggers_result["result"]

# Output all triggers
for trigger in triggers:
    print("ID: " + trigger["triggerid"] + ", Description: " + trigger["description"] + ", Priority: " + trigger["priority"])

This script first retrieves an authentication token from the Zabbix API using the provided credentials. It then sends a trigger.get API request to obtain all triggers that have a value of 1 and a status of 0 (meaning active triggers). The triggers are sorted by priority in descending order. The script outputs the trigger IDs, descriptions, and priorities for each trigger.

Note that this script assumes that the Zabbix server's API is accessible via the specified URL and that the provided credentials are valid. Also, make sure to replace "yourzabbixserver.com", "yourusername", and "yourpassword" with your own values.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-28 02:48:25 +0000

Seen: 13 times

Last updated: May 28 '23