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.
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
Asked: 2023-05-28 02:48:25 +0000
Seen: 13 times
Last updated: May 28 '23
Which languages are appropriate to use for a contemporary website?
How can a HTTP header be inserted in WordPress?
How can data be stored in a data attribute and utilized through Ajax?
How can an array be passed using typo3 flexform xml and itemsProcConfig?
How to use Composer autoload in implementing PHP namespaces?
What is the difference between highlighting HTML code in a .php file in VSCode?
Does JSON encode fail to retrieve data from the database?
Why isn't the cell text appearing when using easytable and fpdf in PHP version 7.4?
Can the GS1 128 barcode decoder in PHP or Jquery be utilized?