|
| 1 | +// Create a new vulnerability-based notification rule with sast and secret rule types returns "Successfully created the |
| 2 | +// notification rule." response |
| 3 | + |
| 4 | +package main |
| 5 | + |
| 6 | +import ( |
| 7 | + "context" |
| 8 | + "encoding/json" |
| 9 | + "fmt" |
| 10 | + "os" |
| 11 | + |
| 12 | + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" |
| 13 | + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" |
| 14 | +) |
| 15 | + |
| 16 | +func main() { |
| 17 | + body := datadogV2.CreateNotificationRuleParameters{ |
| 18 | + Data: &datadogV2.CreateNotificationRuleParametersData{ |
| 19 | + Attributes: datadogV2.CreateNotificationRuleParametersDataAttributes{ |
| 20 | + Enabled: datadog.PtrBool(true), |
| 21 | + Name: "Example-Security-Monitoring", |
| 22 | + Selectors: datadogV2.Selectors{ |
| 23 | + Query: datadog.PtrString("(source:production_service OR env:prod)"), |
| 24 | + RuleTypes: []datadogV2.RuleTypesItems{ |
| 25 | + datadogV2.RULETYPESITEMS_SAST_VULNERABILITY, |
| 26 | + datadogV2.RULETYPESITEMS_SECRET_VULNERABILITY, |
| 27 | + }, |
| 28 | + Severities: []datadogV2.RuleSeverity{ |
| 29 | + datadogV2.RULESEVERITY_CRITICAL, |
| 30 | + }, |
| 31 | + TriggerSource: datadogV2.TRIGGERSOURCE_SECURITY_FINDINGS, |
| 32 | + }, |
| 33 | + Targets: []string{ |
| 34 | + "@john.doe@email.com", |
| 35 | + }, |
| 36 | + TimeAggregation: datadog.PtrInt64(86400), |
| 37 | + }, |
| 38 | + Type: datadogV2.NOTIFICATIONRULESTYPE_NOTIFICATION_RULES, |
| 39 | + }, |
| 40 | + } |
| 41 | + ctx := datadog.NewDefaultContext(context.Background()) |
| 42 | + configuration := datadog.NewConfiguration() |
| 43 | + apiClient := datadog.NewAPIClient(configuration) |
| 44 | + api := datadogV2.NewSecurityMonitoringApi(apiClient) |
| 45 | + resp, r, err := api.CreateVulnerabilityNotificationRule(ctx, body) |
| 46 | + |
| 47 | + if err != nil { |
| 48 | + fmt.Fprintf(os.Stderr, "Error when calling `SecurityMonitoringApi.CreateVulnerabilityNotificationRule`: %v\n", err) |
| 49 | + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) |
| 50 | + } |
| 51 | + |
| 52 | + responseContent, _ := json.MarshalIndent(resp, "", " ") |
| 53 | + fmt.Fprintf(os.Stdout, "Response from `SecurityMonitoringApi.CreateVulnerabilityNotificationRule`:\n%s\n", responseContent) |
| 54 | +} |
0 commit comments