forked from kenazk/relay-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkHealth.py
31 lines (25 loc) · 837 Bytes
/
checkHealth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python
# File: get-http-status.py
# Description: This example script makes a request to a URL and sets its status
# a the output. The status can be used in subsequent steps to
# perform different bits of logic in a workflow.
from urllib.request import urlopen
from relay_sdk import Interface, Dynamic as D
relay = Interface()
def get_http_status(url):
try:
with urlopen(url) as response:
return str(response.status)
except:
# empty string indicates something bad happened.
return ""
if __name__ == '__main__':
url = None
try:
url = relay.get(D.url)
except:
print('No URL was configured. Exiting.')
exit(1)
status = get_http_status(url)
print("Status for service {0} is {1}".format(url, status))
relay.outputs.set('status', status)