Ad Widget

Collapse

How to connect to zabbix 3.0 frontend via python

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lorenzo Alfieri
    Junior Member
    • Nov 2014
    • 7

    #1

    How to connect to zabbix 3.0 frontend via python

    Hi I am trying to get the graph image connecting to the frontend via http request in python.

    I know how to get the graph image, but I cant figure out how to login with urlib2.

    What i have actualy is that :
    Code:
    def login(config):
        url = u'%s/index.php' % config.zabbix_frontend_url
        data = urlencode(dict(
            form='1',
            form_refresh='1',
            name=config.zabbix_username,
            password=config.zabbix_password,
            enter='Enter'))
        cookie_jar = CookieJar()
        cookie_processor = HTTPCookieProcessor(cookie_jar)
        opener = build_opener(cookie_processor)
        # since we only call the index page to login, we are not interested in the output    
        # TODO error handling                                                                
        install_opener(opener)
        urlopen(url, data)
    Since its the first time i use urllib, it can come from that, or just i dont get how to connect to zabbix and handle the connection. PLease help me find out how to do that.
  • peatb
    Zabbix Certified Trainer
    Zabbix Certified Trainer
    Zabbix Certified SpecialistZabbix Certified Professional
    • Aug 2016
    • 36

    #2
    The best way to connect to zabbix here is by using the api. There is a complete implementation of that in python: pyzabbix.

    On redhat based systems you can install that with:
    # yum install python-pip
    # pip install pyzabbix

    I can also recommend the zabbix-gnomes which implements pyzabbix into easy to use scripts: https://github.com/q1x/zabbix-gnomes
    (one of the gnomes is specifically made to fetch graphs)

    Comment

    • Lorenzo Alfieri
      Junior Member
      • Nov 2014
      • 7

      #3
      I check that but i dont think i can get what i want with the API

      Comment

      • Lorenzo Alfieri
        Junior Member
        • Nov 2014
        • 7

        #4
        Ok so simply in the code of what you linked, one of the script is used to get graph, zgetgraph.py, and i checked the code and see that to connect the field 'enter' is set to 'Sign in', while in 2.x it was "Enter".

        That was the mistake i did since i use 3.0, so problem solved it work. Thank you for the link peatb.

        Comment

        Working...