-
Notifications
You must be signed in to change notification settings - Fork 25
/
main.go
57 lines (47 loc) · 1.33 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"fmt"
"log"
"os"
"github.com/lacework/go-sdk/api"
)
func main() {
lacework, err := api.NewClient(os.Getenv("LW_ACCOUNT"),
api.WithSubaccount(os.Getenv("LW_SUBACCOUNT")),
api.WithApiKeys(os.Getenv("LW_API_KEY"), os.Getenv("LW_API_SECRET")),
)
if err != nil {
log.Fatal(err)
}
res, err := lacework.V2.AlertRules.List()
if err != nil {
log.Fatal(err)
}
for _, rule := range res.Data {
support := "Unsupported"
switch rule.Type {
case api.AlertRuleEventType:
support = "Supported"
}
// Output: GUID:RULE_TYPE:[Supported|Unsupported]
fmt.Printf("%s:%s:%s\n", rule.Guid, rule.Type, support)
}
rule := api.AlertRuleConfig{
Channels: []string{"TECHALLY_000000000000AAAAAAAAAAAAAAAAAAAA"},
Description: "This is a test alert rule",
Severities: api.AlertRuleSeverities{api.AlertRuleSeverityHigh},
ResourceGroups: []string{"TECHALLY_000000000000AAAAAAAAAAAAAAAAAAAA"},
AlertSubCategories: []string{"Compliance"},
AlertCategories: []string{"Policy"},
AlertSources: []string{"AWS"},
}
myAlertRule := api.NewAlertRule("MyTestAlertRule",
rule,
)
response, err := lacework.V2.AlertRules.Create(myAlertRule)
if err != nil {
log.Fatal(err)
}
// Output: Alert Rule created: GUID
fmt.Printf("Alert Rule Group created: %s", response.Data.Guid)
}