Skip to content

Commit 8f51601

Browse files
authored
Merge branch 'master' into INVS-175_cse_entity_group_configuration
2 parents efb2787 + a139ca1 commit 8f51601

12 files changed

+443
-38
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
/sumologic/*_source_test.go @maimaisie @vsinghal13
1313
/sumologic/*_ingest_budget* @maimaisie @vsinghal13
1414
/sumologic/*_collector* @maimaisie @vsinghal13
15+
/sumologic/*_cse* @josh-williams @pmontiel-sumo
1516
/website/docs/r/collector* @maimaisie @vsinghal13
1617
/website/docs/r/ingest_* @maimaisie @vsinghal13
1718
/website/docs/r/*_source* @maimaisie @vsinghal13

CHANGELOG.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
1-
## 2.16.0 (Unreleased)
1+
## 2.17.0 (Unreleased)
22
FEATURES:
33
* **New Resource:** sumologic_cse_entity_entity_group_configuration (GH-376)
44
* **New Resource:** sumologic_cse_inventory_entity_group_configuration (GH-376)
55

6+
## 2.16.2 (June 12, 2022)
7+
8+
BUG FIXES:
9+
* Monitor Folder provider now handles more error codes: "api_not_enabled", in addition to: "not_implemented_yet" (GH-389)
10+
11+
## 2.16.1 (June 6, 2022)
12+
13+
BUG FIXES:
14+
* Allow locator field in DefaultDateFormat to be empty (GH-384)
15+
16+
## 2.16.0 (May 20, 2022)
17+
18+
FEATURES:
19+
* Add new optional `obj_permission` set to resource/sumologic_monitor_folder for Fine Grain Permission (FGP) support (GH-373)
20+
21+
BUG FIXES:
22+
* Fix bug in cse match list items creation (was timing out due to StateChangeConf on an infinite loop) (GH-377)
23+
624
## 2.15.0 (May 13, 2022)
725

826
FEATURES:

sumologic/resource_sumologic_monitors_library_folder.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,14 @@ func resourceSumologicMonitorsLibraryFolderRead(d *schema.ResourceData, meta int
159159
return nil
160160
}
161161

162-
fgpResponse, fgpErr := c.GetCmfFgp(fgpTargetType, folder.ID)
163-
if fgpErr != nil {
162+
fgpResponse, fgpGetErr := c.GetCmfFgp(fgpTargetType, folder.ID)
163+
if fgpGetErr != nil {
164164
// if FGP endpoint is not enabled (not implemented), we should suppress this error
165-
if !HasErrorCode(fgpErr.Error(), "not_implemented_yet") {
166-
return fgpErr
165+
suppressedErrorCode := HasErrorCode(fgpGetErr.Error(), []string{"not_implemented_yet", "api_not_enabled"})
166+
if suppressedErrorCode == "" {
167+
return fgpGetErr
167168
} else {
168-
log.Printf("[WARN] FGP Feature has not been enabled yet. Suppressing \"not_implemented_yet\" error under GetCmfFgp operation.")
169+
log.Printf("[WARN] FGP Feature has not been enabled yet. Suppressing \"%s\" error under GetCmfFgp operation.", suppressedErrorCode)
169170
}
170171
} else {
171172
CmfFgpPermStmtsSetToResource(d, fgpResponse.PermissionStatements)
@@ -203,15 +204,16 @@ func resourceSumologicMonitorsLibraryFolderUpdate(d *schema.ResourceData, meta i
203204
return convErr
204205
}
205206

206-
// reading FGP from Backend to reconcille
207+
// reading FGP from Backend to reconcile
207208
fgpGetResponse, fgpGetErr := c.GetCmfFgp(fgpTargetType, monitorFolder.ID)
208209
if fgpGetErr != nil {
209210
// if FGP endpoint is not enabled (not implemented) and FGP feature is not used,
210211
// we should suppress this error
211-
if !HasErrorCode(fgpGetErr.Error(), "not_implemented_yet") && len(permStmts) == 0 {
212+
suppressedErrorCode := HasErrorCode(fgpGetErr.Error(), []string{"not_implemented_yet", "api_not_enabled"})
213+
if suppressedErrorCode == "" && len(permStmts) == 0 {
212214
return fgpGetErr
213215
} else {
214-
log.Printf("[WARN] FGP Feature has not been enabled yet. Suppressing \"not_implemented_yet\" error under GetCmfFgp operation.")
216+
log.Printf("[WARN] FGP Feature has not been enabled yet. Suppressing \"%s\" error under GetCmfFgp operation.", suppressedErrorCode)
215217
}
216218
}
217219

sumologic/resource_sumologic_slo.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ func resourceSumologicSLO() *schema.Resource {
211211
Type: schema.TypeString,
212212
Required: true,
213213
ValidateFunc: validation.StringInSlice([]string{
214+
"Week", "Month", "Quarter",
214215
"1d", "2d", "3d", "4d", "5d", "6d", "7d", "8d", "9d", "10d", "11d", "12d", "13d", "14d",
215216
}, false),
216217
},
@@ -519,15 +520,25 @@ func getSLOCompliance(d *schema.ResourceData) *SLOCompliance {
519520
complianceType := complianceDict["compliance_type"].(string)
520521

521522
startFrom := ""
522-
if complianceType == "Calendar" && complianceDict["start_from"] != nil {
523-
startFrom = complianceDict["start_from"].(string)
523+
windowType := ""
524+
size := complianceDict["size"].(string)
525+
526+
if complianceType == "Calendar" {
527+
// field windowType needs to be specified instead of `size` for calendar compliance
528+
windowType = size
529+
size = ""
530+
531+
if complianceDict["start_from"] != nil {
532+
startFrom = complianceDict["start_from"].(string)
533+
}
524534
}
525535

526536
return &SLOCompliance{
527537
ComplianceType: complianceType,
528538
Target: complianceDict["target"].(float64),
529539
Timezone: complianceDict["timezone"].(string),
530-
Size: complianceDict["size"].(string),
540+
Size: size,
541+
WindowType: windowType,
531542
StartFrom: startFrom,
532543
}
533544
}

sumologic/sumologic_client.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ func (s *Client) Put(urlPath string, payload interface{}) ([]byte, error) {
235235
}
236236

237237
func (s *Client) Get(urlPath string) ([]byte, string, error) {
238+
return s.GetWithErrOpt(urlPath, false)
239+
}
240+
241+
func (s *Client) GetWithErrOpt(urlPath string, return404Err bool) ([]byte, string, error) {
238242
relativeURL, _ := url.Parse(urlPath)
239243
sumoURL := s.BaseURL.ResolveReference(relativeURL)
240244

@@ -260,7 +264,11 @@ func (s *Client) Get(urlPath string) ([]byte, string, error) {
260264
}
261265

262266
if resp.StatusCode == 404 {
263-
return nil, "", nil
267+
if return404Err {
268+
return nil, "", errors.New(string(d))
269+
} else {
270+
return nil, "", nil
271+
}
264272
} else if resp.StatusCode >= 400 {
265273
return nil, "", errors.New(string(d))
266274
}
@@ -341,19 +349,21 @@ func NewClient(accessID, accessKey, authJwt, environment, base_url string, admin
341349
return &client, nil
342350
}
343351

344-
func HasErrorCode(errorJsonStr string, errorCode string) bool {
352+
func HasErrorCode(errorJsonStr string, errorCodeChoices []string) string {
345353
var apiError ApiError
346354
jsonErr := json.Unmarshal([]byte(errorJsonStr), &apiError)
347355
if jsonErr != nil {
348356
// when fail to unmarshal JSON, we should consider the errorCode is not found
349-
return false
357+
return ""
350358
}
351359
for i := range apiError.Errors {
352-
if apiError.Errors[i].Code == errorCode {
353-
return true
360+
for j := range errorCodeChoices {
361+
if apiError.Errors[i].Code == errorCodeChoices[j] {
362+
return errorCodeChoices[j]
363+
}
354364
}
355365
}
356-
return false
366+
return ""
357367
}
358368

359369
type Error struct {
@@ -362,7 +372,9 @@ type Error struct {
362372
Detail string `json:"detail"`
363373
}
364374

365-
// e.g. {"id":"8UQOI-82VTR-YBQ8G","errors":[{"code":"not_implemented_yet","message":"Not implemented yet"}]}
375+
// e.g.:
376+
// {"id":"8UQOI-82VTR-YBQ8G","errors":[{"code":"not_implemented_yet","message":"Not implemented yet"}]}
377+
// {"id":"RO4X1-BZW7P-Q8KJF","errors":[{"code":"api_not_enabled","message":"This API is not enabled for your organization."}]}
366378
type ApiError struct {
367379
Id string `json:"id"`
368380
Errors []Error `json:"errors"`

sumologic/sumologic_cmffgp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func (s *Client) GetCmfFgp(targetType string, targetId string) (*CmfFgpResponse,
1010

1111
// e.g. "v1/monitors/0000000000000003/permissions"
1212
url := fmt.Sprintf("v1/%s/%s/permissions", targetType, targetId)
13-
data, _, err := s.Get(url)
13+
data, _, err := s.GetWithErrOpt(url, true)
1414
if err != nil {
1515
return nil, err
1616
}

sumologic/sumologic_cse_match_list_item.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ func (s *Client) GetCSEMatchListItem(id string) (*CSEMatchListItemGet, error) {
2525
}
2626

2727
func (s *Client) GetCSEMatchListItemsInMatchList(MatchListId string) (*CSEMatchListItemsInMatchListGet, error) {
28-
29-
data, _, err := s.Get(fmt.Sprintf("sec/v1/match-list-items?listIds[%s]", MatchListId))
28+
data, _, err := s.Get(fmt.Sprintf("sec/v1/match-list-items?listIds=%s", MatchListId))
3029
if err != nil {
3130
return nil, err
3231
}

sumologic/sumologic_sources.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type Source struct {
3434

3535
type DefaultDateFormat struct {
3636
Format string `json:"format"`
37-
Locator string `json:"locator"`
37+
Locator string `json:"locator,omitempty"`
3838
}
3939

4040
type Filter struct {
@@ -74,7 +74,7 @@ func resourceSumologicSource() *schema.Resource {
7474
"timezone": {
7575
Type: schema.TypeString,
7676
Optional: true,
77-
Default: "Etc/UTC",
77+
Default: "",
7878
},
7979
"automatic_date_parsing": {
8080
Type: schema.TypeBool,

website/docs/index.html.markdown

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,48 @@ The following properties are common to ALL sources and can be used to configure
124124
- `use_autoline_matching` - (Optional) Type true to enable if you'd like message boundaries to be inferred automatically; type false to prevent message boundaries from being automatically inferred (equivalent to the Infer Boundaries option in the UI). The default setting is true.
125125
- `manual_prefix_regexp` - (Optional) When using useAutolineMatching=false, type a regular expression that matches the first line of the message to manually create the boundary. Note that any special characters in the regex, such as backslashes or double quotes, must be escaped.
126126
- `force_timezone` - (Optional) Type true to force the source to use a specific time zone, otherwise type false to use the time zone found in the logs. The default setting is false.
127-
- `default_date_formats` - (Optional) Define formats for the dates present in your log messages. You can specify a locator regex to identify where timestamps appear in log lines.
128-
- `filters` - (Optional) If you'd like to add a filter to the source, type the name of the filter (Exclude, Include, Mask, Hash, or Forward.
127+
- `default_date_formats` - (Optional) Define the format for the timestamps present in your log messages. You can specify a locator regex to identify where timestamps appear in log lines. Requires 'automatic_date_parsing' set to True.
128+
+ `format` - (Required) The timestamp format supplied as a Java SimpleDateFormat, or "epoch" if the timestamp is in epoch format.
129+
+ `locator` - (Optional) Regular expression to locate the timestamp within the messages.
130+
131+
Usage:
132+
```hcl
133+
default_date_formats {
134+
format = "MM-dd-yyyy HH:mm:ss"
135+
locator = "timestamp:(.*)\\s"
136+
}
137+
```
138+
- `filters` - (Optional) If you'd like to add a filter to the source.
139+
+ `filter_type` - (Required) The type of filter to apply. (Exclude, Include, Mask, or Hash)
140+
+ `name` - (Required) The Name for the filter.
141+
+ `regexp` - (Required) Regular expression to match within the messages. When used with Incude/Exclude the expression must match the entire message. When used with Mask/Hash rules the expression must contain an unnamed capture group to hash/mask.
142+
+ `mask` - (Optional) When applying a Mask rule, replaces the detected expression with this string.
143+
144+
Usage:
145+
```hcl
146+
filters {
147+
filter_type = "Include"
148+
name = "Sample Include"
149+
regexp = ".*\\d{16}.*"
150+
}
151+
filters {
152+
filter_type = "Mask"
153+
name = "Sample Mask"
154+
regexp = "(\\d{16})"
155+
mask = "MaskedID"
156+
}
157+
```
129158
- `cutoff_timestamp` - (Optional) Only collect data more recent than this timestamp, specified as milliseconds since epoch (13 digit).
130159
- `cutoff_relative_time` - (Optional) Can be specified instead of cutoffTimestamp to provide a relative offset with respect to the current time. Example: use -1h, -1d, or -1w to collect data that's less than one hour, one day, or one week old, respectively.
131160
- `fields` - (Optional) Map containing key/value pairs.
132-
161+
162+
Usage:
163+
```hcl
164+
fields = {
165+
environment = "production"
166+
service = "apache"
167+
}
168+
```
133169
## Configuring SNS Subscription
134170
This is supported in the following resources.
135171
- `sumologic_cloudfront_source`

0 commit comments

Comments
 (0)