Skip to content

Commit a485a77

Browse files
Merge pull request #8 from ticoombs/master
Feature: editMonitors
2 parents 31df40c + 16a754a commit a485a77

File tree

3 files changed

+65
-10
lines changed

3 files changed

+65
-10
lines changed

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ History
5050

5151
latest
5252

53+
0.1.4
54+
55+
- Extended API with `.editMonitor()`.
56+
- Updated to use HTTPs by default.
57+
5358
0.1.3
5459

5560
- Extended API with `.deleteMonitorById()`.

uptimerobot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# -*- coding: utf-8 -*-
2-
__version__ = '0.1.3'
2+
__version__ = '0.1.4'

uptimerobot/uptimerobot.py

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
class UptimeRobot(object):
2222
def __init__(self, apiKey):
2323
self.apiKey = apiKey
24-
self.baseUrl = "http://api.uptimerobot.com/"
24+
self.baseUrl = "https://api.uptimerobot.com/"
2525

2626

2727
def addMonitor(self, monitorFriendlyName, monitorURL):
@@ -34,8 +34,8 @@ def addMonitor(self, monitorFriendlyName, monitorURL):
3434
url += "&monitorURL=%s&monitorType=1" % monitorURL
3535
url += "&monitorAlertContacts=%s" % monitorAlertContacts
3636
url += "&noJsonCallback=1&format=json"
37-
sucess, response = self.requestApi(url)
38-
if sucess:
37+
success, response = self.requestApi(url)
38+
if success:
3939
return True
4040
else:
4141
return False
@@ -73,8 +73,8 @@ def getMonitorById(self, monitorId):
7373
url = self.baseUrl
7474
url += "getMonitors?apiKey=%s&monitors=%s" % (self.apiKey, monitorId)
7575
url += "&noJsonCallback=1&format=json"
76-
sucess, response = self.requestApi(url)
77-
if sucess:
76+
success, response = self.requestApi(url)
77+
if success:
7878
status = response.get('monitors').get('monitor')[0].get('status')
7979
alltimeuptimeratio = response.get('monitors').get('monitor')[0].get('alltimeuptimeratio')
8080
return status, alltimeuptimeratio
@@ -88,8 +88,8 @@ def getMonitorByName(self, monitorFriendlyName):
8888
url = self.baseUrl
8989
url += "getMonitors?apiKey=%s" % self.apiKey
9090
url += "&noJsonCallback=1&format=json"
91-
sucess, response = self.requestApi(url)
92-
if sucess:
91+
success, response = self.requestApi(url)
92+
if success:
9393
monitors = response.get('monitors').get('monitor')
9494
for i in range(len(monitors)):
9595
monitor = monitors[i]
@@ -100,6 +100,55 @@ def getMonitorByName(self, monitorFriendlyName):
100100
return None, None
101101

102102

103+
def editMonitor(self, monitorID, monitorStatus=None, monitorFriendlyName=None, monitorURL=None, monitorType=None,
104+
monitorSubType=None, monitorPort=None, monitorKeywordType=None, monitorKeywordValue=None,
105+
monitorHTTPUsername=None, monitorHTTPPassword=None, monitorAlertContacts=None):
106+
"""
107+
monitorID is the only required object. All others are optional and must be quoted.
108+
Returns Response object from api.
109+
"""
110+
111+
url = self.baseUrl
112+
url += "editMonitor?apiKey=%s" % self.apiKey
113+
url += "&monitorID=%s" % monitorID
114+
if monitorStatus:
115+
# Pause, Start Montir
116+
url += "&monitorStatus=%s" % monitorStatus
117+
if monitorFriendlyName:
118+
# Update their FriendlyName
119+
url += "&monitorFriendlyName=%s" % monitorFriendlyName
120+
if monitorURL:
121+
# Edit the MontiorUrl
122+
url += "&monitorURL=%s" % monitorURL
123+
if monitorType:
124+
# Edit the type of montior
125+
url += "&monitorType=%s" % monitorType
126+
if monitorSubType:
127+
# Edit the SubType
128+
url += "&monitorSubType=%s" % monitorSubType
129+
if monitorPort:
130+
# Edit the Port
131+
url += "&monitorPort=%s" % monitorPort
132+
if monitorKeywordType:
133+
# Edit the Keyword Type
134+
url += "&monitorKeywordType=%s" % monitorKeywordType
135+
if monitorKeywordValue:
136+
# Edit the Keyword Match
137+
url += "&monitorKeywordValue=%s" % monitorKeywordValue
138+
if monitorHTTPUsername:
139+
# Edit the HTTP Username
140+
url += "&monitorHTTPUsername=%s" % monitorHTTPUsername
141+
if monitorHTTPPassword:
142+
# Edit the HTTP Password
143+
url += "&monitorHTTPPassword=%s" % monitorHTTPPassword
144+
if monitorAlertContacts:
145+
# Edit the contacts
146+
url += "&monitorAlertContacts=%s" % monitorAlertContacts
147+
url += "&noJsonCallback=1&format=json"
148+
success = self.requestApi(url)
149+
return success
150+
151+
103152
def deleteMonitorById(self, monitorID):
104153
"""
105154
Returns True or False if monitor is deleted
@@ -108,8 +157,8 @@ def deleteMonitorById(self, monitorID):
108157
url += "deleteMonitor?apiKey=%s" % self.apiKey
109158
url += "&monitorID=%s" % monitorID
110159
url += "&noJsonCallback=1&format=json"
111-
sucess, response = self.requestApi(url)
112-
if sucess:
160+
success, response = self.requestApi(url)
161+
if success:
113162
return True
114163
else:
115164
return False
@@ -138,6 +187,7 @@ def requestApi(self, url):
138187
elif arg.startswith("apiKey="):
139188
apiKey = arg.split("=")[1]
140189
if not monitorFriendlyName or not monitorURL:
190+
print "Usage: uptimerobot.py monitorFriendlyName=\"name\" monitorURL=\"www.url.com\""
141191
sys.exit(1)
142192

143193
if not apiKey:

0 commit comments

Comments
 (0)