Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
fix: make date_format optional and fix panic
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki-shunsuke committed Oct 26, 2019
1 parent 7ae0735 commit a014f6d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion terraform/docs/extractor.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ condition_type | string |
extractor_config | object{} |
converters[].type | string |
converters[].config | object{} |
converters[].config.date_format | string | "" |

### Common Optional Argument

Expand All @@ -37,6 +36,7 @@ converters | list | [] |
target_field | string | "" |
condition_value | string | "" |
order | int | 0 |
converters[].config.date_format | string | "" |
converters[].config.time_zone | string | "" |
converters[].config.locale | string | "" |

Expand Down
21 changes: 21 additions & 0 deletions terraform/example/v0.12/extractor.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,24 @@ resource "graylog_extractor" "test_regex" {
}
}
}

resource "graylog_extractor" "http_response_code" {
input_id = graylog_input.gelf_udp.id
title = "Apache http_response_code"
type = "regex"
cursor_strategy = "copy"
source_field = "message"
target_field = "http_response_code"
condition_type = "regex"
condition_value = "[1-5]\\d{2}"
order = 0

converters {
type = "numeric"
config {}
}

regex_type_extractor_config {
regex_value = "HTTP/1.[0-1]\" (\\d{3}) "
}
}
20 changes: 12 additions & 8 deletions terraform/graylog/resource_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func resourceExtractor() *schema.Resource {
Schema: map[string]*schema.Schema{
"date_format": {
Type: schema.TypeString,
Required: true,
Optional: true,
},
"time_zone": {
Type: schema.TypeString,
Expand Down Expand Up @@ -236,14 +236,18 @@ func newExtractor(d *schema.ResourceData) (*graylog.Extractor, string, error) {
converters := make([]graylog.ExtractorConverter, len(list))
for i, a := range list {
b := a.(map[string]interface{})
cfg := b["config"].([]interface{})[0].(map[string]interface{})
c := b["config"].([]interface{})
cfg := &graylog.ExtractorConverterConfig{}
if len(c) > 0 {
if d, ok := c[0].(map[string]interface{}); ok {
cfg.DateFormat = d["date_format"].(string)
cfg.TimeZone = d["time_zone"].(string)
cfg.Locale = d["locale"].(string)
}
}
converters[i] = graylog.ExtractorConverter{
Type: b["type"].(string),
Config: &graylog.ExtractorConverterConfig{
DateFormat: cfg["date_format"].(string),
TimeZone: cfg["time_zone"].(string),
Locale: cfg["locale"].(string),
},
Type: b["type"].(string),
Config: cfg,
}
}
return &graylog.Extractor{
Expand Down

0 comments on commit a014f6d

Please sign in to comment.