Ad Widget

Collapse

login api with http authentificate

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aoc
    Junior Member
    • Aug 2014
    • 2

    #1

    login api with http authentificate

    hi,
    i have a problem that i can't resolve since few days.
    I try to connect my zabbix with api in http connection.

    It's work fine with internal but have error with http.

    #!/usr/bin/env python
    import urllib2
    import json
    def authenticate(url, username, password):
    values = {'jsonrpc': '2.0',
    'method': 'user.authenticate',
    'params': {
    'user': username,
    'password': password,
    },
    'id': '0'
    }

    data = json.dumps(values)
    req = urllib2.Request(url, data, {'Content-Type': 'application/json-rpc'})
    response = urllib2.urlopen(req, data)
    output = json.loads(response.read())
    print output

    try:
    message = output['result']
    except:
    message = output['error']['data']
    print message
    quit()

    return output['result']
    def main():
    url = 'http://localhost/zabbix/api_jsonrpc.php'
    username = "admin"
    password = "zabbix"
    auth = authenticate(url,username,password)
    if __name__ == '__main__':
    main()
    Cannot login.


    Can anyone have an idea?

    Thanks
    Last edited by aoc; 22-08-2014, 14:05.
  • JFontes
    Member
    Zabbix Certified Specialist
    • Jul 2012
    • 36

    #2
    Originally posted by aoc
    hi,
    i have a problem that i can't resolve since few days.
    I try to connect my zabbix with api in http connection.

    It's work fine with internal but have error with http.



    Cannot login.


    Can anyone have an idea?

    Thanks
    Have your zabbix installed in the correct path? "url = 'http://localhost/zabbix/api_jsonrpc.php'"

    You need change this part:

    'user': username,
    'password': password,
    },
    'id': '0'
    }

    your username, your passwd and id 1.

    Comment

    • aoc
      Junior Member
      • Aug 2014
      • 2

      #3
      thanks for your repply.
      I have the username and password already defined from main.
      So i don't understand.
      Any one have an idea?

      Comment

      Working...