Skip to content

Commit

Permalink
chore(api): support source in enrichments
Browse files Browse the repository at this point in the history
  • Loading branch information
talboren committed Apr 8, 2024
1 parent dc7ae9a commit b72f15a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 41 deletions.
81 changes: 41 additions & 40 deletions examples/workflows/new_github_stars.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
# Alert when there are new GitHub Stars utilizing keepstate
workflow:
id: new-github-stars
description: Notify Slack about new GitHub star for keephq/keep
triggers:
- type: interval
value: 300
steps:
- name: get-github-stars
provider:
type: github.stars
config: "{{ providers.github }}"
with:
repository: "keephq/keep"
previous_stars_count:
key: "{{ state.new-github-stars.-1.workflow_context.steps_context.get-github-stars.results.stars }}"
default: 0
actions:
- name: trigger-slack
condition:
- name: assert-condition
id: new-github-stars
description: Notify Slack about new GitHub star for keephq/keep
triggers:
- type: manual
- type: interval
value: 300
steps:
- name: get-github-stars
provider:
config: "{{ providers.github }}"
type: github.stars
with:
previous_stars_count:
default: 0
key: "{{ last_workflow_results.get-github-stars.0.stars }}"
repository: keephq/keep
actions:
- condition:
- assert: "{{ steps.get-github-stars.results.new_stargazers_count }} > 0"
name: assert-condition
type: assert
assert: "{{ steps.get-github-stars.results.new_stargazers_count }} > 0" # if there are more than 0 new stargazers, trigger the action
provider:
type: slack
config: " {{ providers.slack-demo }} "
with:
blocks:
- type: section
text:
type: plain_text
text: There are new keep.len({{ steps.get-github-stars.results.new_stargazers }}) stargazers for keephq/keep
emoji: true
- type: section
text:
type: plain_text
text: |-
{{#steps.get-github-stars.results.new_stargazers}}
- {{username}} at {{starred_at}}
{{/steps.get-github-stars.results.new_stargazers}}
emoji: true
name: trigger-slack
provider:
config: "{{ providers.slack-demo }}"
type: slack
with:
blocks:
- text:
emoji: true
text: There are new keep.len({{ steps.get-github-stars.results.new_stargazers}}) stargazers for keephq/keep
type: plain_text
type: section
- text:
emoji: true
text: "{{#steps.get-github-stars.results.new_stargazers}}
- {{username}} at {{starred_at}}
{{/steps.get-github-stars.results.new_stargazers}}"
type: plain_text
type: section
channel: "C06N0KXXXX"
5 changes: 4 additions & 1 deletion keep/api/bl/enrichments.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
from keep.api.models.db.mapping import MappingRule


def get_nested_attribute(obj, attr_path: str):
def get_nested_attribute(obj: AlertDto, attr_path: str):
"""
Recursively get a nested attribute
"""
# Special case for source, since it's a list
if attr_path == "source" and obj.source is not None and len(obj.source) > 0:
return obj.source[0]
attributes = attr_path.split(".")
for attr in attributes:
# @@ is used as a placeholder for . in cases where the attribute name has a .
Expand Down

0 comments on commit b72f15a

Please sign in to comment.