From 4132387eeb2ba9adaf5660005c45ddc8b77b80ee Mon Sep 17 00:00:00 2001 From: Abdul Rehman Date: Fri, 1 Aug 2025 11:53:16 +0400 Subject: [PATCH 1/3] Update bash_enrichments.py - add sshexecutor This function allows to execute commands via SSH, usually when you have VMs or servers outside Kubernetes --- .../robusta_playbooks/bash_enrichments.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/playbooks/robusta_playbooks/bash_enrichments.py b/playbooks/robusta_playbooks/bash_enrichments.py index 17ed42ff2..d4bf99b8c 100644 --- a/playbooks/robusta_playbooks/bash_enrichments.py +++ b/playbooks/robusta_playbooks/bash_enrichments.py @@ -40,3 +40,39 @@ def node_bash_enricher(event: NodeEvent, params: BashParams): block_list.append(MarkdownBlock(f"Command results for *{params.bash_command}:*")) block_list.append(MarkdownBlock(exec_result)) event.add_enrichment(block_list) + + +@action +def generic_bash_enricher(event: ExecutionBaseEvent, params): + """ + Run any bash command on the runner (can include SSH to remote hosts if desired). + Params: + bash_command: List of command args (recommended), or string for shell execution. + """ + bash_command = params.get("bash_command") + if not bash_command: + event.add_enrichment([MarkdownBlock(":warning: `bash_command` param is required!")]) + return + + try: + if isinstance(bash_command, str): + result = subprocess.run(bash_command, shell=True, capture_output=True, text=True) + else: + result = subprocess.run(bash_command, capture_output=True, text=True) + output = result.stdout.strip() + error = result.stderr.strip() + status = result.returncode + except Exception as e: + output = "" + error = str(e) + status = 1 + + message = ( + f"**Generic Bash Enricher**\n" + f"Command: `{bash_command}`\n" + f"Return code: `{status}`\n" + f"---\n" + f"**STDOUT:**\n```\n{output}\n```\n" + f"**STDERR:**\n```\n{error}\n```" + ) + event.add_enrichment([MarkdownBlock(message)]) From 00f4862df55620f6b1cc077a6ec0d71a5bf65944 Mon Sep 17 00:00:00 2001 From: Abdul Rehman Date: Fri, 1 Aug 2025 12:05:07 +0400 Subject: [PATCH 2/3] Update bash_enrichments.py --- playbooks/robusta_playbooks/bash_enrichments.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playbooks/robusta_playbooks/bash_enrichments.py b/playbooks/robusta_playbooks/bash_enrichments.py index d4bf99b8c..b69764c6e 100644 --- a/playbooks/robusta_playbooks/bash_enrichments.py +++ b/playbooks/robusta_playbooks/bash_enrichments.py @@ -1,4 +1,4 @@ -import logging +import logging, subprocess from typing import List from robusta.api import BaseBlock, BashParams, MarkdownBlock, NodeEvent, PodEvent, RobustaPod, action From 0cbfb0a0bb7c65d91a770b8ffe15d03475e51931 Mon Sep 17 00:00:00 2001 From: Abdul Rehman Date: Fri, 1 Aug 2025 12:14:41 +0400 Subject: [PATCH 3/3] Update bash_enrichments.py --- playbooks/robusta_playbooks/bash_enrichments.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/playbooks/robusta_playbooks/bash_enrichments.py b/playbooks/robusta_playbooks/bash_enrichments.py index b69764c6e..173c87d42 100644 --- a/playbooks/robusta_playbooks/bash_enrichments.py +++ b/playbooks/robusta_playbooks/bash_enrichments.py @@ -1,8 +1,6 @@ import logging, subprocess from typing import List - -from robusta.api import BaseBlock, BashParams, MarkdownBlock, NodeEvent, PodEvent, RobustaPod, action - +from robusta.api import BaseBlock, BashParams, ExecutionBaseEvent, MarkdownBlock, NodeEvent, PodEvent, RobustaPod, action @action def pod_bash_enricher(event: PodEvent, params: BashParams):