Skip to content

Commit 9df44a2

Browse files
authored
chore: use AlertRule subCategory in stead of eventCategory (#1429)
* chore: use AlertRule subCategory in stead of eventCategory
1 parent d6d09fc commit 9df44a2

File tree

6 files changed

+77
-52
lines changed

6 files changed

+77
-52
lines changed

api/_examples/alert-rules/main.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ func main() {
3434
}
3535

3636
rule := api.AlertRuleConfig{
37-
Channels: []string{"TECHALLY_000000000000AAAAAAAAAAAAAAAAAAAA"},
38-
Description: "This is a test alert rule",
39-
Severities: api.AlertRuleSeverities{api.AlertRuleSeverityHigh},
40-
ResourceGroups: []string{"TECHALLY_000000000000AAAAAAAAAAAAAAAAAAAA"},
41-
EventCategories: []string{"Compliance"},
42-
AlertCategories: []string{"Policy"},
43-
AlertSources: []string{"AWS"},
37+
Channels: []string{"TECHALLY_000000000000AAAAAAAAAAAAAAAAAAAA"},
38+
Description: "This is a test alert rule",
39+
Severities: api.AlertRuleSeverities{api.AlertRuleSeverityHigh},
40+
ResourceGroups: []string{"TECHALLY_000000000000AAAAAAAAAAAAAAAAAAAA"},
41+
AlertSubCategories: []string{"Compliance"},
42+
AlertCategories: []string{"Policy"},
43+
AlertSources: []string{"AWS"},
4444
}
4545

4646
myAlertRule := api.NewAlertRule("MyTestAlertRule",

api/alert_rules.go

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,22 @@ var AlertRuleCategories = []string{"Anomaly", "Policy", "Composite"}
4040
// Valid inputs for AlertRule SubCategories property
4141
var AlertRuleSubCategories = []string{
4242
"Compliance",
43-
"App",
44-
"Cloud",
43+
"Application",
44+
"Cloud Activity",
4545
"File",
4646
"Machine",
4747
"User",
4848
"Platform",
49-
"K8sActivity",
49+
"Kubernetes Activity",
5050
"Registry",
5151
"SystemCall",
52+
"Host Vulnerability",
53+
"Container Vulnerability",
54+
"Threat Intel",
55+
// Deprecated eventCategory values
56+
"App",
57+
"Cloud",
58+
"K8sActivity",
5259
}
5360

5461
type alertRuleSeverity int
@@ -142,6 +149,24 @@ func convertSeverityInt(sev int) alertRuleSeverity {
142149
}
143150
}
144151

152+
// Convert deprecated eventCatory values to subCategory values
153+
func convertEventCategories(categories []string) []string {
154+
var res []string
155+
for _, c := range categories {
156+
switch c {
157+
case "App":
158+
res = append(res, "Application")
159+
case "Cloud":
160+
res = append(res, "Cloud Activity")
161+
case "K8sActivity":
162+
res = append(res, "Kubernetes Activity")
163+
default:
164+
res = append(res, c)
165+
}
166+
}
167+
return res
168+
}
169+
145170
const (
146171
AlertRuleSeverityCritical alertRuleSeverity = 1
147172
AlertRuleSeverityHigh alertRuleSeverity = 2
@@ -179,14 +204,14 @@ func NewAlertRule(name string, rule AlertRuleConfig) AlertRule {
179204
Channels: rule.Channels,
180205
Type: AlertRuleEventType,
181206
Filter: AlertRuleFilter{
182-
Name: name,
183-
Enabled: 1,
184-
Description: rule.Description,
185-
Severity: rule.Severities.toInt(),
186-
ResourceGroups: rule.ResourceGroups,
187-
EventCategories: rule.EventCategories,
188-
AlertCategories: rule.AlertCategories,
189-
AlertSources: rule.AlertSources,
207+
Name: name,
208+
Enabled: 1,
209+
Description: rule.Description,
210+
Severity: rule.Severities.toInt(),
211+
ResourceGroups: rule.ResourceGroups,
212+
AlertSubCategories: convertEventCategories(rule.AlertSubCategories),
213+
AlertCategories: rule.AlertCategories,
214+
AlertSources: rule.AlertSources,
190215
},
191216
}
192217
}
@@ -251,13 +276,13 @@ func (svc *AlertRulesService) Get(guid string, response interface{}) error {
251276
}
252277

253278
type AlertRuleConfig struct {
254-
Channels []string
255-
Description string
256-
Severities AlertRuleSeverities
257-
ResourceGroups []string
258-
EventCategories []string
259-
AlertCategories []string
260-
AlertSources []string
279+
Channels []string
280+
Description string
281+
Severities AlertRuleSeverities
282+
ResourceGroups []string
283+
AlertSubCategories []string
284+
AlertCategories []string
285+
AlertSources []string
261286
}
262287

263288
type AlertRule struct {
@@ -273,7 +298,7 @@ type AlertRuleFilter struct {
273298
Description string `json:"description,omitempty"`
274299
Severity []int `json:"severity"`
275300
ResourceGroups []string `json:"resourceGroups"`
276-
EventCategories []string `json:"eventCategory"`
301+
AlertSubCategories []string `json:"subCategory"`
277302
AlertCategories []string `json:"category"`
278303
AlertSources []string `json:"source,omitempty"`
279304
CreatedOrUpdatedTime string `json:"createdOrUpdatedTime,omitempty"`

api/alert_rules_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,13 @@ func TestAlertRuleUpdate(t *testing.T) {
222222

223223
alertRule := api.NewAlertRule("rule_name",
224224
api.AlertRuleConfig{
225-
Channels: []string{"TECHALLY_000000000000AAAAAAAAAAAAAAAAAAAA"},
226-
Description: "This is a test alert rule",
227-
Severities: api.AlertRuleSeverities{api.AlertRuleSeverityHigh},
228-
ResourceGroups: []string{"TECHALLY_100000000000AAAAAAAAAAAAAAAAAAAB"},
229-
EventCategories: []string{"Compliance", "SystemCall"},
230-
AlertSources: []string{"AWS", "Agent", "K8s"},
231-
AlertCategories: []string{"Policy", "Anomaly"},
225+
Channels: []string{"TECHALLY_000000000000AAAAAAAAAAAAAAAAAAAA"},
226+
Description: "This is a test alert rule",
227+
Severities: api.AlertRuleSeverities{api.AlertRuleSeverityHigh},
228+
ResourceGroups: []string{"TECHALLY_100000000000AAAAAAAAAAAAAAAAAAAB"},
229+
AlertSubCategories: []string{"Compliance", "SystemCall"},
230+
AlertSources: []string{"AWS", "Agent", "K8s"},
231+
AlertCategories: []string{"Policy", "Anomaly"},
232232
},
233233
)
234234
assert.Equal(t, "rule_name", alertRule.Filter.Name, "alert rule name mismatch")
@@ -240,7 +240,7 @@ func TestAlertRuleUpdate(t *testing.T) {
240240
if assert.NoError(t, err) {
241241
assert.NotNil(t, response)
242242
assert.Equal(t, intgGUID, response.Data.Guid)
243-
assert.Contains(t, response.Data.Filter.EventCategories, "Compliance", "SystemCall")
243+
assert.Contains(t, response.Data.Filter.AlertSubCategories, "Compliance", "SystemCall")
244244
assert.Contains(t, response.Data.Filter.AlertCategories, "Policy", "Anomaly")
245245
assert.Contains(t, response.Data.Filter.AlertSources, "AWS", "Agent", "K8s")
246246
assert.Contains(t, response.Data.Filter.ResourceGroups, "TECHALLY_100000000000AAAAAAAAAAAAAAAAAAAB")
@@ -307,10 +307,10 @@ func singleMockAlertRule(id string) string {
307307
"severity": [
308308
2
309309
],
310-
"eventCategory": [
310+
"subCategory": [
311311
"Compliance",
312312
"SystemCall"
313-
],
313+
],
314314
"category": [
315315
"Policy",
316316
"Anomaly"
@@ -320,7 +320,7 @@ func singleMockAlertRule(id string) string {
320320
"Agent",
321321
"K8s"
322322
]
323-
},
323+
},
324324
"mcGuid": %q,
325325
"intgGuidList": [
326326
"TECHALLY_000000000000AAAAAAAAAAAAAAAAAAAA"

cli/cmd/alert_rules.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var (
3838
Use: "alert-rule",
3939
Aliases: []string{"alert-rules", "ar"},
4040
Short: "Manage alert rules",
41-
Long: `Manage alert rules to route events to the appropriate people or tools.
41+
Long: `Manage alert rules to route events to the appropriate people or tools.
4242
4343
An alert rule has three parts:
4444
@@ -176,7 +176,7 @@ func buildAlertRuleDetailsTable(rule api.AlertRule) string {
176176
updatedTime = time.Unix(nano/1000, 0).Format(time.RFC3339)
177177
}
178178
details = append(details, []string{"SEVERITIES", strings.Join(severities, ", ")})
179-
details = append(details, []string{"EVENT CATEGORIES", strings.Join(rule.Filter.EventCategories, ", ")})
179+
details = append(details, []string{"EVENT CATEGORIES", strings.Join(rule.Filter.AlertSubCategories, ", ")})
180180
details = append(details, []string{"DESCRIPTION", rule.Filter.Description})
181181
details = append(details, []string{"UPDATED BY", rule.Filter.CreatedOrUpdatedBy})
182182
details = append(details, []string{"LAST UPDATED", updatedTime})
@@ -298,12 +298,12 @@ func promptCreateAlertRule() (api.AlertRuleResponse, error) {
298298
alertRule := api.NewAlertRule(
299299
answers.Name,
300300
api.AlertRuleConfig{
301-
Description: answers.Description,
302-
Channels: channels,
303-
Severities: api.NewAlertRuleSeverities(answers.Severities),
304-
EventCategories: answers.EventCategories,
305-
AlertCategories: alertCategories,
306-
ResourceGroups: groups,
301+
Description: answers.Description,
302+
Channels: channels,
303+
Severities: api.NewAlertRuleSeverities(answers.Severities),
304+
AlertSubCategories: answers.EventCategories,
305+
AlertCategories: alertCategories,
306+
ResourceGroups: groups,
307307
})
308308

309309
cli.StartProgress(" Creating alert rule...")

integration/alert_rules_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ func createAlertRuleWithSlackAlertChannel() (alertRule api.AlertRuleResponse, er
108108
}
109109

110110
rule := api.NewAlertRule("Alert Rule Test", api.AlertRuleConfig{
111-
Channels: []string{slackChannel},
112-
Description: "This is a test Alert Rule",
113-
Severities: api.NewAlertRuleSeverities([]string{"Critical", "High"}),
114-
EventCategories: []string{"Compliance"},
115-
AlertCategories: []string{},
116-
ResourceGroups: []string{},
111+
Channels: []string{slackChannel},
112+
Description: "This is a test Alert Rule",
113+
Severities: api.NewAlertRuleSeverities([]string{"Critical", "High"}),
114+
AlertSubCategories: []string{"Compliance"},
115+
AlertCategories: []string{},
116+
ResourceGroups: []string{},
117117
})
118118

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

integration/test_resources/help/alert-rule

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Manage alert rules to route events to the appropriate people or tools.
1+
Manage alert rules to route events to the appropriate people or tools.
22

33
An alert rule has three parts:
44

0 commit comments

Comments
 (0)