Skip to content

Commit

Permalink
[resotocore][chore] Improve Pagerduty details (#1461)
Browse files Browse the repository at this point in the history
  • Loading branch information
aquamatthias committed Feb 22, 2023
1 parent 63407e8 commit 5866ca9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
16 changes: 9 additions & 7 deletions resotocore/resotocore/core_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,15 @@ def alias_templates() -> List[AliasTemplateConfig]:
"This way you do not need to provide it every time you execute the command."
),
template=(
# aggregate the result by account and region - flat the results, since pagerduty only allows flat data
"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 "
# aggregate the result by cloud -> account -> region -> resource
# resulting structure looks like this:
# {"aws": {"account1": {"region1": {"id1": {"id": "xxx", "name": "yyy", "kind": "zzz" }}}}}
# note: Pagerduty is able to render JSON objects in their webUI, but not arrays.
"head 100 | chunk 100 | jq --no-rewrite '"
'[group_by(.ancestors.cloud.reported.name) | .[] | {(.[0].ancestors.cloud.reported.name // "no-cloud"): ' # noqa: E501
'[group_by(.ancestors.account.reported.name) | .[] | {(.[0].ancestors.account.reported.name // "no-account"): ' # noqa: E501
'[group_by(.ancestors.region.reported.name) | .[] | {(.[0].ancestors.region.reported.name // "no-region"): ' # noqa: E501
"[.[] | {(.id): {id: .reported.id, name: .reported.name, kind: .reported.kind}}] | add }] | add }] | add }] | add'" # noqa: E501
"| jq --no-rewrite '{payload: "
'{summary: "{{summary}}", '
'timestamp: "@utc@", '
Expand Down
8 changes: 4 additions & 4 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) | head 1 | pagerduty --webhook-url "http://localhost:{port}/success" --summary test --routing-key 123 --dedup-key 234',
f'search id(0_0) | 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,9 +899,9 @@ async def test_pagerduty_alias(cli: CLI, echo_http_server: Tuple[int, List[Tuple
"source": "Resoto",
"severity": "warning",
"component": "Resoto",
"custom_details": [
{"cloud": None, "account": None, "region": None, "name": "yes or no", "kind": "bla"},
],
"custom_details": {
"no-cloud": {"no-account": {"no-region": {"0_0": {"id": None, "name": "yes or no", "kind": "bla"}}}}
},
},
"routing_key": "123",
"dedup_key": "234",
Expand Down

0 comments on commit 5866ca9

Please sign in to comment.