Skip to content

Commit

Permalink
add get_alert_rule_details
Browse files Browse the repository at this point in the history
  • Loading branch information
SeaBlooms committed Oct 23, 2024
1 parent b899c92 commit 2aedeca
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@
print(list_alert_rules_r)
print(len(list_alert_rules_r))

# get_alert_rule_details
get_alert_rule_details_r = j1.get_alert_rule_details(alert_rule_id="<GUID>")
print("get_alert_rule_details()")
print(get_alert_rule_details_r)

# create_alert_rule
webhook_token = "<SECRET>"

Expand Down
42 changes: 42 additions & 0 deletions jupiterone/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,48 @@ def list_alert_rules(self):

return results

def get_alert_rule_details(self, alert_rule_id: str = None):
"""Get details of a single defined Alert Rule configured in J1 account
"""
results = []

data = {
"query": LIST_RULE_INSTANCES,
"flags": {
"variableResultSize": True
}
}

r = requests.post(url=self.graphql_url, headers=self.headers, json=data, verify=True).json()
results.extend(r['data']['listRuleInstances']['questionInstances'])

while r['data']['listRuleInstances']['pageInfo']['hasNextPage'] == True:

cursor = r['data']['listRuleInstances']['pageInfo']['endCursor']

# cursor query until last page fetched
data = {
"query": LIST_RULE_INSTANCES,
"variables": {
"cursor": cursor
},
"flags":{
"variableResultSize": True
}
}

r = requests.post(url=self.graphql_url, headers=self.headers, json=data, verify=True).json()
results.extend(r['data']['listRuleInstances']['questionInstances'])

# pick result out of list of results by 'id' key
for item in results:
if item["id"] == alert_rule_id:
result = item
break

return result

Check failure

Code scanning / CodeQL

Potentially uninitialized local variable Error

Local variable 'result' may be used before it is initialized.

def create_alert_rule(self, name: str = None, description: str = None, tags: List[str] = None, polling_interval: str = None, severity: str = None, j1ql: str = None, action_configs: Dict = None):
"""Create Alert Rule Configuration in J1 account
Expand Down

0 comments on commit 2aedeca

Please sign in to comment.