Skip to content

Commit

Permalink
feat(alert_muting_rule): Add action_on_muting_rule_window_ended att…
Browse files Browse the repository at this point in the history
…ribute in `newrelic_alert_muting_rule` Terraform Resource (#1259)

Co-authored-by: pranav-new-relic <[email protected]>
  • Loading branch information
Aashirwadjain and pranav-new-relic authored Jan 8, 2025
1 parent a221c9e commit 2a32988
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 26 deletions.
48 changes: 25 additions & 23 deletions pkg/alerts/muting_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ import (

// MutingRule represents the alert suppression mechanism in the Alerts API.
type MutingRule struct {
ID int `json:"id,string,omitempty"`
AccountID int `json:"accountId,omitempty"`
Condition MutingRuleConditionGroup `json:"condition,omitempty"`
CreatedAt string `json:"createdAt,omitempty"`
CreatedByUser ByUser `json:"createdByUser,omitempty"`
Description string `json:"description,omitempty"`
Enabled bool `json:"enabled"`
Name string `json:"name,omitempty"`
UpdatedAt string `json:"updatedAt,omitempty"`
UpdatedByUser ByUser `json:"updatedByUser,omitempty"`
Schedule *MutingRuleSchedule `json:"schedule,omitempty"`
ID int `json:"id,string,omitempty"`
AccountID int `json:"accountId,omitempty"`
ActionOnMutingRuleWindowEnded AlertsActionOnMutingRuleWindowEnded `json:"actionOnMutingRuleWindowEnded,omitempty"`
Condition MutingRuleConditionGroup `json:"condition,omitempty"`
CreatedAt string `json:"createdAt,omitempty"`
CreatedByUser ByUser `json:"createdByUser,omitempty"`
Description string `json:"description,omitempty"`
Enabled bool `json:"enabled"`
Name string `json:"name,omitempty"`
UpdatedAt string `json:"updatedAt,omitempty"`
UpdatedByUser ByUser `json:"updatedByUser,omitempty"`
Schedule *MutingRuleSchedule `json:"schedule,omitempty"`
}

// ByUser is a collection of the user information that created or updated the muting rule.
Expand Down Expand Up @@ -133,23 +134,24 @@ type MutingRuleScheduleUpdateInput struct {

// MutingRuleCreateInput is the input for creating muting rules.
type MutingRuleCreateInput struct {
Condition MutingRuleConditionGroup `json:"condition"`
Description string `json:"description"`
Enabled bool `json:"enabled"`
Name string `json:"name"`
Schedule *MutingRuleScheduleCreateInput `json:"schedule,omitempty"`
ActionOnMutingRuleWindowEnded AlertsActionOnMutingRuleWindowEnded `json:"actionOnMutingRuleWindowEnded,omitempty"`
Condition MutingRuleConditionGroup `json:"condition"`
Description string `json:"description"`
Enabled bool `json:"enabled"`
Name string `json:"name"`
Schedule *MutingRuleScheduleCreateInput `json:"schedule,omitempty"`
}

// MutingRuleUpdateInput is the input for updating a rule.
type MutingRuleUpdateInput struct {
// Condition is is available from the API, but the json needs to be handled
// properly.

Condition *MutingRuleConditionGroup `json:"condition,omitempty"`
Description string `json:"description,omitempty"`
Enabled bool `json:"enabled"`
Name string `json:"name,omitempty"`
Schedule *MutingRuleScheduleUpdateInput `json:"schedule"`
ActionOnMutingRuleWindowEnded AlertsActionOnMutingRuleWindowEnded `json:"actionOnMutingRuleWindowEnded,omitempty"`
Condition *MutingRuleConditionGroup `json:"condition,omitempty"`
Description string `json:"description,omitempty"`
Enabled bool `json:"enabled"`
Name string `json:"name,omitempty"`
Schedule *MutingRuleScheduleUpdateInput `json:"schedule"`
}

// ListMutingRules queries for all muting rules in a given account.
Expand Down Expand Up @@ -321,6 +323,7 @@ const (

alertsMutingRuleFields = `
accountId
actionOnMutingRuleWindowEnded
condition {
conditions {
attribute
Expand Down Expand Up @@ -361,7 +364,6 @@ const (
alertsMutingRulesCreate = `mutation CreateRule($accountID: Int!, $rule: AlertsMutingRuleInput!) {
alertsMutingRuleCreate(accountId: $accountID, rule: $rule) {` +
alertsMutingRuleFields +

`}
}`

Expand Down
14 changes: 11 additions & 3 deletions pkg/alerts/muting_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var (
"timeZone": "America/Los_Angeles",
"weeklyRepeatDays": null
},
"actionOnMutingRuleWindowEnded": "CLOSE_ISSUES_ON_INACTIVE",
"status": "INACTIVE",
"updatedAt": "2021-01-12T00:50:39.533Z",
"updatedByUser": {
Expand Down Expand Up @@ -117,7 +118,8 @@ var (
"gravatar": "https://secure.gravatar.com/avatar/692dc9742bd717014494f5093faff304",
"id": 1,
"name": "Test User"
}
},
"actionOnMutingRuleWindowEnded": "CLOSE_ISSUES_ON_INACTIVE"
}
}
}
Expand Down Expand Up @@ -168,7 +170,8 @@ var (
"gravatar": "https://secure.gravatar.com/avatar/692dc9742bd717014494f5093faff304",
"id": 1,
"name": "Test User"
}
},
"actionOnMutingRuleWindowEnded": "CLOSE_ISSUES_ON_INACTIVE"
}
}`

Expand All @@ -182,7 +185,8 @@ var (
"repeat": null,
"repeatCount": null,
"weeklyRepeatDays": null
}
},
"actionOnMutingRuleWindowEnded": "DO_NOTHING"
}
}`

Expand Down Expand Up @@ -248,6 +252,7 @@ func TestListMutingRules(t *testing.T) {
ID: 1,
Name: "Test User",
},
ActionOnMutingRuleWindowEnded: "CLOSE_ISSUES_ON_INACTIVE",
},
}

Expand Down Expand Up @@ -313,6 +318,7 @@ func TestGetMutingRule(t *testing.T) {
ID: 1,
Name: "Test User",
},
ActionOnMutingRuleWindowEnded: "CLOSE_ISSUES_ON_INACTIVE",
}

actual, err := alerts.GetMutingRule(accountID, ruleID)
Expand Down Expand Up @@ -376,6 +382,7 @@ func TestCreateMutingRule(t *testing.T) {
ID: 1,
Name: "Test User",
},
ActionOnMutingRuleWindowEnded: "CLOSE_ISSUES_ON_INACTIVE",
}

actual, err := alerts.CreateMutingRule(accountID, MutingRuleCreateInput{})
Expand Down Expand Up @@ -407,6 +414,7 @@ func TestUpdateMutingRule(t *testing.T) {
EndRepeat: &endRepeat,
StartTime: &startTime,
},
ActionOnMutingRuleWindowEnded: "DO_NOTHING",
}

actual, err := alerts.UpdateMutingRule(accountID, ruleID, MutingRuleUpdateInput{})
Expand Down
17 changes: 17 additions & 0 deletions pkg/alerts/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ package alerts

import "github.com/newrelic/newrelic-client-go/v2/pkg/nrtime"

// AlertsActionOnMutingRuleWindowEnded - Configuration on the action when the muting rule window is ended or disabled
type AlertsActionOnMutingRuleWindowEnded string

var AlertsActionOnMutingRuleWindowEndedTypes = struct {
// Muting Rule closes issues when the muting rule window is ended or disabled to notify users.
CLOSE_ISSUES_ON_INACTIVE AlertsActionOnMutingRuleWindowEnded
// The currently opened issues will not be notified even if the muting rule window is ended or disabled.
DO_NOTHING AlertsActionOnMutingRuleWindowEnded
}{
// Muting Rule closes issues when the muting rule window is ended or disabled to notify users.
CLOSE_ISSUES_ON_INACTIVE: "CLOSE_ISSUES_ON_INACTIVE",
// The currently opened issues will not be notified even if the muting rule window is ended or disabled.
DO_NOTHING: "DO_NOTHING",
}

// AlertsDayOfWeek - The day of the week used to configure a WEEKLY scheduled MutingRule
type AlertsDayOfWeek string

Expand Down Expand Up @@ -221,6 +236,8 @@ type AlertsMutingRuleConditionInput struct {

// AlertsMutingRuleInput - Input for creating MutingRules for New Relic Alerts Violations.
type AlertsMutingRuleInput struct {
// The action when the muting rule window is ended or disabled.
ActionOnMutingRuleWindowEnded AlertsActionOnMutingRuleWindowEnded `json:"actionOnMutingRuleWindowEnded,omitempty"`
// The condition that defines which violations to target.
Condition AlertsMutingRuleConditionGroupInput `json:"condition,omitempty"`
// The description of the MutingRule.
Expand Down

0 comments on commit 2a32988

Please sign in to comment.