Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(alerts-muting-rule): Add end_behaviour attribute in newrelic_alert_muting_rule Terraform Resource #1259

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 25 additions & 22 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"`
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"`
ActionOnMutingRuleWindowEnded AlertsActionOnMutingRuleWindowEnded `json:"actionOnMutingRuleWindowEnded,omitempty"`
}

// ByUser is a collection of the user information that created or updated the muting rule.
Expand Down Expand Up @@ -133,23 +134,25 @@ 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"`
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"`
}

// 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"`
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"`
}

// ListMutingRules queries for all muting rules in a given account.
Expand Down Expand Up @@ -356,12 +359,12 @@ const (
repeatCount
weeklyRepeatDays
}
actionOnMutingRuleWindowEnded
`

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
Loading