示例#1
0
def delAlarm(data):

    alarm_id = data['alarm_id']
    del_url = 'http://icoset1cs1.ad2lab.com:8777/v2/alarms/' + alarm_id

    getToken.main()
    global token_value
    token_value = getToken.token_value

    headers = {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
        'X-Auth-Token': token_value
    }

    response = requests.delete(del_url, verify=False, headers=headers)
    print(response.status_code)

    status = ""
    if response.status_code == 204:
        status = "Alarm " + alarm_id + "  deleted"
    else:
        status = "Alarm " + alarm_id + " not deleted Code : "

    return status
示例#2
0
def delAlarm(data):

        alarm_id = data['alarm_id']
        del_url = 'http://icoset1cs1.ad2lab.com:8777/v2/alarms/' + alarm_id

        getToken.main()
        global token_value
        token_value = getToken.token_value


        headers = {
                        'Accept': 'application/json',
                        'Content-Type' : 'application/json',
                        'X-Auth-Token': token_value
                }


        response = requests.delete(del_url,verify=False,headers=headers)
        print(response.status_code)
		
        status = ""
        if response.status_code == 204 :
                status = "Alarm "+ alarm_id + "  deleted"
        else :
                status = "Alarm "+ alarm_id + " not deleted Code : "

        return status
示例#3
0
def MeterList():
    try:
        getToken.main()
        global token_value
        token_value = getToken.token_value
        headers = {'Accept': 'application/json', 'X-Auth-Token': token_value}

        response = requests.get(listOfMetersUrl, verify=False, headers=headers)

        print(response.status_code)
        alarm_list_response = response.content

        getMeter(alarm_list_response)


#               print(forward_token())
#       print(type(alarm_list_response))

    except requests.exceptions.SSLError as e:
        print("SSL Certificate error")

    global meterSet
    global resourceSet

    return meterSet, resourceSet
示例#4
0
def MeterList():
        try:
                getToken.main()
                global token_value
                token_value = getToken.token_value
                headers = {
                        'Accept': 'application/json',
                        'X-Auth-Token': token_value
                }

                response = requests.get(listOfMetersUrl,verify=False,headers=headers)

                print(response.status_code)
                alarm_list_response = response.content

                getMeter(alarm_list_response)
		
#               print(forward_token())
        #       print(type(alarm_list_response))

        except requests.exceptions.SSLError as e:
                print("SSL Certificate error")

        global meterSet
	global resourceSet
	
        return meterSet, resourceSet
示例#5
0
def createAlarm(data):

    try:
        getToken.main()
        head = {
            'Content-Type': 'application/json',
            'Accept': 'application/json',
            'X-Auth-Token': getToken.token_value
        }

        old_data = {
            "threshold_rule": {
                "meter_name":
                "cpu_usage_high",
                "evaluation_periods":
                3,
                "period":
                600,
                "statistic":
                "avg",
                "threshold":
                40.0,
                "query": [{
                    "field": "resource_id",
                    "type": "",
                    "value": "500a1594-4972-7968-2914-c333201585bd",
                    "op": "eq"
                }],
                "comparison_operator":
                "gt"
            },
            "repeat_actions": False,
            "type": "threshold",
            "description": " Test of CPU usage high",
            "name": "cpu_high_alarm_ada_007"
        }

        print(getToken.token_value)
        #		print(type(payLoad))
        #		print(type(json.dumps(payLoad))

        #                response = requests.post(Url,auth=HTTPBasicAuth('admin','passw0rd'),verify=False,headers=head,data=json.dumps(payLoad))
        response = requests.post(Url,
                                 verify=False,
                                 headers=head,
                                 data=json.dumps(data))

        print(response.status_code)

    except requests.exceptions.SSLError as e:
        print("SSL Certificate error")
    print(response.status_code)
    return response.status_code
示例#6
0
def putAlarm(data):
#	getAlarmList.AlarmList()

	alarm_id = data['alarm_id']
	update_url = 'http://icoset1cs1.ad2lab.com:8777/v2/alarms/' + alarm_id 

	getToken.main()
	global token_value
        token_value = getToken.token_value
#	data = json.loads(data)

	headers = {
                        'Accept': 'application/json',
			'Content-Type' : 'application/json',
                        'X-Auth-Token': token_value
                }

	
	old_body = requests.get(update_url,verify=False,headers=headers)

#	print(type(old_body.content))
	json_body = json.loads(old_body.content)
#	print(type(json_body))
		
	json_body['threshold_rule']['threshold'] = data['threshold']
	json_body['threshold_rule']['comparison_operator'] = data['comparison_operator']
#	print(data['comparison_operator'])
#	print("***********")
	json_body['threshold_rule']['statistic'] = data['statistics']
	
	
	
	response = requests.put(update_url,verify=False,headers=headers,data = json.dumps(json_body))
	print(response.status_code)	
	status = ""
	if response.status_code == 200 :
		status = "Alarm "+ alarm_id + "  updated"
	else :
		status = "Alarm "+ alarm_id + " not updated. Code : " + response.status_code 
	
	return status
示例#7
0
def createAlarm(data):

        try:
		getToken.main()
		head= {'Content-Type': 'application/json',
		        'Accept': 'application/json',
			'X-Auth-Token': getToken.token_value 
		        }


		old_data = 	{"threshold_rule": {

			"meter_name": "cpu_usage_high", "evaluation_periods": 3, "period": 600, "statistic": "avg", "threshold": 40.0,
			 "query": [{"field": "resource_id", "type": "", "value": "500a1594-4972-7968-2914-c333201585bd", "op": "eq"}], 
			 "comparison_operator": "gt" }, 
		"repeat_actions": False, 
		"type": "threshold", 
		"description": " Test of CPU usage high", 
		"name": "cpu_high_alarm_ada_007"}




		print(getToken.token_value)
#		print(type(payLoad))
#		print(type(json.dumps(payLoad))
		
#                response = requests.post(Url,auth=HTTPBasicAuth('admin','passw0rd'),verify=False,headers=head,data=json.dumps(payLoad))
                response = requests.post(Url,verify=False,headers=head,data=json.dumps(data))

		
		print(response.status_code)

        except requests.exceptions.SSLError as e:
                print("SSL Certificate error")
	print (response.status_code)
	return response.status_code