2121class 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