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

Commit

Permalink
Merge pull request #189 from suzuki-shunsuke/fix/issue-187
Browse files Browse the repository at this point in the history
Fix extractor: make date_format optional and fix panic
  • Loading branch information
suzuki-shunsuke committed Oct 26, 2019
2 parents 7ae0735 + cbadbbb commit f3f37b2
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 20 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
22 changes: 11 additions & 11 deletions terraform/example/v0.12/alarm_callback.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ resource "graylog_alarm_callback" "http" {
}

resource "graylog_alarm_callback" "email" {
type = "org.graylog2.alarmcallbacks.EmailAlarmCallback"
type = "org.graylog2.alarmcallbacks.EmailAlarmCallback"
stream_id = graylog_stream.test.id
title = "test"
title = "test"
email_configuration {
sender = "graylog@example.org"
sender = "graylog@example.org"
subject = "Graylog alert for stream: $${stream.title}: $${check_result.resultDescription}"
user_receivers = [
"username"
Expand All @@ -26,16 +26,16 @@ resource "graylog_alarm_callback" "email" {
}

resource "graylog_alarm_callback" "slack" {
type = "org.graylog2.plugins.slack.callback.SlackAlarmCallback"
type = "org.graylog2.plugins.slack.callback.SlackAlarmCallback"
stream_id = graylog_stream.test.id
title = "test"
title = "test"
slack_configuration {
graylog2_url = "https://graylog.example.com"
color = "#FF0000"
webhook_url = "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
user_name = "Graylog"
backlog_items = 5
channel = "#general"
graylog2_url = "https://graylog.example.com"
color = "#FF0000"
webhook_url = "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
user_name = "Graylog"
backlog_items = 5
channel = "#general"
custom_message = "$${alert_condition.title}\\n\\n$${foreach backlog message}\\n<https://graylog.example.com/streams/$${stream.id}/search?rangetype=absolute&from=$${message.timestamp}&to=$${message.timestamp} | link> $${message.message}\\n$${end}"
}
}
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}) "
}
}
15 changes: 15 additions & 0 deletions terraform/example/v0.12/input.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,18 @@ resource "graylog_input_static_fields" "gelf_udp" {
foo = "bar"
}
}

resource "graylog_input" "json_path" {
title = "json path"
type = "org.graylog2.inputs.misc.jsonpath.JsonPathInput"
global = "true"

attributes {
interval = 30
path = "$.userId"
throttling_allowed = true
target_url = "http://jsonplaceholder.typicode.com/posts/1"
source = "id"
timeunit = "SECONDS"
}
}
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 f3f37b2

Please sign in to comment.