mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-24 21:11:53 +00:00
chore(slack): fix integration with provider (#3565)
Co-authored-by: Sergio Garcia <38561120+sergargar@users.noreply.github.com>
This commit is contained in:
+15
-15
@@ -2,6 +2,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
from os import environ
|
||||
|
||||
from colorama import Fore, Style
|
||||
|
||||
@@ -35,6 +36,7 @@ from prowler.lib.logger import logger, set_logging_config
|
||||
from prowler.lib.outputs.compliance.compliance import display_compliance_table
|
||||
from prowler.lib.outputs.json.json import close_json
|
||||
from prowler.lib.outputs.outputs import extract_findings_statistics
|
||||
from prowler.lib.outputs.slack import send_slack_message
|
||||
from prowler.lib.outputs.summary_table import display_summary_table
|
||||
from prowler.providers.aws.lib.s3.s3 import send_to_s3_bucket
|
||||
from prowler.providers.aws.lib.security_hub.security_hub import (
|
||||
@@ -200,21 +202,19 @@ def prowler():
|
||||
# Extract findings stats
|
||||
stats = extract_findings_statistics(findings)
|
||||
|
||||
# TODO: adapt the slack integration for the new AWS provider
|
||||
# if args.slack:
|
||||
# if "SLACK_API_TOKEN" in os.environ and "SLACK_CHANNEL_ID" in os.environ:
|
||||
# _ = send_slack_message(
|
||||
# os.environ["SLACK_API_TOKEN"],
|
||||
# os.environ["SLACK_CHANNEL_ID"],
|
||||
# stats,
|
||||
# provider,
|
||||
# provider,
|
||||
# )
|
||||
# else:
|
||||
# logger.critical(
|
||||
# "Slack integration needs SLACK_API_TOKEN and SLACK_CHANNEL_ID environment variables (see more in https://docs.prowler.cloud/en/latest/tutorials/integrations/#slack)."
|
||||
# )
|
||||
# sys.exit(1)
|
||||
if args.slack:
|
||||
if "SLACK_API_TOKEN" in environ and "SLACK_CHANNEL_ID" in environ:
|
||||
_ = send_slack_message(
|
||||
environ["SLACK_API_TOKEN"],
|
||||
environ["SLACK_CHANNEL_ID"],
|
||||
stats,
|
||||
provider,
|
||||
)
|
||||
else:
|
||||
logger.critical(
|
||||
"Slack integration needs SLACK_API_TOKEN and SLACK_CHANNEL_ID environment variables (see more in https://docs.prowler.cloud/en/latest/tutorials/integrations/#slack)."
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
if args.output_modes:
|
||||
for mode in args.output_modes:
|
||||
|
||||
@@ -6,10 +6,10 @@ from prowler.config.config import aws_logo, azure_logo, gcp_logo, square_logo_im
|
||||
from prowler.lib.logger import logger
|
||||
|
||||
|
||||
def send_slack_message(token, channel, stats, provider, audit_info):
|
||||
def send_slack_message(token, channel, stats, provider):
|
||||
try:
|
||||
client = WebClient(token=token)
|
||||
identity, logo = create_message_identity(provider, audit_info)
|
||||
identity, logo = create_message_identity(provider)
|
||||
response = client.chat_postMessage(
|
||||
username="Prowler",
|
||||
icon_url=square_logo_img,
|
||||
|
||||
@@ -333,7 +333,5 @@ class TestSlackIntegration:
|
||||
), mock.patch(
|
||||
"prowler.lib.outputs.slack.WebClient", new=mocked_web_client
|
||||
):
|
||||
response = send_slack_message(
|
||||
"test-token", "test-channel", {}, "provider", {}
|
||||
)
|
||||
response = send_slack_message("test-token", "test-channel", {}, "provider")
|
||||
assert response == mocked_slack_response
|
||||
|
||||
Reference in New Issue
Block a user