Search code examples
jsonapizabbix

Zabbix Json Api get health of host or hostgroup


I am currently trying out Zabbix 2.4 json api and can connect get alerts and triggers but I'm having trouble finding a way to check if a given hostgroup contains no open errors and is thereby healthy. A simple way to check this doenst seem to exist? I have searched stackoverflow, google and Zabbix documentation. any clues as to tackeling this question? The following reuqest gives me errors but no way to tell if errors are still open.

{
"jsonrpc": "2.0",
"method": "alert.get",
"params": {
"output": "extend",
"groupids": "83",
"time_from": "1441065600"
},
"auth": "ZZZZZZZZZZZZZZZZZZZZZZZZZ",
"id": 1
}

Update: (solved)

$resource = "http://zabbix/api_jsonrpc.php"

$body = '
{
"jsonrpc": "2.0",
"method": "trigger.get",
"params": {
    "active": 1,
    "only_true": "1",
    "monitord": 1,
    "selectGroups": 1,
    "output": "extend",
    "expandDescription": "1",
    "selectGroups": "1",
        "groupids": 83,     <----  this field changes :)
    "filter": {
        "value": 1,
        "priority": [3,4,5]    <----- filter off low prios
    },
    "sortfield": "priority",
    "sortorder": "DESC"
},
"auth": "ZZZZZZZZZZZZZZZZZZZZZZZZZ",
"id": 1
}
'
$result = Invoke-RestMethod -Method Post -Uri $resource -Body $body -ContentType "application/json"

$result.result

Solution

  • Use active triggers of host/group. Some my code, which I use:

    zapi.trigger.get(only_true=1,
            skipDependent=1,
            monitored=1,
            active=1,
            output='extend',
            expandDescription=1,
            selectGroups=1,
            expandData='host',
            hostids=<host_id>,
            sortfield='priority',
            sortorder='DESC',
            filter={"value": 1, "priority": ['4','5']}
        )
    

    https://www.zabbix.com/documentation/2.4/manual/api/reference/trigger/get