Skip to content

Commit

Permalink
Merge pull request #80 from iLert/feature/add-telegram-alert-action-type
Browse files Browse the repository at this point in the history
Feature/add telegram alert action type
  • Loading branch information
STLVRTX authored Jan 13, 2024
2 parents c04e1b5 + 6eda070 commit 3c10993
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 12.01.2024, Version 2.5.0

- feature/add-telegram-alert-action-type in [#80](https://github.com/iLert/terraform-provider-ilert/pull/80)

## 05.01.2024, Version 2.4.1

- fix/status-page-theme-mode-field in [#79](https://github.com/iLert/terraform-provider-ilert/pull/79)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.19

require (
github.com/hashicorp/terraform-plugin-sdk/v2 v2.25.0
github.com/iLert/ilert-go/v3 v3.4.1
github.com/iLert/ilert-go/v3 v3.5.0
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/iLert/ilert-go/v3 v3.4.1 h1:kXofKIkU4b/Mm2fG3INnJSz6g5XATgQwY/ExmsEX0u0=
github.com/iLert/ilert-go/v3 v3.4.1/go.mod h1:xHJ8qdmthK4HExcQOd3V5JARed/EBKTdX86MqrJ1yJ0=
github.com/iLert/ilert-go/v3 v3.5.0 h1:lIQqtO8BosDNri1ZkTTlG6kYOSDepdSygfCx00EMyIw=
github.com/iLert/ilert-go/v3 v3.5.0/go.mod h1:xHJ8qdmthK4HExcQOd3V5JARed/EBKTdX86MqrJ1yJ0=
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
Expand Down
33 changes: 32 additions & 1 deletion ilert/resource_alert_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,22 @@ func resourceAlertAction() *schema.Resource {
},
},
},

"telegram": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
MinItems: 1,
ForceNew: true,
ConflictsWith: removeStringsFromSlice(alertActionTypesAll, ilert.ConnectorTypes.Telegram),
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"channel_id": {
Type: schema.TypeString,
Required: true,
},
},
},
},
"created_at": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -960,6 +975,16 @@ func buildAlertAction(d *schema.ResourceData) (*ilert.AlertAction, error) {
}
}

if val, ok := d.GetOk("telegram"); ok {
vL := val.([]interface{})
if len(vL) > 0 {
v := vL[0].(map[string]interface{})
alertAction.Params = &ilert.AlertActionParamsTelegram{
ChannelID: v["channel_id"].(string),
}
}
}

if val, ok := d.GetOk("alert_filter"); ok {
vL := val.([]interface{})
if len(vL) > 0 {
Expand Down Expand Up @@ -1237,6 +1262,12 @@ func resourceAlertActionRead(ctx context.Context, d *schema.ResourceData, m inte
"service_ids": result.AlertAction.Params.ServiceIds,
},
})
case ilert.ConnectorTypes.Telegram:
d.Set("telegram", []interface{}{
map[string]interface{}{
"channel_id": result.AlertAction.Params.ChannelID,
},
})
}

alertFilter, err := flattenAlertActionAlertFilter(result.AlertAction.AlertFilter)
Expand Down
2 changes: 1 addition & 1 deletion ilert/resource_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

func resourceConnector() *schema.Resource {
// include only type that schema supports
connectorTypesAll := removeStringsFromSlice(ilert.ConnectorTypesAll, ilert.ConnectorTypes.Email, ilert.ConnectorTypes.MicrosoftTeams, ilert.ConnectorTypes.MicrosoftTeamsBot, ilert.ConnectorTypes.ZoomChat, ilert.ConnectorTypes.ZoomMeeting, ilert.ConnectorTypes.Webex, ilert.ConnectorTypes.Slack, ilert.ConnectorTypes.Webhook, ilert.ConnectorTypes.Zapier, ilert.ConnectorTypes.DingTalkAction, ilert.ConnectorTypes.AutomationRule)
connectorTypesAll := removeStringsFromSlice(ilert.ConnectorTypesAll, ilert.ConnectorTypes.Email, ilert.ConnectorTypes.MicrosoftTeams, ilert.ConnectorTypes.MicrosoftTeamsBot, ilert.ConnectorTypes.ZoomChat, ilert.ConnectorTypes.ZoomMeeting, ilert.ConnectorTypes.Webex, ilert.ConnectorTypes.Slack, ilert.ConnectorTypes.Webhook, ilert.ConnectorTypes.Zapier, ilert.ConnectorTypes.DingTalkAction, ilert.ConnectorTypes.AutomationRule, ilert.ConnectorTypes.Telegram)
return &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Expand Down
7 changes: 7 additions & 0 deletions website/docs/r/alert_action.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ The following arguments are supported:
- `dingtalk` - (Optional) A [dingtalk](#dingtalk-arguments) block.
- `dingtalk_action` - (Optional) A [dingtalk_action](#dingtalk-action-arguments) block.
- `automation_rule` - (Optional) An [automation_rule](#automation-rule-arguments) block.
- `telegram` - (Optional) An [telegram](#telegram-arguments) block.
- `alert_filter` - (Optional) An [alert_filter](#alert-filter-arguments) block.

#### Alert Source Arguments
Expand Down Expand Up @@ -252,6 +253,12 @@ The following arguments are supported:
- `resolve_incident` - (Optional, requires `template_id`) Determines whether an incident should be resolved or not. Default: `false`
- `send_notification` - (Optional, requires `template_id`) Determines whether notifications should be sent or not. Default: `false`

#### Telegram Arguments

> See [the Telegram integration documentation](https://docs.ilert.com/integrations/telegram) for more details.
- `channel_id` - (Required) The Telegram channel id.

#### Alert Filter Arguments

- `operator` - (Required) The operator to use for the filter. Allowed values are `AND` or `OR`.
Expand Down

0 comments on commit 3c10993

Please sign in to comment.