Exemplo n.º 1
0
def check_neutron():
    neutron_url = None
    req_count = '1'
    auth_url, tenant_name, user_name,password,region=get_auth()
    headers = {'content-type': 'application/json'}
    try:
        auth_response = get_auth_response()

        if not auth_response['access']['token']['id']:
            raise Exception("Authentication failed. Failed to get an auth token.")

        auth_token = auth_response['access']['token']['id']

        tenant_id = auth_response['access']['token']['tenant']['id']

        services = auth_response['access']['serviceCatalog']

        if neutron_url is None:
            for service in services:
                if service['type'] == 'network':
                    if region:
                        for region_urls in service['endpoints']:
                            if region_urls['region'] == region:
                                neutron_url = region_urls['publicURL']
                    else:
                        neutron_url = service['endpoints'][0]['publicURL']
        else:
            neutron_url = neutron_url


        if neutron_url is None:
            raise Exception("Authentication succeeded but unable to find network service")
            
    except Exception as e:
        print 'WARNING: Athentication failed for tenant %s and user %s' % (tenant_name, user_name)

    headers['X-Auth-Token'] = auth_token
    #neutron_networks_response = requests.get(neutron_url + '/v2.0/networks', headers=headers, verify=False).json()
    #print neutron_networks_response
    try:
        neutron_networks_response = requests.get(neutron_url + '/v2.0/networks', headers=headers, verify=False).json()
        
        network_count = 0
        for network in neutron_networks_response['networks']:
            network_count += 1

        if req_count and network_count < int(req_count):
            print "CRITICAL: %d networks found less than required %d" % (network_count, int(req_count))

        if req_count:
            print "OK: Retrieved %d networks, required %d" % (network_count, int(req_count))
        else:
            print "OK: Retrieved %d networks" % (network_count)


    except Exception as e:
        print 'CRITICAL:Unable to retrieve networks for tenant %s' % (tenant_name)
Exemplo n.º 2
0
def check_glance():
    glance_url = None
    req_count = "1" 
    auth_url, tenant_name, user_name,password,region=get_auth()
    headers = {'content-type': 'application/json'}
    try:
        auth_response = get_auth_response();

        if not auth_response['access']['token']['id']:
            raise Exception("Authentication failed. Failed to get an auth token.")

        auth_token = auth_response['access']['token']['id']

        services = auth_response['access']['serviceCatalog']
       
        if glance_url is None:
            for service in services:
                if service['type'] == 'image':
                    if region:
                        for region_urls in service['endpoints']:
                            if region_urls['region'] == region:
                                glance_url = region_urls['publicURL']
                    else:
                        glance_url = service['endpoints'][0]['publicURL']
        else:
            glance_url = glance_url

        if glance_url is None:
            raise Exception("Authentication succeeded but unable to find image service")

    except Exception as e:
        print 'WARNING: Athentication failed for tenant %s and user %s' % (tenant_name, user_name) 

    headers['X-Auth-Token'] = auth_token  

    try:
        glance_images_list_response = requests.get(glance_url + '/images', headers=headers, verify=False).json()
        image_count = 0
        if 'images' in glance_images_list_response:
            for image in glance_images_list_response['images']:
                image_count += 1
            if req_count and image_count < int(req_count):
                print "CRITICAL: %d images found less than required %d" % (image_count, int(req_count)) 
     
        if req_count: 
            print "OK: Retrieved %d images, required %d" % (image_count, int(req_count))
        else:
            print "OK: Retrieved %d images" % (image_count)


    except Exception as e:
        print e
        print 'CRITICAL: Failed to retrieve images for tenant %s and user %s' % (tenant_name, user_name) 
Exemplo n.º 3
0
def check_nova():
    auth_url, tenant_name, user_name,password,region=get_auth()
    nova_url = None
    req_count = '1'
    #requst keystone to generate token for tenant_name
    auth_response = get_auth_response()
    headers = {'content-type': 'application/json'}
    #get token id
    auth_token = auth_response['access']['token']['id']

    if auth_token is None:
            print 'CRITICAL: Failed to generate an auth token for tenant %s and user %s' % (tenant_name, user_name)

    tenant_id = auth_response['access']['token']['tenant']['id']
    services = auth_response['access']['serviceCatalog']

    #get nova_url from services if not known
    if nova_url is None:
    	for service in services:
            	if service['type'] == 'compute':
                    	if region:
                        		for region_urls in service['endpoints']:
                            			if region_urls['region'] == region:
                                			nova_url = region_urls['publicURL']
                    	else:
                        		nova_url = service['endpoints'][0]['publicURL']
    else:
    	nova_url = nova_url + "/" + tenant_id

    if nova_url is None:
        print ("Authentication succeeded but unable to find compute service")

    headers['X-Auth-Token'] = auth_token  

    #get flavors
    try:
        nova_flavor_list_response = requests.get(nova_url + '/flavors', headers=headers, verify=False).json()
        flavor_count = 0
        for flavor in nova_flavor_list_response['flavors']:
    	    print ("%s found") % (flavor['name'])
            flavor_count += 1
        if req_count and flavor_count < int(req_count):
            print "CRITICAL: %d flavors found less than required %d" % (flavor_count, int(req_count)) 
     
        if req_count: 
            print "OK: Retrieved %d flavors, required %d" % (flavor_count, int(req_count))
        else:
            print "OK: Retrieved %d flavors" % (flavor_count)
    except Exception as e:
        print 'CRITICAL: Failed to retrieve flavors for tenant %s and user %s' % (tenant_name, user_name) 

    nova_manage_check()
Exemplo n.º 4
0
def check_keystone():
	auth_url, tenant_name, user_name,password,region=get_auth()	
	auth_request = get_auth_response()
	headers = {'content-type': 'application/json'}
	#print auth_request
	#requst keystone to generate token for tenant_name
	auth_response = get_auth_response() ;
	"""if not auth_response['access']['token']['id']:
		raise Exception"""
	#get token id
	auth_token = auth_response['access']['token']['id']
	#print auth_token
	if auth_token is None:
		print 'CRITICAL: Failed to generate an auth token for tenant %s and user %s' % (tenant_name, username) 

	"""except Exception as e:
		print 'CRITICAL: Athentication failed for tenant admin and user keystone' 
		sys.exit()"""
	print 'OK: Successfully generated an auth token for tenant admin and user keystone'