The example below is suitable for Python 3 or higher. It is a script for simple monitoring, where you can press 1 or 2 to send "OK" or "Failure" via webhook.
The purpose of this example is to demonstrate how the calls should be made for monitoring using the webhook created by the platform.
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())
For questions, inquiries, or technical support, please contact us through the chat on the ElvenWorks platform or on our website.
Comments
0 comments
Please sign in to leave a comment.