File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff 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
180219if __name__ == "__main__" :
181220 for arg in sys .argv :
You can’t perform that action at this time.
0 commit comments