Skip to content

Commit

Permalink
Extend alert muting rule with field recurrence (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdudzik-splunk authored May 23, 2024
1 parent e5064b1 commit 145517a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 2 deletions.
2 changes: 2 additions & 0 deletions alertmuting/model_alert_muting_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type AlertMutingRule struct {
LastUpdated int64 `json:"lastUpdated,omitempty"`
// The SignalFx-assigned user ID of the last user who updated the alert muting rule, in the form of a JSON string. If the system made the last update, the value is \"AAAAAAAAAA\". **This property is read-only; it's always set by the system.**
LastUpdatedBy string `json:"lastUpdatedBy,omitempty"`
// Recurrence period of the muting rule. **read/write**
Recurrence *AlertMutingRuleRecurrence `json:"recurrence,omitempty"`
// Toggle if alerts should be sent once the muting period is over. If not specified, defaults to true
SendAlertsOnceMutingPeriodHasEnded bool `json:"sendAlertsOnceMutingPeriodHasEnded,omitempty"`
// Starting time of an alert muting rule, in Unix time format UTC. If not specified, defaults to the current time. **read/write**.
Expand Down
6 changes: 6 additions & 0 deletions alertmuting/model_alert_muting_rule_recurrence.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package alertmuting

type AlertMutingRuleRecurrence struct {
Value int32 `json:"value,omitempty"`
Unit string `json:"unit,omitempty"`
}
2 changes: 2 additions & 0 deletions alertmuting/model_create_update_alert_muting_rule_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ type CreateUpdateAlertMutingRuleRequest struct {
Description string `json:"description,omitempty"`
// List of alert muting filters for this rule, in the form of a JSON array of alert muting filter objects. Each object is a set of conditions for an alert muting rule. Each object property (name-value pair) specifies a dimension or custom property to match to alert events. **read/write**
Filters []*AlertMutingRuleFilter `json:"filters,omitempty"`
// Recurrence period of the muting rule. **read/write**
Recurrence *AlertMutingRuleRecurrence `json:"recurrence,omitempty"`
// Toggle if alerts should be sent once the muting period is over. If not specified, defaults to true **read/write**
SendAlertsOnceMutingPeriodHasEnded bool `json:"sendAlertsOnceMutingPeriodHasEnded,omitempty"`
// Starting time of an alert muting rule, in Unix time format UTC. If not specified, defaults to the current time. **read/write**.
Expand Down
10 changes: 10 additions & 0 deletions alertmuting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ func TestGetAlertMutingRule(t *testing.T) {
result, err := client.GetAlertMutingRule(context.Background(), "string")
assert.NoError(t, err, "Unexpected error getting alert mutnig rule")
assert.Equal(t, result.Description, "string", "Name does not match")
assert.NotNil(t, result.Recurrence, "Recurrence is nil")
assert.Equal(t, "d", result.Recurrence.Unit, "Recurrence Unit does not match")
assert.Equal(t, int32(10), result.Recurrence.Value, "Recurrence Value does not match")
assert.Equal(t, "server6", result.Filters[0].PropertyValue.Values[1], "Property Value does not match")
}

Expand Down Expand Up @@ -115,8 +118,15 @@ func TestUpdateAlertMutingRule(t *testing.T) {

result, err := client.UpdateAlertMutingRule(context.Background(), "string", &alertmuting.CreateUpdateAlertMutingRuleRequest{
Description: "string",
Recurrence: &alertmuting.AlertMutingRuleRecurrence{
Unit: "d",
Value: 10,
},
})
assert.NoError(t, err, "Unexpected error updating alert muting rule")
assert.NotNil(t, result.Recurrence, "Recurrence is nil")
assert.Equal(t, "d", result.Recurrence.Unit, "Recurrence Unit does not match")
assert.Equal(t, int32(10), result.Recurrence.Value, "Recurrence Value does not match")
assert.Equal(t, "string", result.Description, "Description does not match")
}

Expand Down
6 changes: 5 additions & 1 deletion testdata/fixtures/alertmuting/get_success.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@
"lastUpdated": 1557689430000,
"lastUpdatedBy": "string",
"startTime": 0,
"stopTime": 0
"stopTime": 0,
"recurrence": {
"unit": "d",
"value": 10
}
}
6 changes: 5 additions & 1 deletion testdata/fixtures/alertmuting/update_success.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@
"lastUpdated": 1557689430000,
"lastUpdatedBy": "string",
"startTime": 0,
"stopTime": 0
"stopTime": 0,
"recurrence": {
"unit": "d",
"value": 10
}
}

0 comments on commit 145517a

Please sign in to comment.