سؤال

I need to get all the triggers from my Zabbix Dashboard. So if there is a trigger, doesn't matter which severity, I need to get this. Here is a screenshot of the trigger dashboard with one entry: enter image description here click on it to watch it bigger
So if there are no active triggers, this list is empty.

What I've already:

jsonObj.put("method", "trigger.get");
        // Priority: 0 = Not classified | 1 = Information | 2 = Warning | 3 =
        // Average | 4 = High | 5 = Disaster
        jsonObj.put(
                "params",
                (new JSONObject().put(
                        "filter",
                        new JSONObject().put("priority", 1).put("group", "WZU-Server")).put(
                        "output", "extend")));

But this returns me a lot of old triggers, which aren't active anymore. I really only need the triggers, which are displayed on the dashboard!

How can I achieve this? I don't get it for hours with the zabbix api...

INFO:
The group ID is 7
There are different hosts in this group
If a trigger has the status OK, I don't need it. Only if there is a PROBLEM.

Edit
I'm really close to my target.
My current code looks like this:

int count = 2;
while (count <= 5){
    jsonObj.put("jsonrpc", "2.0");
    jsonObj.put("method", "trigger.get");
    // Value: 0 = OK | 1 = PROBLEM | 2 = UNKNOWN
    // Priority: 0 = Not classified | 1 = Information | 2 = Warning | 3 =
    // Average | 4 = High | 5 = Disaster

    // count = priority. It start with two and end with 5
    jsonObj.put("params", (new JSONObject().put("filter", new JSONObject().put("priority", count).put("group", "WZU-Server").put("value", 1)).put("output", "extend")));
    jsonObj.put("id", 0);
    jsonObj.put("auth", "8ba6b9f29dd68e0c98cdea9ee01f2614");

    putMethod.setRequestEntity(new StringRequestEntity(jsonObj.toString(), "application/json", "UTF-8"));
}

At this time, my dashboard is empty. So I shouldn't get any Objects of this code.
"Warning" is empty, so it is okay.
"Average returns 8 Objects. All of the objects are older than a week. Bad!
"High" is empty, so it is okay.
"Disaster" returns 1 Objects. This object is over one week old. Bad!

So how can I achieve that I only get the entrys of my dashboard?

هل كانت مفيدة؟

المحلول

I have an external application that calls zabbix API to check statuses.

There is no such thing as "status of the systems". If by "systems" you mean "hosts". In zabbix you have hosts that have monitored items. Items are constantly getting values that are saved into history. The data received passes triggers mechanisms that can raise alerts.

Now, what you mention that you see in dashboard is probably a mix of a host availability statuses and alerts. Let us call the whole picture you see in the dashboard "system health". To understand the system health you may want:

  • Check if there are any hosts with unavailable agent, that's it, hosts you monitor with zabbix agent installed and zabbix server can't reach the agent. To do that you can use host.get with filter on "available" property.

  • Check if there are any alerts, that's it, if you use alerts, this is the simplest way to get the red stuff from the dashboard. you can do that with alert.get. I've never used it, so check if you need any filters there to get active alerts.

  • Probably you can also check events coming from triggers using event.get but I've never used this method either.

  • What works for me and what you may be forced to do if you have agentless hosts without alerts in the system health, is checking specific items history. To do it you need to use history.get to get the values, usually last N values or values for the last N minutes, which you can analyze in your code. This approach probably moves the monitoring and alerting purpose from zabbix to your app leaving zabbix server to only to gather the data.

Just keep experimenting, but read how zabbix works and what the concepts are first. The knowledge of the platform will save you lots of time that you'd better invest in writing code.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top