Skip to content

add mention for slack bot workflow trigger #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions connection.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ notify:
suppress_duplicates: True
slack:
webhook_url: https://hooks.slack.com/services/T0XXXXXXXXXXX/BXXXXXXXX/1CIyXXXXXXXXXXXXXXX
mention: "<@U013BDEFABC>"
jira:
username: "amce@org.com"
server_url: "https://amce.atlassian.net"
Expand Down
8 changes: 5 additions & 3 deletions hawk_scanner/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def group_results(args, results):
return grouped_results


def format_slack_message(group, result, records_mini):
def format_slack_message(group, result, records_mini, mention):
template_map = {
's3': """
*** PII Or Secret Found ***
Expand Down Expand Up @@ -171,7 +171,7 @@ def format_slack_message(group, result, records_mini):
Exposed Values: {exposed_values}
"""
}
return template_map.get(group, "").format(
return f"{mention} " + template_map.get(group, "").format(
vulnerable_profile=result['profile'],
bucket=result.get('bucket', ''),
file_path=result.get('file_path', ''),
Expand Down Expand Up @@ -258,7 +258,9 @@ def main():
add_columns_to_table(group, table)
for i, result in enumerate(group_data, 1):
records_mini = ', '.join(result['matches']) if len(result['matches']) < 25 else ', '.join(result['matches'][:25]) + f" + {len(result['matches']) - 25} more"
slack_message = format_slack_message(group, result, records_mini)
connection = system.get_connection(args)
mention = connection.get('notify', {}).get('slack', {}).get('mention', '')
slack_message = format_slack_message(group, result, records_mini, mention)
if slack_message:
system.create_jira_ticket(args, result, slack_message)
system.SlackNotify(slack_message, args)
Expand Down
23 changes: 23 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,29 @@ sources:
```

You can add or remove profiles from the connection.yml file as needed. You can also configure only one or two data sources if you don't need to scan all of them.

## Slack Bot Mentions and Workflow Integration

Hawk-eye now supports customizable Slack mentions in alert messages, allowing you to trigger internal Slack bot workflows (such as archiving the channel, etc) automatically.

### How to Configure Slack Mentions

In your `connection.yml`, under the `notify.slack` section, add a `mention` key. This value should be the Slack user ID of your bot in the format `<@USERID>`. Using the display name (e.g., `@DataScanBot`) will not trigger a real mention—Slack requires the user ID format.

**Example:**
```yaml
notify:
slack:
webhook_url: https://hooks.slack.com/services/...
mention: "<@U12345678>" # Replace with your bot's actual user ID
```

When Hawk-eye sends a Slack alert, the message will begin with this mention, ensuring your bot is properly notified and any associated workflows are triggered.

**Tip:** To find your bot's user ID, click on the bot's profile in Slack and look for the ID in the URL (e.g., `/team/U12345678`).

```

</div>

## Adding New Commands
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = "0.3.38"
VERSION = "0.3.39"

from setuptools import setup, find_packages

Expand Down