Ad Widget

Collapse

API Discussion

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nelsonab
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Sep 2006
    • 1233

    #16
    Some progress has ben made

    I've made some progress towards getting a REST interface working.

    Here is an example:

    Code:
    [{"clock":"1208763391","value":"0.0166"}]
    I thought I'd throw the VERY rough draft to get some comments.

    Before trying this you will need mod_rewrite running and working on your Apache install. I am running on OpenSuSE 11 and had to change the "AllowOverride" option from None to All in the default-server.conf file.

    To install it untar the attached tarball in your zabbix directory. This should create a subdirectory called api. In this directory you will find a .htaccess file. You may need to edit this file depending on your system. The api directory should owned and writeable by the process apache is running as.

    You will also need to edit your zabbix.conf.php file in the conf directory. The following variable needs to be added: ZBX_API_BASE_URL here is an example:
    PHP Code:
    $ZBX_API_BASE_URL  "/api"
    The variable should point to the directory which you have placed the API into.

    To access the REST interface point your browser to your zabbix server and api directory such as:



    You will then be prompted to enter a valid zabbix username and password. Next you will see a JSON object of all active hosts on your system.

    The following query:
    http://zabbix-server/api/host/<hostid>
    Will return information on the one host.

    http://zabbix-server/api/host/<hostid>/items
    Will return a list of all items associated with a host.

    http://zabbix-server/api/history/<itemid>
    Will return the most recent history table result for the item given. Only the history table is queried for now.

    With history you can also do more complex queries such as:
    http://zabbix-server/api/history/<itemid>?starttime=<startime>&endtime=<endtime>&re verse
    This will return all values for itemid in the history table where the time is between starttime and endtime and return it in reverse order. One caviat is that the query will automatically limit itself to 100,000 items unless told otherwise. This is done to speed query performance and prevent runaway queries. More information on the available options are in the comments within the zabbixrest.php file.

    As you use the interface a log file is generated. You can disable logging by removing the logfile name in the constructor in the index.php file. The log file will log plaintext passwords as it does a dump of the $_SERVER variable. (This is work in progress )

    Right now only GET actions are supported.

    I hope to get some progress made on PUT in a few days.

    Note: Very little error checking is made on the perameters. You have been warned.
    Attached Files
    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

    • richlv
      Senior Member
      Zabbix Certified Trainer
      Zabbix Certified SpecialistZabbix Certified Professional
      • Oct 2005
      • 3112

      #17
      nice. if i understand this correctly, this builds upon web frontend and requires it up and running, right ?
      that would still mean two separate db touching processes, frontend and server.
      though i can't quite imagine how could an api be easily built that would eliminate these two different implementations and still be fast & robust enough =)
      Zabbix 3.0 Network Monitoring book

      Comment

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

        #18
        You are correct, this basically extends the php frontend. I have tried to reuse as much code as possible, but in some cases that's easier said than done. :-) Either way you're going to have to make some kind of network layer. Using a HTTP like interface is the most flexible for applications today so it made the most sense to extend the frontend for now.

        Now I was thinking the other day and did some research on this, what would be REALLY awesome would be to add LUA scripting to the Zabbix Server. The nice thing about that is you could then create custom functions for triggers and importing of data. The other nice thing about LUA is that it's small and fast. According to the language shootout it is one of the faster languages.

        I might hack something together with LUA when I get a chance next. :-)
        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

        • lamont
          Member
          • Nov 2007
          • 89

          #19
          Originally posted by nelsonab
          The other nice thing about LUA is that it's small and fast. According to the language shootout it is one of the faster languages.
          “More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity.” - W.A. Wulf

          “We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.” - Donald Knuth

          “Bottlenecks occur in surprising places, so don't try to second guess and put in a speed hack until you have proven that's where the bottleneck is.” - Rob Pike

          “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson'

          I might hack something together with LUA when I get a chance next. :-)
          it sounds like the problem you are solving is that you don't get to do enough LUA programming...

          Comment

          • Alexei
            Founder, CEO
            Zabbix Certified Trainer
            Zabbix Certified SpecialistZabbix Certified Professional
            • Sep 2004
            • 5654

            #20
            Lamont, do you collect excuses? You must be extremely lazy person!
            Alexei Vladishev
            Creator of Zabbix, Product manager
            New York | Tokyo | Riga
            My Twitter

            Comment

            • lamont
              Member
              • Nov 2007
              • 89

              #21
              Originally posted by Alexei
              Lamont, do you collect excuses? You must be extremely lazy person!
              no, i just remembered a portion of the knuth quote and hit wikipedia and found a gold mine...

              but yeah, i'm too lazy to get through my entire language TODO list of learning python, php, lua, ruby and haskell...

              oh, more java experience would be good, too, since our software devs are basically a java shop...

              Comment

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

                #22
                Originally posted by lamont
                no, i just remembered a portion of the knuth quote and hit wikipedia and found a gold mine...

                but yeah, i'm too lazy to get through my entire language TODO list of learning python, php, lua, ruby and haskell...

                oh, more java experience would be good, too, since our software devs are basically a java shop...
                You forgot Ruby... ;-) That is unless you know it already, if that is the case, YEAH!

                I found Lua to be an extremely easy to pick up language. There is an IMAP filter application that uses Lua as it's scripting language. One day I started to write some IMAP filter scripts, next thing I kenw I was writing a framework to handle abstracted filtration. Yes I was building a nailgun to put a nail in the wall to hang a picture. ;-)
                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

                • mlange
                  Member
                  • Sep 2008
                  • 78

                  #23
                  Will the API be part of the upcoming 1.8 version? We tested it and extended some functions - it is really useful esp. for large environments. Managing the configuration in the frontend only is simply not not enough.

                  Comment

                  • Alexei
                    Founder, CEO
                    Zabbix Certified Trainer
                    Zabbix Certified SpecialistZabbix Certified Professional
                    • Sep 2004
                    • 5654

                    #24
                    Originally posted by mlange
                    Will the API be part of the upcoming 1.8 version?
                    Yes, it will!
                    Alexei Vladishev
                    Creator of Zabbix, Product manager
                    New York | Tokyo | Riga
                    My Twitter

                    Comment

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

                      #25
                      What's the roadmap look like for it? Any chance some of us could help "vet" (assist with a peer review) the API specification to head off any potential shortcomings?
                      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

                      • mlange
                        Member
                        • Sep 2008
                        • 78

                        #26
                        We are really looking forward to seeing this! The missing API is a lack which prevents Zabbix to be used in automated environments.

                        Comment

                        • lamont
                          Member
                          • Nov 2007
                          • 89

                          #27
                          Originally posted by nelsonab
                          You forgot Ruby... ;-) That is unless you know it already, if that is the case, YEAH!
                          nope, didn't forget it. i had ruby up there.

                          i played around with ruby, i think around ruby-1.4 sometime around 2002 (?) and found it to be a very nice language and i liked it a lot. it improved my perl programming quite a bit to play with ruby (heh). the only problem was that after creating some ruby scripts it became obvious that i was going to become the single-point-of-failure for those scripts since nobody else in that organization knew ruby.

                          if i had it all to do over again at my current job i'd probably have started off programming in ruby. i picked perl because i thought it would be easier to hire SAs who knew perl and get the jr SAs at work programming in perl, based on my prior experience. however, we've lost everyone who knew any perl, i'm despairing of the jr SAs ever stopping writing scripts in bash, and we can't seem to hire anyone -- so i might as well have just been selfish in choice of language and gone with something interesting and pretty...

                          oh, and I'm *EXTREMELY* excited about the mention of the API in 1.8

                          can't wait...
                          Last edited by lamont; 02-05-2009, 23:23.

                          Comment

                          • Alexei
                            Founder, CEO
                            Zabbix Certified Trainer
                            Zabbix Certified SpecialistZabbix Certified Professional
                            • Sep 2004
                            • 5654

                            #28
                            Originally posted by nelsonab
                            What's the roadmap look like for it? Any chance some of us could help "vet" (assist with a peer review) the API specification to head off any potential shortcomings?
                            Sure! I would like to have the first API functions (auth, host related stuff) to be ready and documented before first beta of 1.8. It does not mean that the API will be frozen, it will be ready for corrections and improvements!
                            Alexei Vladishev
                            Creator of Zabbix, Product manager
                            New York | Tokyo | Riga
                            My Twitter

                            Comment

                            • lamont
                              Member
                              • Nov 2007
                              • 89

                              #29
                              if you want to know what i'm doing right now via some hacked together scripts:

                              1 - getting a list of hosts on the server
                              2 - getting a list of triggers setup on a host
                              3 - creating hosts remotely
                              4 - creating items remotely
                              5 - creating triggers remotely
                              6 - creating it services remotely

                              and i'm doing a lot of create_if_not_exist() style of semantics.

                              for some things like hosts and items you can't create duplicate entries, and the create will fail if the object already exists -- but for triggers and it services you need to check for existence first before creating. and its at least a nice-to-have to pay some attention to concurrency issues and atomicity so that having the client of the API do a check (select) and then a create (insert) doesn't concurrently race and create duplicate entries.

                              some other nice-to-haves:

                              - creating graphs remotely
                              - adding graphs to screens remotely

                              Comment

                              • Alexei
                                Founder, CEO
                                Zabbix Certified Trainer
                                Zabbix Certified SpecialistZabbix Certified Professional
                                • Sep 2004
                                • 5654

                                #30
                                Please vote for the API there: http://www.zabbix.com/forum/showthread.php?t=12460

                                Alexei Vladishev
                                Creator of Zabbix, Product manager
                                New York | Tokyo | Riga
                                My Twitter

                                Comment

                                Working...