From b72f15a0839b72dc9d7c029526fada57dbe3fab1 Mon Sep 17 00:00:00 2001 From: Tal Borenstein Date: Mon, 8 Apr 2024 14:54:44 +0300 Subject: [PATCH] chore(api): support source in enrichments --- examples/workflows/new_github_stars.yml | 81 +++++++++++++------------ keep/api/bl/enrichments.py | 5 +- 2 files changed, 45 insertions(+), 41 deletions(-) diff --git a/examples/workflows/new_github_stars.yml b/examples/workflows/new_github_stars.yml index 4e9484ec63..41f91e3d5b 100644 --- a/examples/workflows/new_github_stars.yml +++ b/examples/workflows/new_github_stars.yml @@ -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" diff --git a/keep/api/bl/enrichments.py b/keep/api/bl/enrichments.py index e805ba5bce..43c98c205f 100644 --- a/keep/api/bl/enrichments.py +++ b/keep/api/bl/enrichments.py @@ -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 .