#!/usr/bin/env python #-*- coding:utf-8 -*- import sys import json import urllib2 from optparse import OptionParser class ZabbixApi(): def __init__(self): self.url="https://zabbix_address/api_jsonrpc.php" self.header={"Content-Type":"application/json"} def Token(self): data=json.dumps({ "jsonrpc": "2.0", "method": "user.login", "params": { "user": "xxxxx", "password": "xxxxx" }, "id": 1 }) request=urllib2.Request(self.url,data) for key in self.header: request.add_header(key,self.header[key]) try: result = urllib2.urlopen(request) response = json.loads(result.read()) return response['result'] except urllib2.URLError as e: print "