Ad Widget

Collapse

Zabbix API with http authentication

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • atelesca
    Junior Member
    • Mar 2012
    • 6

    #1

    Zabbix API with http authentication

    Hello,
    does anyone know how can I make the API work with http authentication?

    My server is configured with Shibboleth authentication and the user is successfully authentication via the Zabbix frontend.
    However, the following code from the API that was working with internal authentication:


    import simplejson as json
    import urllib2
    import sys

    obj = {
    "jsonrpc": "2.0",
    "method": "user.login",
    "params": {
    "user": "xxxxx",
    "password": "xxxxx"
    },
    "id": 1
    }

    url = 'http://xxxxxxxxx/zabbix/api_jsonrpc.php'
    data = json.dumps(obj)
    request = urllib2.Request(url, data, {'Content-Type': 'application/json'})
    response = urllib2.urlopen(request)
    res = json.load(response)
    if 'error' in res:
    # An error occurred; raise an exception
    print 'An error occurred! %s' %res["error"]
    sys.exit(-1)

    hash_pass=res["result"]
    print hash_pass



    now gives me the following error because it does not manage to reach the zabbix API.
    Traceback (most recent call last):
    File "host_creation.py", line 20, in ?
    res = json.load(response)
    File "/usr/lib64/python2.4/site-packages/simplejson/__init__.py", line 267, in load
    parse_constant=parse_constant, **kw)
    File "/usr/lib64/python2.4/site-packages/simplejson/__init__.py", line 307, in loads
    return _default_decoder.decode(s)
    File "/usr/lib64/python2.4/site-packages/simplejson/decoder.py", line 335, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    File "/usr/lib64/python2.4/site-packages/simplejson/decoder.py", line 353, in raw_decode
    raise ValueError("No JSON object could be decoded")
    ValueError: No JSON object could be decoded



    It gets blocked by the SSO authentication that comes before the Zabbix login.

    Do you have any ideas?
    Thanks.
    Cheers,
    Adriana
  • Pavels
    Member
    • Oct 2011
    • 83

    #2
    To pass the HTTP authentication you'll need to include the HTTP "Authenticate" header with each API request. You can find more info about that here http://www.httpwatch.com/httpgallery/authentication/

    Then, as usual, you login into the API itself using the user.login method, but with HTTP authentication you don't need to specify the password, only the user name. Everything else works as usual.

    You can check out the Zabbix API libraries available for python, some of them include HTTP authentication support https://www.zabbix.org/wiki/Docs/api/libraries
    Last edited by Pavels; 13-02-2013, 10:20.

    Comment

    Working...