Ad Widget

Collapse

Using API to pull all triggers over last 24hrs

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • obrienmd
    Junior Member
    • Jul 2010
    • 26

    #1

    Using API to pull all triggers over last 24hrs

    I'm attempting to build a script which will automatically e-mail all Zabbix triggers over the last 24 hours to a predefined group (IE: hosts going up/down, etc, etc). We already have immediate e-mail from the Zabbix interface to predefined groups upon important triggers.

    It seems that what I 'get' 'trigger' items using the API, I don't actually get trigger "events", I just get a list of triggers that are available. Is there a different object I can use to grab an array w/ all instances of trigger events, and associated data (host, status, etc, etc, etc)?

    Thanks!
  • nelsonab
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Sep 2006
    • 1233

    #2
    Try the events class. I haven't managed to work with it much yet but I think it might get you closer to where you want to go.

    A few things to note, keep track of the API version number, Right now when the number increases expect your code to break until things settle out. :-) Also be sure to submit bugs when you find them.

    If you want I can prioritize adding it to my base API library.
    RHCE, author of zbxapi
    Ansible, the missing piece (Zabconf 2017): https://www.youtube.com/watch?v=R5T9NidjjDE
    Zabbix and SNMP on Linux (Zabconf 2015): https://www.youtube.com/watch?v=98PEHpLFVHM

    Comment

    • obrienmd
      Junior Member
      • Jul 2010
      • 26

      #3
      I'm using the PHP class for the API - I will keep an eye out for changes, though.

      Will try to work with the events class, and let you know how it works out... hopefully in the next hour or two

      Comment

      • obrienmd
        Junior Member
        • Jul 2010
        • 26

        #4
        OK, when I use the following code after loading the PHP library:
        ZabbixAPI::fetch_array('event','get',array())

        And print_r the results, I get "Array ( [0] => )"

        The execution time of the fetch_array is LONG, and CPU is pegged.

        Comment

        • nelsonab
          Senior Member
          Zabbix Certified SpecialistZabbix Certified Professional
          • Sep 2006
          • 1233

          #5
          That looks like a bug to me!
          RHCE, author of zbxapi
          Ansible, the missing piece (Zabconf 2017): https://www.youtube.com/watch?v=R5T9NidjjDE
          Zabbix and SNMP on Linux (Zabconf 2015): https://www.youtube.com/watch?v=98PEHpLFVHM

          Comment

          • obrienmd
            Junior Member
            • Jul 2010
            • 26

            #6
            Best place to post bug? I've added in php class dev's original blog post, and Zabbix forum thread.

            Comment

            • nelsonab
              Senior Member
              Zabbix Certified SpecialistZabbix Certified Professional
              • Sep 2006
              • 1233

              #7


              I don't think it's a bug with the API interface, but with the API itself.
              RHCE, author of zbxapi
              Ansible, the missing piece (Zabconf 2017): https://www.youtube.com/watch?v=R5T9NidjjDE
              Zabbix and SNMP on Linux (Zabconf 2015): https://www.youtube.com/watch?v=98PEHpLFVHM

              Comment

              • obrienmd
                Junior Member
                • Jul 2010
                • 26

                #8
                Posted bug: https://support.zabbix.com/browse/ZBX-2732

                Please let me know if you think there's any more relevant info I need to put in there!

                Comment

                • nelsonab
                  Senior Member
                  Zabbix Certified SpecialistZabbix Certified Professional
                  • Sep 2006
                  • 1233

                  #9
                  Looks to be about the right minimum. I have a hunch there's a loop in the API code or other race condition preventing it from returning.
                  RHCE, author of zbxapi
                  Ansible, the missing piece (Zabconf 2017): https://www.youtube.com/watch?v=R5T9NidjjDE
                  Zabbix and SNMP on Linux (Zabconf 2015): https://www.youtube.com/watch?v=98PEHpLFVHM

                  Comment

                  • obrienmd
                    Junior Member
                    • Jul 2010
                    • 26

                    #10
                    Would you be interested in adding a comment to the linked ticket with your thoughts?

                    Comment

                    • obrienmd
                      Junior Member
                      • Jul 2010
                      • 26

                      #11
                      Ticket was closed, stating 1.8.3 fixed this, but I upgraded to 1.8.3 (built from source) and the problem persisted. Script returned same result fairly quickly, but the apache process pegged the CPU until PHP maximum execution time had been reached.

                      Comment

                      • nelsonab
                        Senior Member
                        Zabbix Certified SpecialistZabbix Certified Professional
                        • Sep 2006
                        • 1233

                        #12
                        If you did download the latest trunk and the bug still exists then I'd reopen the ticket. However if you downloaded the nightly build then it's likely the fix hasn't made it in. In my experience the team is pretty good at fixing the pretty straight forward bugs when someone draws attention to them, and I'm willing to bet this was a straight forward bug. As for arrays vs hashes... well that's another story... :-)
                        RHCE, author of zbxapi
                        Ansible, the missing piece (Zabconf 2017): https://www.youtube.com/watch?v=R5T9NidjjDE
                        Zabbix and SNMP on Linux (Zabconf 2015): https://www.youtube.com/watch?v=98PEHpLFVHM

                        Comment

                        • obrienmd
                          Junior Member
                          • Jul 2010
                          • 26

                          #13
                          Hrm, will pull trunk later today and try again.

                          Comment

                          • obrienmd
                            Junior Member
                            • Jul 2010
                            • 26

                            #14
                            Latest trunk wouldn't build for me, but I'm running this build (latest nightly 1.8.3):

                            Zabbix Server v1.8.3 (revision 13392) (29 March 2010)
                            Compilation time: Jul 21 2010 09:35:53

                            Comment

                            • obrienmd
                              Junior Member
                              • Jul 2010
                              • 26

                              #15
                              Hrm, so ticket was closed, closer noted that fix was not in trunk, but in dev branch... I was able to checkout/build most branches, but dev branch is a mystery to me... any tips on how to apply patches / merge the api work in dev that addresses this?

                              Comment

                              Working...