Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 99 additions & 1 deletion examples/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import random
import time
import os
import json

account = os.environ.get("JUPITERONE_ACCOUNT")
token = os.environ.get("JUPITERONE_TOKEN")
Expand Down Expand Up @@ -332,12 +333,61 @@
]
}

create_jira_ticket_action_config = {
"integrationInstanceId" : "<GUID>",
"type" : "CREATE_JIRA_TICKET",
"entityClass" : "Record",
"summary" : "Jira Task created via JupiterOne Alert Rule",
"issueType" : "Task",
"project" : "KEY",
"additionalFields" : {
"description" : {
"type" : "doc",
"version" : 1,
"content" : [
{
"type" : "paragraph",
"content" : [
{
"type" : "text",
"text" : "{{alertWebLink}}\n\n**Affected Items:**\n\n* {{queries.query0.data|mapProperty('displayName')|join('\n* ')}}"
}
]
}
]
},
"customfield_1234": "text-value",
"customfield_5678": {
"value": "select-value"
},
"labels" : [
"label1","label2"
],
}
}

alert_rule_labels = [
{
"labelName": "tagkey1",
"labelValue": "tagval"
},
{
"labelName": "tagkey2",
"labelValue": "tagval"
}
]

resource_group_id = "<GUID>"

create_alert_rule_r = j1.create_alert_rule(name="create_alert_rule-name",
description="create_alert_rule-description",
tags=['tag1', 'tag2'],
labels=alert_rule_labels,
polling_interval="DISABLED",
severity="INFO",
j1ql="find jupiterone_user")
j1ql="find jupiterone_user",
action_configs=create_jira_ticket_action_config,
resource_group_id=resource_group_id)
print("create_alert_rule()")
print(create_alert_rule_r)

Expand Down Expand Up @@ -380,6 +430,41 @@
}
]

alert_rule_config_jira = [
{
"integrationInstanceId" : "<GUID>",
"type" : "CREATE_JIRA_TICKET",
"entityClass" : "Record",
"summary" : "Jira Task created via JupiterOne Alert Rule",
"issueType" : "Task",
"project" : "KEY",
"additionalFields" : {
"description" : {
"type" : "doc",
"version" : 1,
"content" : [
{
"type" : "paragraph",
"content" : [
{
"type" : "text",
"text" : "{{alertWebLink}}\n\n**Affected Items:**\n\n* {{queries.query0.data|mapProperty('displayName')|join('\n* ')}}"
}
]
}
]
},
"customfield_1234": "text-value",
"customfield_5678": {
"value": "select-value"
},
"labels" : [
"label1","label2"
],
}
}
]

alert_rule_config_multiple = [
{
"type": "WEBHOOK",
Expand All @@ -404,6 +489,19 @@
}
]

alert_rule_labels = [
{
"labelName": "tagkey1",
"labelValue": "tagval"
},
{
"labelName": "tagkey2",
"labelValue": "tagval"
}
]

resource_group_id = "<GUID>"

# polling_interval can be DISABLED, THIRTY_MINUTES, ONE_HOUR, FOUR_HOURS, EIGHT_HOURS, TWELVE_HOURS, ONE_DAY, or ONE_WEEK
# tag_op can be OVERWRITE or APPEND
# severity can be INFO, LOW, MEDIUM, HIGH, or CRITICAL
Expand Down
14 changes: 12 additions & 2 deletions jupiterone/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,10 +887,12 @@ def create_alert_rule(
name: str = None,
description: str = None,
tags: List[str] = None,
labels: List[dict] = None,
polling_interval: str = None,
severity: str = None,
j1ql: str = None,
action_configs: Dict = None,
resource_group_id: str = None,
):
"""Create Alert Rule Configuration in J1 account"""

Expand Down Expand Up @@ -931,15 +933,15 @@ def create_alert_rule(
},
"specVersion": 1,
"tags": tags,
"labels": labels,
"templates": {},
"resourceGroupId": resource_group_id,
}
}

if action_configs:
variables["instance"]["operations"][0]["actions"].append(action_configs)

print(variables)

response = self._execute_query(CREATE_RULE_INSTANCE, variables=variables)

return response["data"]["createInlineQuestionRuleInstance"]
Expand All @@ -962,8 +964,10 @@ def update_alert_rule(
severity: str = None,
tags: List[str] = None,
tag_op: str = None,
labels: List[dict] = None,
action_configs: List[dict] = None,
action_configs_op: str = None,
resource_group_id: str = None,
):
"""Update Alert Rule Configuration in J1 account"""
# fetch existing alert rule
Expand Down Expand Up @@ -1020,6 +1024,10 @@ def update_alert_rule(
else:
tags_config = alert_rule_config["tags"]

# update labels list if provided
if labels is not None:
label_config = labels

# update action_configs list if provided
if action_configs is not None:

Expand Down Expand Up @@ -1054,6 +1062,8 @@ def update_alert_rule(
"operations": operations,
"pollingInterval": interval_config,
"tags": tags_config,
"labels": label_config,
"resourceGroupId": resource_group_id,
}
}

Expand Down
Loading