Skip to content

Commit dc45130

Browse files
authored
Add --slacktitle CLI option to be able to provide a custom title in the Slack message output (#459)
This PR adds the ability to provide a custom message in the slack output. This is useful for example if you want to include the environment name or something similar.
1 parent 90cbfc8 commit dc45130

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

robusta_krr/core/models/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class Config(pd.BaseSettings):
7070
file_output: Optional[str] = pd.Field(None)
7171
file_output_dynamic: bool = pd.Field(False)
7272
slack_output: Optional[str] = pd.Field(None)
73+
slack_title: Optional[str] = pd.Field(None)
7374
azureblob_output: Optional[str] = pd.Field(None)
7475
teams_webhook: Optional[str] = pd.Field(None)
7576
azure_subscription_id: Optional[str] = pd.Field(None)

robusta_krr/core/runner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,10 @@ def _process_result(self, result: Result) -> None:
158158

159159
# Post message with file link to channel
160160
channel = settings.slack_output if settings.slack_output.startswith('#') else f"#{settings.slack_output}"
161+
slack_title = settings.slack_title if settings.slack_title else f'Kubernetes Resource Report for {(" ".join(settings.namespaces))}'
161162
client.chat_postMessage(
162163
channel=channel,
163-
text=f'Kubernetes Resource Report for {(" ".join(settings.namespaces))}\n{file_permalink}'
164+
text=f'{slack_title}\n{file_permalink}'
164165
)
165166

166167
os.remove(file_name)

robusta_krr/main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,12 @@ def run_strategy(
266266
help="Send to output to a slack channel, must have SLACK_BOT_TOKEN with permissions: chat:write, files:write, chat:write.public. Bot must be added to the channel.",
267267
rich_help_panel="Output Settings",
268268
),
269+
slack_title: Optional[str] = typer.Option(
270+
None,
271+
"--slacktitle",
272+
help="Title of the slack message. If not provided, will use the default 'Kubernetes Resource Report for <environment>'.",
273+
rich_help_panel="Output Settings",
274+
),
269275
azureblob_output: Optional[str] = typer.Option(
270276
None,
271277
"--azurebloboutput",
@@ -355,6 +361,7 @@ def run_strategy(
355361
file_output=file_output,
356362
file_output_dynamic=file_output_dynamic,
357363
slack_output=slack_output,
364+
slack_title=slack_title,
358365
azureblob_output=azureblob_output,
359366
teams_webhook=teams_webhook,
360367
azure_subscription_id=azure_subscription_id,

0 commit comments

Comments
 (0)