Adequado para Python 3 ou superior, o exemplo abaixo é de script para
monitoramento simples, pressionando 1 ou 2 para enviar OK ou Failure.

 

O objetivo deste exemplo é apenas demonstrar como as chamadas devem
ser feitas para o monitoramento, via webhook, criado pela plataforma.

 

Exemplo:

				
					import requests

print('FAILURE OR OK?')


print('TYPE 1 FOR FAILURE')


print('TYPE 2 FOR OK')


status = int(input('SELECT 1 OR 2:'))


choice = status


print('---', 'the option to be performed is: ', choice, '---')


token_headers = {'Content-Type': 'application/json'}


token_url = 'https://apis.elven.works/external/auth/v1/client/<Your Company ID>'


token_payload = {


'client_id': '<YOUR INFORMATION HERE>',


'client_secret': '<YOUR INFORMATION HERE>'


}


req_token = requests.post(


url=token_url,


json=token_payload,


headers=token_headers


)


token = req_token.json()['access_token']


req_headers = {'Content-Type': 'application/json',


'Authorization': 'Bearer ' + token}


req_url = 'https://apis.elven.works/external/auth/v1/client/<Your Company ID>'


req_payload = {'service': <YOUR SERVICE ID HERE> ,


'organization': '<YOUR ORGANIZATION ID HERE>'}


if (status == 2):


print("HITS")


hits_latency = {'latency': 100000}


req_payload.update(hits_latency)


hits = requests.post(


url=req_url + 'hits',


json=req_payload,


headers=req_headers


)


print(req_payload)


print(hits.json())


if (status == 1):


print("failures")


failures_issue = {'issue': 'Error message'}


req_payload.update(failures_issue)


hits = requests.post(


url=req_url + 'failures',


json=req_payload,


headers=req_headers


)


print(req_payload)


print(hits.json())
				
			
Rolar para cima