Skip to content

Commit

Permalink
[resotocore][fix] Fix pagerduty alert. (#1453)
Browse files Browse the repository at this point in the history
* [resotocore][fix] Fix pagerduty alert.

* fix test
  • Loading branch information
aquamatthias authored Feb 17, 2023
1 parent 7d0c15d commit 41826ed
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
20 changes: 11 additions & 9 deletions resotocore/resotocore/core_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,7 @@ def alias_templates() -> List[AliasTemplateConfig]:
info="Create an alert in pagerduty from a search.",
description=(
"Perform a search and send the result to pagerduty.\n\n"
"No resource specific data will be sent to pagerduty. "
"The resources are aggregated by account and region with the count of matching resources.\n"
"A call to this command will only send the first 100 occurrences to the incident, the rest is dropped. "
"The `summary` should explain why this alert is triggered, so that the user can take action.\n"
"The `dedup_key` is used to identify an alert uniquely. "
"You can fire the same alert multiple times by using the same dedup_key.\n\n"
Expand All @@ -361,24 +360,27 @@ def alias_templates() -> List[AliasTemplateConfig]:
),
template=(
# aggregate the result by account and region - flat the results, since pagerduty only allows flat data
'aggregate "account_{/ancestors.account.reported.id}__region_{/ancestors.region.reported.id}" as name :'
"sum(1) as count | chunk 100 | head 1 | "
"jq --no-rewrite 'map({(.group.name // \"none\"): .count}) | add | {details: .}'"
"head 100 | jq --no-rewrite {"
"cloud: .ancestors.cloud.reported.name, "
"account: .ancestors.account.reported.name, "
"region: .ancestors.region.reported.name, "
"name: .reported.name, "
"kind: .reported.kind} | chunk 100 "
"| jq --no-rewrite '{payload: "
'{summary: "{{summary}}", '
'timestamp: "@utc@", '
'source:"{{source}}", '
'severity: "{{severity}}", '
'component: "{{component}}", '
"custom_details: .details, "
"custom_details: .}, "
'routing_key: "{{routing_key}}", '
'dedup_key: "{{dedup_key}}", '
'images:[{src: "https://cdn.some.engineering/assets/resoto-logos/resoto-logo.svg", href: '
'"https://resoto.com/", alt: "Resoto Home Page"}], '
'images:[{src: "https://cdn.some.engineering/assets/resoto-illustrations/small/resoto-alert.png", href:'
' "https://resoto.com/", alt: "Resoto Home Page"}], '
"links:[], "
'event_action: "{{event_action}}", '
'client: "Resoto Service", '
'client_url: "https://resoto.com"}}\''
'client_url: "https://resoto.com"}\''
# send the event to pagerduty
' | http {{webhook_url}} "Content-Type:application/json"'
),
Expand Down
32 changes: 17 additions & 15 deletions resotocore/tests/resotocore/cli/command_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ async def test_jira_alias(cli: CLI, echo_http_server: Tuple[int, List[Tuple[Requ
async def test_pagerduty_alias(cli: CLI, echo_http_server: Tuple[int, List[Tuple[Request, Json]]]) -> None:
port, requests = echo_http_server
result = await cli.execute_cli_command(
f'search is(bla) | pagerduty --webhook-url "http://localhost:{port}/success" --summary test --routing-key 123 --dedup-key 234',
f'search is(bla) | head 1 | pagerduty --webhook-url "http://localhost:{port}/success" --summary test --routing-key 123 --dedup-key 234',
stream.list,
)
assert result == [["1 requests with status 200 sent."]]
Expand All @@ -899,21 +899,23 @@ async def test_pagerduty_alias(cli: CLI, echo_http_server: Tuple[int, List[Tuple
"source": "Resoto",
"severity": "warning",
"component": "Resoto",
"custom_details": {"account___region_": 100},
"routing_key": "123",
"dedup_key": "234",
"images": [
{
"src": "https://cdn.some.engineering/assets/resoto-logos/resoto-logo.svg",
"href": "https://resoto.com/",
"alt": "Resoto Home Page",
}
"custom_details": [
{"cloud": None, "account": None, "region": None, "name": "yes or no", "kind": "bla"},
],
"links": [],
"event_action": "trigger",
"client": "Resoto Service",
"client_url": "https://resoto.com",
}
},
"routing_key": "123",
"dedup_key": "234",
"images": [
{
"src": "https://cdn.some.engineering/assets/resoto-illustrations/small/resoto-alert.png",
"href": "https://resoto.com/",
"alt": "Resoto Home Page",
}
],
"links": [],
"event_action": "trigger",
"client": "Resoto Service",
"client_url": "https://resoto.com",
}


Expand Down

0 comments on commit 41826ed

Please sign in to comment.