-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmuting_rules.py
49 lines (44 loc) · 1.42 KB
/
muting_rules.py
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
import json
import requests
import logging
class GetMutingRules():
def __init__(self, key, accountId):
self.url = 'https://api.newrelic.com/graphql'
self.headers = {
'Content-Type': 'application/json',
'API-Key': key
}
self.query = f'''
{{
actor {{
account(id: {accountId}) {{
alerts {{
mutingRules {{
name
id
enabled
status
}}
}}
}}
}}
}}
'''
self.vars = {}
def sendRequest(self):
res = requests.request("POST", self.url, headers=self.headers, json={'query': self.query, 'variables': self.vars})
return res
def getMutingRules(self):
try:
resp = self.sendRequest()
logging.debug('GetMutingRules')
logging.debug(resp.json())
if (resp.status_code == 200):
parsed = resp.json()
rules = parsed['data']['actor']['account']['alerts']['mutingRules']
else:
logging.error('Failed to get muting rules. Response: ' + str(resp.status_code))
except Exception as e:
logging.exception('Exception occurred - Failed to get muting rules')
raise
return(rules)