Skip to content

Commit 8e33075

Browse files
committed
Included additional API wrappers
1 parent a7b015d commit 8e33075

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

uptimerobot/uptimerobot.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,47 @@ def requestApi(self, url):
174174
return True, jContent
175175
return False, jContent
176176

177+
def getAlertContacts(self, alertContacts=None, offset=None, limit=None):
178+
"""
179+
Get Alert Contacts
180+
"""
181+
url = self.baseUrl
182+
url += "getAlertContacts?apiKey=%s" % self.apiKey
183+
if alertContacts:
184+
url += "&alertContacts=%s" % alertContacts
185+
if offset:
186+
url += "&offset=%s" % offset
187+
if limit:
188+
url += "&limit=%s" % limit
189+
url += "&format=json"
190+
return self.requestApi(url)
191+
192+
def getAlertContactIds(self, urlFormat=False):
193+
ids = []
194+
success, response = self.getAlertContacts()
195+
if success:
196+
alertContacts = response.get('alertcontacts').get('alertcontact')
197+
for alertContact in alertContacts:
198+
ids.append(alertContact.get('id'))
199+
if urlFormat:
200+
formatted = ""
201+
for id in ids:
202+
formatted += id + "-"
203+
return formatted[:-1]
204+
else:
205+
return ids
177206

207+
def getMonitorId(self, name):
208+
success, response = self.getMonitors()
209+
if success:
210+
monitors = response.get('monitors').get('monitor')
211+
for monitor in monitors:
212+
if monitor['friendlyname'] == name:
213+
return monitor['id']
214+
return None
178215

216+
def deleteMonitorByName(self, name):
217+
return self.deleteMonitorById(self.getMonitorId(name))
179218

180219
if __name__ == "__main__":
181220
for arg in sys.argv:

0 commit comments

Comments
 (0)