Ad Widget

Collapse

Build screens fast using API

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fvdhoeven
    Junior Member
    • Apr 2013
    • 11

    #1

    Build screens fast using API

    I've build a script in python to quickly build a screen from several hosts (or a switch) which uses the API of Zabbix. It can be found here:
    zabbix-screenbuilder

    I had the need for a script like this because I was monitoring some switches with auto discovery of the ports and wanted to display the discovered ports in a screen. Currently that is not possible in Zabbix so i built this script.

    Feel free to improve upon it It was build quickly and maybe not in the most efficient way, but it got the job done.
  • tchjts1
    Senior Member
    • May 2008
    • 1605

    #2
    I haven't tried it, but I like the concept.
    I can see where this may come in handy.

    Comment

    • steveboyson
      Senior Member
      • Jul 2013
      • 582

      #3
      Select hostgroup: 12
      selectHostgroup - Hostgroup selected (hostgroupid: 15, hostgroupname: Physical servers)
      Something went wrong
      Error: addstr() returned ERR
      Traceback (most recent call last):
      File "screenbuilder.py", line 406, in <module>
      main()
      File "screenbuilder.py", line 385, in main
      doMenu(menu)
      File "screenbuilder.py", line 241, in doMenu
      processmenu(menu_data)
      File "screenbuilder.py", line 227, in processmenu
      processmenu(menu['options'][getin], menu) # display the submenu
      File "screenbuilder.py", line 224, in processmenu
      if getin == optioncount:
      UnboundLocalError: local variable 'getin' referenced before assignment

      Comment

      • fvdhoeven
        Junior Member
        • Apr 2013
        • 11

        #4
        Python version

        It might have something to do with the python version. I've build and tested (and used) this with version 2.6.6 and on CentOS. I haven't tested this on different versions or platforms.

        Comment

        • steveboyson
          Senior Member
          • Jul 2013
          • 582

          #5
          It's a SuSE 12.3 box with Python 2.7.3

          Comment

          • pgcorchary
            Junior Member
            • Dec 2014
            • 1

            #6
            Super! ... but issues

            First of all .. this is SUPER. I have been looking for something like this EXACTLY. I have a 1/2 built script of my own, but the goals were no as ambitious, only to create a screen of one item for all hosts of a named hostgroups.

            Anyway ... I tried your script and got the following.

            ...
            Connected to Zabbix API Version: 2.2.3
            ...

            Traceback (most recent call last):
            File "./screenbuilder.py", line 406, in <module>
            main()
            File "./screenbuilder.py", line 387, in main
            checkScreenGraphs(hostgroupid, hostgroupname, menu)
            File "./screenbuilder.py", line 335, in checkScreenGraphs
            storeScreenGraphs(hostgroupid, hostgroupname, menu_data, screenid)
            File "./screenbuilder.py", line 260, in storeScreenGraphs
            zapi.screenitem.create(screenitem)
            AttributeError: 'ZabbixAPI' object has no attribute 'screenitem'

            It correctly got all HGs, hosts, and items, and at the very last step to build the graph, threw this error as above. Thoughts?

            Comment

            • fvdhoeven
              Junior Member
              • Apr 2013
              • 11

              #7
              Will check

              I will have a look at it later today. I'll report back!

              Comment

              • fvdhoeven
                Junior Member
                • Apr 2013
                • 11

                #8
                Replaced API library

                I also had some errors when I tried to use it again. In my case I upgraded Zabbix to a newer version and it stopped working. So I downloaded a newer zabbix API library (courtesy of https://github.com/gescheit/scripts/tree/master/zabbix) and then it worked again. I've updated the code on github.

                Hope this helped!

                Comment

                • steveboyson
                  Senior Member
                  • Jul 2013
                  • 582

                  #9
                  Unfortunately, it doesn't work.

                  :::
                  Code:
                  Connecting to Zabbix API
                  Zabbix API connection failed
                  Additional info: (u'Error -32602: Invalid params., Not authorized while sending {"params": {}, "jsonrpc": "2.0", "method": "APIInfo.version", "id": 1}', -32602)

                  Comment

                  • steveboyson
                    Senior Member
                    • Jul 2013
                    • 582

                    #10
                    zabbix_api.py MD5 is
                    00d43d60387cb06c138fce52d6e38704 zabbix_api.py
                    and lives in /usr/lib/python2.7/site-packages/zabbix_api-0.1-py2.7.egg

                    (I downloaded the most current release of the API and installed with "python setup.py install"). The .pyc gets compiled there, though.

                    The example from zabbix_api works (sort of).

                    Comment

                    • fvdhoeven
                      Junior Member
                      • Apr 2013
                      • 11

                      #11
                      lib folder

                      My script doesn't use the library you just installed. It uses the library in the lib folder provider with my script. So updating it on your server, won't help.

                      You can however remove this line:
                      sys.path.append('./lib')

                      so that the script does use the API installed on your server, or update the library in the lib folder.

                      Comment

                      • steveboyson
                        Senior Member
                        • Jul 2013
                        • 582

                        #12
                        Makes no difference, with none of the available zabbix_api.py screenbuilder works here.

                        Comment

                        • steveboyson
                          Senior Member
                          • Jul 2013
                          • 582

                          #13
                          Funny: using the old "zabbix_api.py" (14838 bytes) the program starts, screen_info.py even gives an output.

                          But after configuring some graphs/hosts it bails out with:
                          Code:
                          Do you want to create a screen called "Screenbuilder" with these graphs? (Yes/No): Yes
                          OK
                          Traceback (most recent call last):
                            File "screenbuilder.py", line 406, in <module>
                              main()
                            File "screenbuilder.py", line 387, in main
                              checkScreenGraphs(hostgroupid, hostgroupname, menu)
                            File "screenbuilder.py", line 335, in checkScreenGraphs
                              storeScreenGraphs(hostgroupid, hostgroupname, menu_data, screenid)
                            File "screenbuilder.py", line 294, in storeScreenGraphs
                              zapi.screenitem.create(screenitem)
                            File "./lib/zabbix_api.py", line 357, in method
                              return self.universal("%s.%s" % (self.data["prefix"], name), opts[0])
                            File "./lib/zabbix_api.py", line 80, in wrapper
                              return self.do_request(self.json_obj(method, opts))['result']
                            File "./lib/zabbix_api.py", line 364, in do_request
                              return self.parent.do_request(req)
                            File "./lib/zabbix_api.py", line 318, in do_request
                              raise ZabbixAPIException(msg, jobj['error']['code'])
                          zabbix_api.ZabbixAPIException: (u'Error -32500: Application error., Incorrect row span provided for screen element located at X - 0 and Y - 0. while sending {"params": {"resourcetype": 0, "resourceid": "2723", "screenid": "225", "height": "200", "width": "500", "y": 0, "x": 0}, "jsonrpc": "2.0", "method": "screenitem.create", "auth": "2a5a98fb94c6b572f8d1319627f6af10", "id": 13}', -32500)

                          Comment

                          • steveboyson
                            Senior Member
                            • Jul 2013
                            • 582

                            #14
                            Updated our Zabbix installation from 2.0.10 to 2.0.13.
                            Still does not work :-(

                            Comment

                            • almirf
                              Junior Member
                              • Sep 2015
                              • 29

                              #15
                              Dear fvdhoeven

                              Im have a problem, im need to show my screen sorted my values of an item

                              With this API im can do this?

                              im can do for examplle one TOP20 with the best 20 screens that have higher value of incoming traffic ?

                              Thanks
                              Almir



                              Originally posted by fvdhoeven
                              I've build a script in python to quickly build a screen from several hosts (or a switch) which uses the API of Zabbix. It can be found here:
                              zabbix-screenbuilder

                              I had the need for a script like this because I was monitoring some switches with auto discovery of the ports and wanted to display the discovered ports in a screen. Currently that is not possible in Zabbix so i built this script.

                              Feel free to improve upon it It was build quickly and maybe not in the most efficient way, but it got the job done.

                              Comment

                              Working...