Esempio n. 1
0
    decode_user_attribute = json.loads(
        base64.b64decode(decode_consul_kv[0]["Value"]))
    system_domain = decode_user_attribute['dns']
    system_name = decode_user_attribute['name']

    # Create ZabbixAPI class instance
    try:
        zapi = ZabbixAPI(url=zabbix_url,
                         user=zabbix_user,
                         password=zabbix_password)
    except Exception, e:
        print e, 'ZabbixAPI: Authenticate failed.'

    # Get Zabbix API version
    try:
        result_version = zapi.api_version()
    except:
        result_version = "2.4"

    # Hostgroup get
    hostgroup = system_name
    try:
        result_hostgroup = zapi.do_request('hostgroup.get',
                                           {'filter': {
                                               'name': hostgroup
                                           }})
        if not result_hostgroup['result']:
            print 'Can not be found host group ' + hostgroup
            exit(-1)
        else:
            hostgroup_id = result_hostgroup['result'][0]['groupid']
    # Getting Consul KV
    consul_kv = get_kv("cloudconductor/system_domain",ret_url_encode(os.environ['CONSUL_SECRET_KEY']))
    decode_consul_kv = json.loads(consul_kv)
    decode_user_attribute = json.loads(base64.b64decode(decode_consul_kv[0]["Value"]))
    system_domain = decode_user_attribute['dns']
    system_name = decode_user_attribute['name']

    # Create ZabbixAPI class instance
    try:
        zapi = ZabbixAPI(url=zabbix_url, user=zabbix_user, password=zabbix_password)
    except Exception, e:
        print e, 'ZabbixAPI: Authenticate failed.'

    # Get Zabbix API version
    try:
        result_version = zapi.api_version()
    except:
        result_version = "2.4"

    # Hostgroup get
    hostgroup = system_name
    try:
        result_hostgroup = zapi.do_request('hostgroup.get', { 'filter': {'name': hostgroup}})
        if not result_hostgroup['result']:
            print 'Can not be found host group ' + hostgroup
            exit (-1)
        else:
            hostgroup_id = result_hostgroup['result'][0]['groupid']
    except Exception, e:
        print e, 'ZabbixAPI: hostgroup.get exist failed.'