Skip to content

Commit 9b65eb9

Browse files
committed
Impove Slack bot mode debug logging to surface failures
Signed-off-by: lelia <lelia@socket.dev>
1 parent b15eea8 commit 9b65eb9

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

socketsecurity/output.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,20 @@ def handle_output(self, diff_report: Diff) -> None:
5858
slack_url = "Not configured"
5959
if self.config.slack_plugin.config and self.config.slack_plugin.config.get("url"):
6060
slack_url = self.config.slack_plugin.config.get("url")
61+
slack_mode = (self.config.slack_plugin.config or {}).get("mode", "webhook")
62+
bot_token = os.getenv("SOCKET_SLACK_BOT_TOKEN")
63+
bot_token_status = "Set" if bot_token else "Not set"
6164
self.logger.debug("=== Slack Webhook Debug Information ===")
6265
self.logger.debug(f"Slack Plugin Enabled: {self.config.slack_plugin.enabled}")
66+
self.logger.debug(f"Slack Mode: {slack_mode}")
6367
self.logger.debug(f"SOCKET_SLACK_ENABLED environment variable: {slack_enabled_env}")
6468
self.logger.debug(f"SOCKET_SLACK_CONFIG_JSON environment variable: {slack_config_env}")
6569
self.logger.debug(f"Slack Webhook URL: {slack_url}")
70+
self.logger.debug(f"SOCKET_SLACK_BOT_TOKEN: {bot_token_status}")
6671
self.logger.debug(f"Slack Alert Levels: {self.config.slack_plugin.levels}")
72+
if self.config.reach:
73+
facts_path = os.path.join(self.config.target_path or ".", self.config.reach_output_file or ".socket.facts.json")
74+
self.logger.debug(f"Reachability facts file: {facts_path} (exists: {os.path.exists(facts_path)})")
6775
self.logger.debug("=====================================")
6876

6977
if self.config.slack_plugin.enabled:

socketsecurity/plugins/slack.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,20 @@ def _send_bot_alerts(self, diff, config: CliConfig):
135135
if not bot_token:
136136
logger.error("SOCKET_SLACK_BOT_TOKEN environment variable not set for bot mode.")
137137
return
138-
138+
139139
if not bot_token.startswith("xoxb-"):
140140
logger.error("SOCKET_SLACK_BOT_TOKEN must start with 'xoxb-' (Bot User OAuth Token).")
141141
return
142-
142+
143+
logger.debug("SOCKET_SLACK_BOT_TOKEN: Set (valid xoxb- format)")
144+
143145
# Get bot_configs from configuration
144146
bot_configs = self.config.get("bot_configs", [])
145-
147+
146148
if not bot_configs:
147149
logger.warning("No bot_configs configured for bot mode.")
148150
return
149-
151+
150152
logger.debug("Slack Plugin Enabled (bot mode)")
151153
logger.debug("Alert levels: %s", self.config.get("levels"))
152154
logger.debug(f"Number of bot_configs: {len(bot_configs)}")
@@ -212,29 +214,35 @@ def _send_bot_reachability_alerts(self, bot_configs: list, bot_token: str, repo_
212214
"""Send reachability alerts using bot mode with Slack API."""
213215
# Construct path to socket facts file
214216
facts_file_path = os.path.join(config.target_path or ".", f"{config.reach_output_file}")
215-
logger.debug(f"Loading reachability data from {facts_file_path}")
216-
217+
facts_file_exists = os.path.exists(facts_file_path)
218+
logger.debug(f"Loading reachability data from {facts_file_path} (exists: {facts_file_exists})")
219+
220+
if not facts_file_exists:
221+
logger.error(f"Reachability facts file not found: {facts_file_path} — was --reach run successfully?")
222+
return
223+
217224
# Load socket facts file
218225
facts_data = load_socket_facts(facts_file_path)
219-
226+
220227
if not facts_data:
221-
logger.debug("No .socket.facts.json file found or failed to load")
228+
logger.error(f"Failed to load or parse reachability facts file: {facts_file_path}")
222229
return
223-
230+
224231
# Get components with vulnerabilities
225232
components_with_vulns = get_components_with_vulnerabilities(facts_data)
226-
233+
logger.debug(f"Components with vulnerabilities in facts file: {len(components_with_vulns) if components_with_vulns else 0}")
234+
227235
if not components_with_vulns:
228236
logger.debug("No components with vulnerabilities found in .socket.facts.json")
229237
return
230-
238+
231239
# Convert to alerts format
232240
components_with_alerts = convert_to_alerts(components_with_vulns)
233-
241+
234242
if not components_with_alerts:
235243
logger.debug("No alerts generated from .socket.facts.json")
236244
return
237-
245+
238246
logger.debug(f"Found {len(components_with_alerts)} components with reachability alerts")
239247

240248
# Send to each configured bot_config with filtering
@@ -265,10 +273,12 @@ def _send_bot_reachability_alerts(self, bot_configs: list, bot_token: str, repo_
265273
filtered_component['alerts'] = filtered_component_alerts
266274
filtered_components.append(filtered_component)
267275

276+
logger.debug(f"Bot config '{name}': {len(filtered_components)} components after severity filter {bot_config.get('severities', '(all)')}")
277+
268278
if not filtered_components:
269279
logger.debug(f"No reachability alerts match filter criteria for bot_config '{name}'. Skipping.")
270280
continue
271-
281+
272282
# Format for Slack using the formatter (max 45 blocks for findings + 5 for header/footer)
273283
slack_notifications = format_socket_facts_for_slack(
274284
filtered_components,

0 commit comments

Comments
 (0)