-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewMonitor.py
More file actions
60 lines (54 loc) · 2.28 KB
/
newMonitor.py
File metadata and controls
60 lines (54 loc) · 2.28 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import sys
import http.client
APIKEY = "uptimeRobotAPIKey"
alertContact = "contactIDNumber"
myURL = sys.argv[2]
conn = http.client.HTTPSConnection("api.uptimerobot.com")
headers = {
'cache-control': "no-cache",
'content-type': "application/x-www-form-urlencoded"
}
def serverchecks():
'''
:param server:
:param FQDN:
:return: Function to create 6 different health checks (WHM, ICMP, FTP, SMTP, POP3, IMAP) based on the FQDN. Returns the status of the request.
'''
monitors = {'WHM': 'type=4&sub_type=99&port=2087',
'ICMP': 'type=3',
'FTP': 'type=4&sub_type=3',
'SMTP': 'type=4&sub_type=4',
'POP3': 'type=4&sub_type=5',
'IMAP': 'type=4&sub_type=6',
}
for X in monitors:
#print("api_key=" + APIKEY + "&format=json&" + monitors[X] + "&url=" + myURL + "&friendly_name=" + myURL + "-" + X + "&alert_contacts=" + alertContact + "")
payload = "api_key=" + APIKEY + "&format=json&" + monitors[X] + "&url=" + myURL + "&friendly_name=" + myURL + "-" + X + "&alert_contacts=" + alertContact + ""
conn.request("POST", "/v2/newMonitor", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
def hostcheck():
'''
:param server:
:param FQDN:
:return: Function to create 1 health checks based on the FQDN. Returns the status of the request.
'''
monitors = {'HTTP': 'type=1'
}
for X in monitors:
#print("api_key=" + APIKEY + "&format=json&" + monitors[X] + "&url=http://" + myURL + "&friendly_name=" + myURL + "-" + X + "&alert_contacts=" + alertContact + "")
payload = "api_key=" + APIKEY + "&format=json&" + monitors[X] + "&url=http://" + myURL + "&friendly_name=" + myURL + "-" + X + "&alert_contacts=" + alertContact + ""
conn.request("POST", "/v2/newMonitor", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
if len(sys.argv) != 3:
print("This script will create health monitors on uptimerobot.")
print("")
print("usage", sys.argv[0], "<HOST or SERVER> <URL>")
sys.exit(3)
if sys.argv[1].lower() == "host":
hostcheck()
if sys.argv[1].lower() == "server":
serverchecks()