Suitable for Python 3 or above.

Below is an example of a script for simple monitoring, pressing 1 or 2 to send OK or Failure.

The purpose of this example is only to demonstrate how calls should be made to the webhook monitoring created by 1P.

Example:

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())

Elvenworks Soluções em tecnologia LTDA

Smart Platforms

 

Follow Us

Email: contact@elven.works