Ad Widget

Collapse

API Current Problems Count

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HoCaM
    Junior Member
    • Jan 2013
    • 8

    #1

    API Current Problems Count

    Hi all,

    i am new to the Zabbix API and i am struggling a bit getting values to create something like the Zabbix Dashboard but in a different frontend. So eventually i need to extract/present the count of current Problems grouped by Severity. The software i am using is capable of transforming data sources so the absolutely best would be if i can get a dataset out of Zabbix for each Problem like:

    Status - Severity - Host - Description(Triggername)

    But as i said if i can get only the Column "Severity" i am good. I can then count how often e.g. "Warning" or "High" exists within this Dataset.

    Has anyone already realized this and can give me some help?

    Thanks

    Marc




  • dimir
    Zabbix developer
    • Apr 2011
    • 1080

    #2
    Here's an example on how to connect to Zabbix using API and list problems: https://sbcode.net/zabbix/zabbix-api-python-example/

    That's python but similarly, you can use any language, all you need is support for JSON RPC.

    When you get your "hello world" script working, master on getting all you nead from problems using this document: https://www.zabbix.com/documentation...ce/problem/get

    Comment

    • HoCaM
      Junior Member
      • Jan 2013
      • 8

      #3
      Hi Dimir,

      first of all thanks for the reply and the code example. My first problem description was probably i bit inaccurate. Sorry for that. I general, I got the API/JSON working. My particular problem is that there is a big difference in what i see on the dashboard (lets say 10 current problems) and the results from the API request (eg. 60 items). From what i understand i can get current/unresolved problems from problem.get using "params: recent" or from the trigger.get using "filter : value 1". Both results are not in line with the dashboard. It looks like some of these problems are pretty old. Btw: i am using PowerBi.

      Regards
      Marc

      Comment

      • dimir
        Zabbix developer
        • Apr 2011
        • 1080

        #4
        By default it would list current PROBLEM triggers. If you set {"recent" => true} then additionally it would return recently (depends on "Display OK triggers for N seconds" setting) resolved PROBLEM triggers.
        I haven't tried this but I think by default the amount of returned triggers should be the same as displayed in the Dashboard. Make sure you have no filters set on the Problems widget.
        Also, in Problems widget configuration there is parameter "Show lines". It's how many triggers to show max in a widget (no pagination).
        Another reason that might be there is permissions. Are you using the same user to login to Frontend and to login to API? If your API user can access more hosts, it might get more problems.
        If that doesn't help I'd check the details of each Problem returned by API and try to understand the reason.
        Last edited by dimir; 04-03-2021, 15:50.

        Comment

        • HoCaM
          Junior Member
          • Jan 2013
          • 8

          #5
          ......It seems that some of the "old" problems belongs to host that are meanwhile disabled!?

          Comment

          • dimir
            Zabbix developer
            • Apr 2011
            • 1080

            #6
            Could you show your request?
            And do you use the same user account for connecting to Frontend and for connecting to API?

            Comment

            • dimir
              Zabbix developer
              • Apr 2011
              • 1080

              #7
              OK, I think I've got it. Dashboard does not show disabled/in maintenance hosts, it works this way:

              Code:
              - get problems
              - for each problem
                - fetch its trigger with filter {'monitored' => true} (which means filter out disabled hosts)
                - if nothing is returned, disregard this problem
              You would need to do something similar.
              Last edited by dimir; 05-03-2021, 09:59.

              Comment

              • HoCaM
                Junior Member
                • Jan 2013
                • 8

                #8
                Hi Dimir,
                i am ussing a dedicated user for API but i have already checked the results when logging into the GUI with this user. I got the same result which was expected since the this user and the user i normally use for the GUI are in the same group and have therefore identical permissions.
                I will try to realize what you have suggested (looping through the problems and fetching the trigger/host information). Once i got this working (with a reasonable performance) i will post the solution here...
                Many thanks so far.
                Take Care

                Comment

                • HoCaM
                  Junior Member
                  • Jan 2013
                  • 8

                  #9
                  Hi Dimir,

                  thanks for your hints. The gamechanger was to use the monitored_hosts flag.

                  For all that have to achieve something similar, my solution looks like:

                  1. Create a function that extract all MONITORED hosts using:
                  ""method"": ""host.get"",
                  ""params"": {
                  ""output"": [""hostid"",""host"",""status"",""name""],
                  ""monitored_hosts"" : [true]
                  2. Convert the table-column "hostid" to a list and finally to a variable (VAR1, type string) like "[hostid1,hostid2,hostid3,....]"
                  3. Fire the final problems query using the previously created string
                  ""method"": ""problem.get"",
                  ""params"": {
                  ""output"": [""eventid"", ""name"",""severity"",""objectid""],
                  ""hostids"": " & VAR1 & ",
                  ""sortfield"": ""eventid"",
                  ""sortorder"": ""DESC""
                  4. This results in a table of current, unresolved problems for all actively monitored hosts.

                  As mentioned this has been realized with Power BI. Fair to say that - as far as i know - you cannot set the Power Bi report refresh cycle to 60 sec or so meaning this solution is probably not suitable for realtime monitoring/alerting!

                  Comment

                  • dimir
                    Zabbix developer
                    • Apr 2011
                    • 1080

                    #10
                    Yeah, that's another way of doing it. I mean instead of fetching all problems and then check if host is enabled, get list of enabled hosts and then fetch problems of those. Depending on how many hosts you have in the system one or another approach could be more effective.
                    In the end, did you achieve the goal, meaning the result is the same as on the dashboard?

                    Comment


                    • HoCaM
                      HoCaM commented
                      Editing a comment
                      Yes, both dashboards showing the same content.
                  Working...