Skip to content

Commit de5140b

Browse files
authored
Create a new action for Splunk alarms to send to slack app (#219)
* Create a new action for Splunk alarms to send to slack app * Fix url * Fix test * Restore missing character * Fix param name * Fix test name * Again * Fix url again
1 parent 2c2e382 commit de5140b

File tree

4 files changed

+102
-0
lines changed

4 files changed

+102
-0
lines changed

client/models/saved_searches.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ type SavedSearchObject struct {
117117
ActionSlackParamFields string `json:"action.slack.param.fields,omitempty" url:"action.slack.param.fields"`
118118
ActionSlackParamMessage string `json:"action.slack.param.message,omitempty" url:"action.slack.param.message"`
119119
ActionSlackParamWebhookUrlOverride string `json:"action.slack.param.webhook_url_override,omitempty" url:"action.slack.param.webhook_url_override"`
120+
ActionSlackAppAlertIntegrationParamAutoJoinChannel string `json:"action.slack_app_alert_integration.param.auto_join_channel,omitempty" url:"action.slack_app_alert_integration.param.auto_join_channel"`
121+
ActionSlackAppAlertIntegrationParamBotUsername string `json:"action.slack_app_alert_integration.param.bot_username,omitempty" url:"action.slack_app_alert_integration.param.bot_username"`
122+
ActionSlackAppAlertIntegrationParamChannel string `json:"action.slack_app_alert_integration.param.channel,omitempty" url:"action.slack_app_alert_integration.param.channel"`
123+
ActionSlackAppAlertIntegrationParamEmoji string `json:"action.slack_app_alert_integration.param.emoji,omitempty" url:"action.slack_app_alert_integration.param.emoji"`
124+
ActionSlackAppAlertIntegrationParamMessage string `json:"action.slack_app_alert_integration.param.message,omitempty" url:"action.slack_app_alert_integration.param.message"`
120125
ActionJiraServiceDeskParamAccount string `json:"action.jira_service_desk.param.account,omitempty" url:"action.jira_service_desk.param.account"`
121126
ActionJiraServiceDeskParamJiraProject string `json:"action.jira_service_desk.param.jira_project,omitempty" url:"action.jira_service_desk.param.jira_project"`
122127
ActionJiraServiceDeskParamJiraIssueType string `json:"action.jira_service_desk.param.jira_issue_type,omitempty" url:"action.jira_service_desk.param.jira_issue_type"`

docs/resources/saved_searches.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ This resource block supports the following arguments:
130130
- `action_slack_param_attachment` - (Optional) Include a message attachment. Valid values are message, none, or alert_link
131131
- `action_slack_param_message` - (Optional) Enter the chat message to send to the Slack channel. The message can include tokens that insert text based on the results of the search.
132132
- `action_slack_param_webhook_url_override` - (Optional) You can override the Slack webhook URL here if you need to send the alert message to a different Slack team
133+
- `action_slack_app_alert_integration_param_auto_join_channel` - (Optional) Automatically join the channel if the bot is not already a member (Should be 1 (Enabled) or 0 (Disabled))
134+
- `action_slack_app_alert_integration_param_bot_username` - (Optional) The bot username that will post the message
135+
- `action_slack_app_alert_integration_param_channel` - (Optional) Slack channel to send the message to (Should start with # or @)
136+
- `action_slack_app_alert_integration_param_emoji` - (Optional) Emoji icon to use as the bot's avatar (Should start and end with :)
137+
- `action_slack_app_alert_integration_param_message` - (Optional) Enter the chat message to send to the Slack channel. The message can include tokens that insert text based on the results of the
138+
- `action_slack_app_alert_integration_param_fields`
133139
- `action_jira_service_desk_param_account` - (Optional) Jira Service Desk account name
134140
- `action_jira_service_desk_param_jira_project` - (Optional) Jira Project name
135141
- `action_jira_service_desk_param_jira_issue_type` - (Optional) Jira issue type name

splunk/resource_splunk_saved_searches.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,31 @@ func savedSearches() *schema.Resource {
696696
Optional: true,
697697
Description: "You can override the Slack webhook URL here if you need to send the alert message to a different Slack team.",
698698
},
699+
"action_slack_app_alert_integration_param_auto_join_channel": {
700+
Type: schema.TypeString,
701+
Optional: true,
702+
Description: "Valid values: (1 | 0) Specify whether the Slack App bot should automatically join the channel if it is not already a member. Defaults to false.",
703+
},
704+
"action_slack_app_alert_integration_param_bot_username": {
705+
Type: schema.TypeString,
706+
Optional: true,
707+
Description: "Specify a custom bot username for the Slack App alert.",
708+
},
709+
"action_slack_app_alert_integration_param_channel": {
710+
Type: schema.TypeString,
711+
Optional: true,
712+
Description: "Slack channel to send the message to (Should not start with #)",
713+
},
714+
"action_slack_app_alert_integration_param_emoji": {
715+
Type: schema.TypeString,
716+
Optional: true,
717+
Description: "Specify a custom bot emoji for the Slack App alert.",
718+
},
719+
"action_slack_app_alert_integration_param_message": {
720+
Type: schema.TypeString,
721+
Optional: true,
722+
Description: "Enter the chat message to send to the Slack channel. The message can include tokens that insert text based on the results of the search.",
723+
},
699724
"action_jira_service_desk_param_account": {
700725
Type: schema.TypeString,
701726
Optional: true,
@@ -1608,6 +1633,21 @@ func savedSearchesRead(d *schema.ResourceData, meta interface{}) error {
16081633
if err = d.Set("action_slack_param_webhook_url_override", entry.Content.ActionSlackParamWebhookUrlOverride); err != nil {
16091634
return err
16101635
}
1636+
if err = d.Set("action_slack_app_alert_integration_param_auto_join_channel", entry.Content.ActionSlackAppAlertIntegrationParamAutoJoinChannel); err != nil {
1637+
return err
1638+
}
1639+
if err = d.Set("action_slack_app_alert_integration_param_bot_username", entry.Content.ActionSlackAppAlertIntegrationParamBotUsername); err != nil {
1640+
return err
1641+
}
1642+
if err = d.Set("action_slack_app_alert_integration_param_channel", entry.Content.ActionSlackAppAlertIntegrationParamChannel); err != nil {
1643+
return err
1644+
}
1645+
if err = d.Set("action_slack_app_alert_integration_param_emoji", entry.Content.ActionSlackAppAlertIntegrationParamEmoji); err != nil {
1646+
return err
1647+
}
1648+
if err = d.Set("action_slack_app_alert_integration_param_message", entry.Content.ActionSlackAppAlertIntegrationParamMessage); err != nil {
1649+
return err
1650+
}
16111651
if err = d.Set("action_jira_service_desk_param_account", entry.Content.ActionJiraServiceDeskParamAccount); err != nil {
16121652
return err
16131653
}
@@ -2013,6 +2053,11 @@ func getSavedSearchesConfig(d *schema.ResourceData) (savedSearchesObj *models.Sa
20132053
ActionSlackParamFields: d.Get("action_slack_param_fields").(string),
20142054
ActionSlackParamMessage: d.Get("action_slack_param_message").(string),
20152055
ActionSlackParamWebhookUrlOverride: d.Get("action_slack_param_webhook_url_override").(string),
2056+
ActionSlackAppAlertIntegrationParamAutoJoinChannel: d.Get("action_slack_app_alert_integration_param_auto_join_channel").(string),
2057+
ActionSlackAppAlertIntegrationParamBotUsername: d.Get("action_slack_app_alert_integration_param_bot_username").(string),
2058+
ActionSlackAppAlertIntegrationParamChannel: d.Get("action_slack_app_alert_integration_param_channel").(string),
2059+
ActionSlackAppAlertIntegrationParamEmoji: d.Get("action_slack_app_alert_integration_param_emoji").(string),
2060+
ActionSlackAppAlertIntegrationParamMessage: d.Get("action_slack_app_alert_integration_param_message").(string),
20162061
ActionJiraServiceDeskParamAccount: d.Get("action_jira_service_desk_param_account").(string),
20172062
ActionJiraServiceDeskParamJiraProject: d.Get("action_jira_service_desk_param_jira_project").(string),
20182063
ActionJiraServiceDeskParamJiraIssueType: d.Get("action_jira_service_desk_param_jira_issue_type").(string),

splunk/resource_splunk_saved_searches_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,29 @@ resource "splunk_saved_searches" "test" {
195195
realtime_schedule = true
196196
search = "index=main level=error"
197197
}
198+
199+
`
200+
const newSavedSearchesSlackAppAlertIntegration = `
201+
resource "splunk_saved_searches" "test" {
202+
name = "Test Slack App Alert"
203+
actions = "slack_app_alert"
204+
action_slack_app_alert_integration_param_auto_join_channel = "1"
205+
action_slack_app_alert_integration_param_bot_username = "SplunkBot"
206+
action_slack_app_alert_integration_param_channel = "channel"
207+
action_slack_app_alert_integration_param_emoji = ":splunk:"
208+
action_slack_app_alert_integration_param_message = "error message"
209+
alert_comparator = "greater than"
210+
alert_digest_mode = true
211+
alert_expires = "30d"
212+
alert_threshold = "0"
213+
alert_type = "number of events"
214+
cron_schedule = "*/1 * * * *"
215+
disabled = false
216+
is_scheduled = true
217+
is_visible = true
218+
realtime_schedule = true
219+
search = "index=main level=error"
220+
}
198221
`
199222

200223
const newSavedSearchesVictorops = `
@@ -540,6 +563,29 @@ func TestAccSplunkSavedSearches(t *testing.T) {
540563
resource.TestCheckResourceAttr(resourceName, "search", "index=main level=error"),
541564
),
542565
},
566+
{
567+
Config: newSavedSearchesSlackAppAlertIntegration,
568+
Check: resource.ComposeTestCheckFunc(
569+
resource.TestCheckResourceAttr(resourceName, "name", "Test Slack App Alert"),
570+
resource.TestCheckResourceAttr(resourceName, "actions", "slack_app_alert"),
571+
resource.TestCheckResourceAttr(resourceName, "action_slack_app_alert_integration_param_auto_join_channel", "1"),
572+
resource.TestCheckResourceAttr(resourceName, "action_slack_app_alert_integration_param_bot_username", "SplunkBot"),
573+
resource.TestCheckResourceAttr(resourceName, "action_slack_app_alert_integration_param_channel", "channel"),
574+
resource.TestCheckResourceAttr(resourceName, "action_slack_app_alert_integration_param_emoji", ":splunk:"),
575+
resource.TestCheckResourceAttr(resourceName, "action_slack_app_alert_integration_param_message", "error message"),
576+
resource.TestCheckResourceAttr(resourceName, "alert_comparator", "greater than"),
577+
resource.TestCheckResourceAttr(resourceName, "alert_digest_mode", "true"),
578+
resource.TestCheckResourceAttr(resourceName, "alert_expires", "30d"),
579+
resource.TestCheckResourceAttr(resourceName, "alert_threshold", "0"),
580+
resource.TestCheckResourceAttr(resourceName, "alert_type", "number of events"),
581+
resource.TestCheckResourceAttr(resourceName, "cron_schedule", "*/1 * * * *"),
582+
resource.TestCheckResourceAttr(resourceName, "disabled", "false"),
583+
resource.TestCheckResourceAttr(resourceName, "is_scheduled", "true"),
584+
resource.TestCheckResourceAttr(resourceName, "is_visible", "true"),
585+
resource.TestCheckResourceAttr(resourceName, "realtime_schedule", "true"),
586+
resource.TestCheckResourceAttr(resourceName, "search", "index=main level=error"),
587+
),
588+
},
543589
{
544590
Config: newSavedSearchesVictorops,
545591
Check: resource.ComposeTestCheckFunc(

0 commit comments

Comments
 (0)