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 #269 from suzuki-shunsuke/docs/refactor-example
Browse files Browse the repository at this point in the history
docs: refactor example using jsonencode
  • Loading branch information
suzuki-shunsuke committed May 8, 2020
2 parents 7e6ab9a + 346e7c4 commit 7479ad3
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 182 deletions.
43 changes: 21 additions & 22 deletions examples/v0.12/dashboard.tf
Expand Up @@ -66,26 +66,25 @@ resource "graylog_dashboard_widget_positions" "test" {
}

resource "graylog_dashboard_widget" "stacked_chart" {
description = "stacked chart"
dashboard_id = graylog_dashboard.test.id
type = "STACKED_CHART"
cache_time = 10
json_configuration = <<EOF
{
"interval": "hour",
"timerange": {
"type": "relative",
"range": 86400
},
"renderer": "bar",
"interpolation": "linear",
"series": [
{
"query": "",
"field": "AccessMask",
"statistical_function": "count"
}
]
}
EOF
description = "stacked chart"
dashboard_id = graylog_dashboard.test.id
type = "STACKED_CHART"
cache_time = 10

json_configuration = jsonencode({
interval = "hour"
timerange = {
type = "relative"
range = 86400
},
renderer = "bar"
interpolation = "linear"
series = [
{
query = ""
field = "AccessMask"
statistical_function = "count"
}
]
})
}
117 changes: 57 additions & 60 deletions examples/v0.12/event_definition.tf
Expand Up @@ -3,34 +3,32 @@ resource "graylog_event_definition" "test" {
description = ""
priority = 1
alert = true
config = <<EOF
{
"type": "aggregation-v1",
"query": "test",
"streams": [
"${graylog_stream.test.id}"
],
"search_within_ms": 60000,
"execute_every_ms": 60000,
"group_by": [],
"series": [],
"conditions": null
}
EOF
field_spec = <<EOF
{
"test": {
"data_type": "string",
"providers": [
{
"type": "template-v1",
"template": "test",
"require_values": false
}
]
}
}
EOF

config = jsonencode({
type = "aggregation-v1"
query = "test"
streams = [
"${graylog_stream.test.id}"
],
search_within_ms = 60000
execute_every_ms = 60000
group_by = []
series = []
conditions = null
})

field_spec = jsonencode({
test = {
data_type = "string"
providers = [
{
type = "template-v1"
template = "test"
require_values = false
}
]
}
})

key_spec = ["test"]

Expand All @@ -51,40 +49,39 @@ resource "random_uuid" "event_definition_test2_series0" {}
resource "graylog_event_definition" "test2" {
title = "new-event-definition 2"
priority = 2
config = <<EOF
{
"type": "aggregation-v1",
"query": "test",
"streams": [
"${graylog_stream.test.id}"
],
"search_within_ms": 60000,
"execute_every_ms": 60000,
"group_by": [
"alert"
],
"series": [
{
"id": "${random_uuid.event_definition_test2_series0.result}",
"function": "avg",
"field": "alert"
}
],
"conditions": {
"expression": {
"expr": ">",
"left": {
"expr": "number-ref",
"ref": "${random_uuid.event_definition_test2_series0.result}"
},
"right": {
"expr": "number",
"value": 0

config = jsonencode({
type = "aggregation-v1"
query = "test"
streams = [
"${graylog_stream.test.id}"
],
search_within_ms = 60000
execute_every_ms = 60000
group_by = [
"alert"
]
series = [
{
id = "${random_uuid.event_definition_test2_series0.result}"
function = "avg"
field = "alert"
}
]
conditions = {
expression = {
expr = ">"
left = {
expr = "number-ref"
ref = "${random_uuid.event_definition_test2_series0.result}"
}
right = {
expr = "number"
value = 0
}
}
}
}
}
EOF
})

notification_settings {
grace_period_ms = 0
Expand Down
116 changes: 53 additions & 63 deletions examples/v0.12/event_notification.tf
Expand Up @@ -2,91 +2,81 @@ resource "graylog_event_notification" "legacy-http-alarm-callback" {
title = "legacy-http-alarm-callback"
description = "Migrated legacy alarm callback"

config = <<EOF
{
"type": "legacy-alarm-callback-notification-v1",
"callback_type": "org.graylog2.alarmcallbacks.HTTPAlarmCallback",
"configuration": {
"url": "https://example.com"
}
}
EOF
config = jsonencode({
type = "legacy-alarm-callback-notification-v1"
callback_type = "org.graylog2.alarmcallbacks.HTTPAlarmCallback"
configuration = {
url = "https://example.com"
}
})
}

resource "graylog_event_notification" "legacy-email-alarm-callback" {
title = "legacy-email-alarm-callback"
description = "Migrated legacy alarm callback"

config = <<EOF
{
"type": "legacy-alarm-callback-notification-v1",
"callback_type": "org.graylog2.alarmcallbacks.EmailAlarmCallback",
"configuration": {
"sender": "graylog@example.org",
"subject": "Graylog alert for stream ",
"user_receivers": [
"username"
],
"body": "hello world",
"email_receivers": [
"graylog@example.com"
]
}
}
EOF
config = jsonencode({
type = "legacy-alarm-callback-notification-v1"
callback_type = "org.graylog2.alarmcallbacks.EmailAlarmCallback"
configuration = {
sender = "graylog@example.org"
subject = "Graylog alert for stream "
user_receivers = [
"username"
]
body = "hello world"
email_receivers = [
"graylog@example.com"
]
}
})
}

resource "graylog_event_notification" "legacy-slack-alarm-callback" {
title = "legacy-slack-alarm-callback"
description = "Migrated legacy alarm callback"

config = <<EOF
{
"type": "legacy-alarm-callback-notification-v1",
"callback_type": "org.graylog2.plugins.slack.callback.SlackAlarmCallback",
"configuration": {
"graylog2_url": "https://graylog.example.com",
"notify_channel": false,
"link_names": true,
"custom_message": "hello world",
"webhook_url": "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX",
"color": "#FF0000",
"backlog_items": 5,
"user_name": "Graylog",
"channel": "#general"
}
}
EOF
config = jsonencode({
type = "legacy-alarm-callback-notification-v1"
callback_type = "org.graylog2.plugins.slack.callback.SlackAlarmCallback"
configuration = {
graylog2_url = "https://graylog.example.com"
notify_channel = false
link_names = true
custom_message = "hello world"
webhook_url = "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
color = "#FF0000"
backlog_items = 5
user_name = "Graylog"
channel = "#general"
}
})
}

resource "graylog_event_notification" "http" {
title = "http"
description = "http notification"

config = <<EOF
{
"type": "http-notification-v1",
"url": "http://example.com"
}
EOF
config = jsonencode({
type = "http-notification-v1"
url = "http://example.com"
})
}

resource "graylog_event_notification" "email" {
title = "email"
description = "email notification"

config = <<EOF
{
"type": "email-notification-v1",
"sender": "graylog@example.com",
"subject": "Graylog event notification",
"body_template": "hello",
"email_recipients": [
"graylog@example.com"
],
"user_recipients": [
"admin"
]
}
EOF
config = jsonencode({
type = "email-notification-v1"
sender = "graylog@example.com"
subject = "Graylog event notification"
body_template = "hello"
email_recipients = [
"graylog@example.com"
]
user_recipients = [
"admin"
]
})
}

0 comments on commit 7479ad3

Please sign in to comment.