Skip to content

Commit e655e4e

Browse files
authored
fix: Solve Monitor alert import and vuln exception removal (#83)
* fix: Solve Monitor alert import and vuln exception removal * chore: Remove unneeded depends * build: Bump required Go version to 1.14
1 parent 5047cdc commit e655e4e

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

.github/workflows/ci-pull-request.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ jobs:
4040
- name: Checkout code
4141
uses: actions/checkout@v2
4242

43+
- name: Set up Go
44+
uses: actions/setup-go@v2
45+
with:
46+
go-version: ^1.14
47+
4348
- name: Build project
4449
run: GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -o terraform-provider-sysdig
4550

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ Terraform Provider for Sysdig
1111
Requirements
1212
------------
1313

14-
- [Terraform](https://www.terraform.io/downloads.html) 0.12.x
15-
- [Go](https://golang.org/doc/install) 1.13 (to build the provider plugin)
14+
- [Terraform](https://www.terraform.io/downloads.html) > 0.12.x
15+
- [Go](https://golang.org/doc/install) > 1.14 (to build the provider plugin)
1616

1717
Building The Provider
1818
---------------------

sysdig/internal/client/secure/vulnerability_exception.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ func (client *sysdigSecureClient) DeleteVulnerabilityException(ctx context.Conte
109109
}
110110
defer response.Body.Close()
111111

112-
if response.StatusCode != http.StatusNoContent {
112+
// We will ignore the 404 error, because the exception may have been removed if the exception list has been
113+
// removed as well. This should not affect the user, because removing a non existing exception has no effect.
114+
if response.StatusCode != http.StatusNoContent && response.StatusCode != http.StatusNotFound {
113115
return errors.New(response.Status)
114116
}
115117

sysdig/resource_sysdig_monitor_alert_event.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package sysdig
33
import (
44
"context"
55
"fmt"
6+
"regexp"
67
"strconv"
78
"time"
89

@@ -169,15 +170,24 @@ func eventAlertFromResourceData(data *schema.ResourceData) (alert *monitor.Alert
169170
return
170171
}
171172

173+
// https://regex101.com/r/mmpz0D/1
174+
var alertConditionRegex = regexp.MustCompile(`count\(customEvent\)\s?(?P<rel>[^\w])\s?(?P<count>\d+)`)
175+
172176
func eventAlertToResourceData(alert *monitor.Alert, data *schema.ResourceData) (err error) {
173177
err = alertToResourceData(alert, data)
174178
if err != nil {
175179
return
176180
}
177181

178-
var event_rel string
179-
var event_count int
180-
_, err = fmt.Sscanf(alert.Condition, "count(customEvent) %s %d", &event_rel, &event_count)
182+
relIndex := alertConditionRegex.SubexpIndex("rel")
183+
countIndex := alertConditionRegex.SubexpIndex("count")
184+
matches := alertConditionRegex.FindStringSubmatch(alert.Condition)
185+
if matches == nil {
186+
return fmt.Errorf("alert condition %s does not match expected expression %s", alert.Condition, alertConditionRegex.String())
187+
}
188+
189+
event_rel := matches[relIndex]
190+
event_count, err := strconv.Atoi(matches[countIndex])
181191
if err != nil {
182192
return
183193
}

0 commit comments

Comments
 (0)