Skip to content

Commit 46c1e59

Browse files
committed
chore: add slack webhook debugging
1 parent 7af45bc commit 46c1e59

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
66

77
[project]
88
name = "socketsecurity"
9-
version = "2.2.5"
9+
version = "2.2.6"
1010
requires-python = ">= 3.10"
1111
license = {"file" = "LICENSE"}
1212
dependencies = [
@@ -52,6 +52,7 @@ dev = [
5252

5353
[project.scripts]
5454
socketcli = "socketsecurity.socketcli:cli"
55+
socketclidev = "socketsecurity.socketcli:cli"
5556

5657
[project.urls]
5758
Homepage = "https://socket.dev"

socketsecurity/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
__author__ = 'socket.dev'
2-
__version__ = '2.2.5'
2+
__version__ = '2.2.6'

socketsecurity/output.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ def handle_output(self, diff_report: Diff) -> None:
3434
plugin_mgr = PluginManager({"jira": jira_config})
3535
plugin_mgr.send(diff_report, config=self.config)
3636

37+
# Debug Slack webhook configuration when debug is enabled (always show when debug is on)
38+
if self.config.enable_debug:
39+
import os
40+
slack_enabled_env = os.getenv("SOCKET_SLACK_ENABLED", "Not set")
41+
slack_config_env = os.getenv("SOCKET_SLACK_CONFIG_JSON", "Not set")
42+
slack_url = "Not configured"
43+
if self.config.slack_plugin.config and self.config.slack_plugin.config.get("url"):
44+
slack_url = self.config.slack_plugin.config.get("url")
45+
self.logger.debug("=== Slack Webhook Debug Information ===")
46+
self.logger.debug(f"Slack Plugin Enabled: {self.config.slack_plugin.enabled}")
47+
self.logger.debug(f"SOCKET_SLACK_ENABLED environment variable: {slack_enabled_env}")
48+
self.logger.debug(f"SOCKET_SLACK_CONFIG_JSON environment variable: {slack_config_env}")
49+
self.logger.debug(f"Slack Webhook URL: {slack_url}")
50+
self.logger.debug(f"Slack Alert Levels: {self.config.slack_plugin.levels}")
51+
self.logger.debug("=====================================")
52+
3753
if self.config.slack_plugin.enabled:
3854
slack_config = {
3955
"enabled": self.config.slack_plugin.enabled,

socketsecurity/plugins/slack.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ def get_name():
1515

1616
def send(self, diff, config: CliConfig):
1717
if not self.config.get("enabled", False):
18+
if config.enable_debug:
19+
logger.debug("Slack plugin is disabled - skipping webhook notification")
1820
return
1921
if not self.config.get("url"):
2022
logger.warning("Slack webhook URL not configured.")
23+
if config.enable_debug:
24+
logger.debug("Slack webhook URL is missing from configuration")
2125
return
2226
else:
2327
url = self.config.get("url")
@@ -31,13 +35,21 @@ def send(self, diff, config: CliConfig):
3135

3236
message = self.create_slack_blocks_from_diff(diff, config)
3337
logger.debug(f"Sending message to {url}")
38+
39+
if config.enable_debug:
40+
logger.debug(f"Slack webhook URL: {url}")
41+
logger.debug(f"Number of alerts to send: {len(diff.new_alerts)}")
42+
logger.debug(f"Message blocks count: {len(message)}")
43+
3444
response = requests.post(
3545
url,
3646
json={"blocks": message}
3747
)
3848

3949
if response.status_code >= 400:
4050
logger.error("Slack error %s: %s", response.status_code, response.text)
51+
elif config.enable_debug:
52+
logger.debug(f"Slack webhook response: {response.status_code}")
4153

4254
@staticmethod
4355
def create_slack_blocks_from_diff(diff: Diff, config: CliConfig):

0 commit comments

Comments
 (0)