Skip to content

Commit 2910edf

Browse files
authored
fix: alert rules empty arrays (#1347)
1 parent 4c1c21c commit 2910edf

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

api/alert_rules.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -154,26 +154,26 @@ const (
154154
// NewAlertRule returns an instance of the AlertRule struct
155155
//
156156
// Basic usage: Initialize a new AlertRule struct, then
157-
// use the new instance to do CRUD operations
158157
//
159-
// client, err := api.NewClient("account")
160-
// if err != nil {
161-
// return err
162-
// }
158+
// use the new instance to do CRUD operations
163159
//
164-
// alertRule := api.NewAlertRule(
165-
// "Foo",
166-
// api.AlertRuleConfig{
167-
// Description: "My Alert Rule"
168-
// Severities: api.AlertRuleSeverities{api.AlertRuleSeverityHigh,
169-
// Channels: []string{"TECHALLY_000000000000AAAAAAAAAAAAAAAAAAAA"},
170-
// ResourceGroups: []string{"TECHALLY_111111111111AAAAAAAAAAAAAAAAAAAA"}
171-
// },
172-
// },
173-
// )
160+
// client, err := api.NewClient("account")
161+
// if err != nil {
162+
// return err
163+
// }
174164
//
175-
// client.V2.AlertRules.Create(alertRule)
165+
// alertRule := api.NewAlertRule(
166+
// "Foo",
167+
// api.AlertRuleConfig{
168+
// Description: "My Alert Rule"
169+
// Severities: api.AlertRuleSeverities{api.AlertRuleSeverityHigh,
170+
// Channels: []string{"TECHALLY_000000000000AAAAAAAAAAAAAAAAAAAA"},
171+
// ResourceGroups: []string{"TECHALLY_111111111111AAAAAAAAAAAAAAAAAAAA"}
172+
// },
173+
// },
174+
// )
176175
//
176+
// client.V2.AlertRules.Create(alertRule)
177177
func NewAlertRule(name string, rule AlertRuleConfig) AlertRule {
178178
return AlertRule{
179179
Channels: rule.Channels,
@@ -272,10 +272,10 @@ type AlertRuleFilter struct {
272272
Enabled int `json:"enabled"`
273273
Description string `json:"description,omitempty"`
274274
Severity []int `json:"severity"`
275-
ResourceGroups []string `json:"resourceGroups,omitempty"`
276-
EventCategories []string `json:"eventCategory,omitempty"`
275+
ResourceGroups []string `json:"resourceGroups"`
276+
EventCategories []string `json:"eventCategory"`
277277
Sources []string `json:"sources,omitempty"`
278-
AlertCategories []string `json:"category,omitempty"`
278+
AlertCategories []string `json:"category"`
279279
CreatedOrUpdatedTime string `json:"createdOrUpdatedTime,omitempty"`
280280
CreatedOrUpdatedBy string `json:"createdOrUpdatedBy,omitempty"`
281281
}

cli/cmd/alert_rules.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,18 +288,21 @@ func promptCreateAlertRule() (api.AlertRuleResponse, error) {
288288
}
289289

290290
resourceGroups, resourceGroupMap := promptAddResourceGroupsToAlertRule()
291-
var groups []string
291+
groups := make([]string, 0)
292292
for _, group := range resourceGroups {
293293
groups = append(groups, resourceGroupMap[group])
294294
}
295295

296+
alertCategories := make([]string, 0)
297+
296298
alertRule := api.NewAlertRule(
297299
answers.Name,
298300
api.AlertRuleConfig{
299301
Description: answers.Description,
300302
Channels: channels,
301303
Severities: api.NewAlertRuleSeverities(answers.Severities),
302304
EventCategories: answers.EventCategories,
305+
AlertCategories: alertCategories,
303306
ResourceGroups: groups,
304307
})
305308

integration/alert_rules_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build alert_rule
2-
31
// Author:: Darren Murray (<[email protected]>)
42
// Copyright:: Copyright 2021, Lacework Inc.
53
// License:: Apache License, Version 2.0
@@ -114,6 +112,8 @@ func createAlertRuleWithSlackAlertChannel() (alertRule api.AlertRuleResponse, er
114112
Description: "This is a test Alert Rule",
115113
Severities: api.NewAlertRuleSeverities([]string{"Critical", "High"}),
116114
EventCategories: []string{"Compliance"},
115+
AlertCategories: []string{},
116+
ResourceGroups: []string{},
117117
})
118118

119119
return lacework.V2.AlertRules.Create(rule)

0 commit comments

Comments
 (0)