Skip to content

Commit

Permalink
fix: Slack command output disable affected full message instead of co…
Browse files Browse the repository at this point in the history
…mmand output only
  • Loading branch information
furan917 committed Nov 27, 2023
1 parent 5060a6b commit 0f1773d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ _All caps for envs, lowercase for config file_
- `MAGECOMM_RMQ_PASS` Default: ``
- `MAGECOMM_RMQ_TLS` Default: `false`
- `MAGECOMM_RMQ_VHOST` Default: `/`
- `MAGECOMM_SLACK_ENABLED` Default: `false`, (true|false), if true you must configure the WEBHOOK or APP configurations to work
- `MAGECOMM_SLACK_DISABLE_OUTPUT_NOTIFICATIONS` Default: 'false, (true|false), if true we will not send output notifications to slack
- `MAGECOMM_SLACK_ENABLED` Default: `false`, (true|false), if true you must configure the WEBHOOK or APP configurations to work. When true will send to slack a message when a command has executed with the command, the environment it was on and the commands output
- `MAGECOMM_SLACK_DISABLE_OUTPUT_NOTIFICATIONS` Default: `false`, (true|false), if true command outputs will not be sent to slack along with the execution message
- `MAGECOMM_SLACK_WEBHOOK_URL` Default: ``
- `MAGECOMM_SLACK_WEBHOOK_CHANNEL` Default: ``
- `MAGECOMM_SLACK_WEBHOOK_USERNAME` Default: ``
Expand Down
16 changes: 12 additions & 4 deletions messages/handler/magerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,22 @@ func (handler *MagerunHandler) ProcessMessage(messageBody string, correlationID
output = "Command finished with no output"
}

if config_manager.GetBoolValue(config_manager.ConfigSlackEnabled) && !config_manager.GetBoolValue(config_manager.ConfigSlackDisableOutputNotifications) {
if config_manager.GetBoolValue(config_manager.ConfigSlackEnabled) {
logger.Infof("Slack notification is enabled, sending output notification")
notifier := notifictions.DefaultSlackNotifier
commandOutputMessage := ""
outputMessage := fmt.Sprintf(
" Command: '%v' on environment: '%s' ran with output: \n %s",
"Executed Command: '%v' on Environment: '%s'",
strings.Join(strings.Fields(messageBody), " "),
config_manager.GetValue(config_manager.CommandConfigEnvironment),
output)
config_manager.GetValue(config_manager.CommandConfigEnvironment))

if !config_manager.GetBoolValue(config_manager.ConfigSlackDisableOutputNotifications) {
commandOutputMessage = fmt.Sprintf(
"Returned with output: \n %s",
output)
outputMessage = outputMessage + "\n" + commandOutputMessage
}

err := notifier.Notify(fmt.Sprintf(outputMessage))
if err != nil {
logger.Warnf("Failed to send slack output notification: %v\n", err)
Expand Down

0 comments on commit 0f1773d

Please sign in to comment.