2016-02-01 12:39:02 +01:00
|
|
|
package datadog
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
2017-02-20 13:48:32 +01:00
|
|
|
"gopkg.in/zorkian/go-datadog-api.v2"
|
2016-02-01 12:39:02 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccDatadogMonitor_Basic(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckDatadogMonitorDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-02-13 15:31:00 +01:00
|
|
|
{
|
2016-02-01 12:39:02 +01:00
|
|
|
Config: testAccCheckDatadogMonitorConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckDatadogMonitorExists("datadog_monitor.foo"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "name", "name for monitor foo"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "message", "some message Notify: @hipchat-channel"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "type", "metric alert"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "query", "avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo} by {host} > 2"),
|
|
|
|
resource.TestCheckResourceAttr(
|
2016-05-19 15:51:27 +02:00
|
|
|
"datadog_monitor.foo", "notify_no_data", "false"),
|
2017-02-17 16:08:31 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "new_host_delay", "600"),
|
2016-02-01 12:39:02 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "renotify_interval", "60"),
|
|
|
|
resource.TestCheckResourceAttr(
|
2016-08-22 05:55:26 +02:00
|
|
|
"datadog_monitor.foo", "thresholds.warning", "1.0"),
|
2016-02-01 12:39:02 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
2016-08-22 05:55:26 +02:00
|
|
|
"datadog_monitor.foo", "thresholds.critical", "2.0"),
|
2016-05-19 10:29:23 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "require_full_window", "true"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "locked", "false"),
|
2016-08-18 17:54:44 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2016-12-07 12:05:57 +01:00
|
|
|
"datadog_monitor.foo", "tags.0", "foo:bar"),
|
2016-08-18 17:54:44 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2016-12-07 12:05:57 +01:00
|
|
|
"datadog_monitor.foo", "tags.1", "baz"),
|
2016-02-01 12:39:02 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-12-05 10:52:59 +01:00
|
|
|
func TestAccDatadogMonitor_BasicNoTreshold(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckDatadogMonitorDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-02-13 15:31:00 +01:00
|
|
|
{
|
2016-12-05 10:52:59 +01:00
|
|
|
Config: testAccCheckDatadogMonitorConfigNoThresholds,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckDatadogMonitorExists("datadog_monitor.foo"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "name", "name for monitor foo"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "message", "some message Notify: @hipchat-channel"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "type", "metric alert"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "query", "avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo} by {host} > 2"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "notify_no_data", "false"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "renotify_interval", "60"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "require_full_window", "true"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "locked", "false"),
|
|
|
|
resource.TestCheckResourceAttr(
|
2016-12-08 11:17:42 +01:00
|
|
|
"datadog_monitor.foo", "tags.0", "foo:bar"),
|
2016-12-05 10:52:59 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
2016-12-08 11:17:42 +01:00
|
|
|
"datadog_monitor.foo", "tags.1", "bar:baz"),
|
2016-12-05 10:52:59 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-02-01 12:39:02 +01:00
|
|
|
func TestAccDatadogMonitor_Updated(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckDatadogMonitorDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-02-13 15:31:00 +01:00
|
|
|
{
|
2016-02-01 12:39:02 +01:00
|
|
|
Config: testAccCheckDatadogMonitorConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckDatadogMonitorExists("datadog_monitor.foo"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "name", "name for monitor foo"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "message", "some message Notify: @hipchat-channel"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "escalation_message", "the situation has escalated @pagerduty"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "query", "avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo} by {host} > 2"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "type", "metric alert"),
|
|
|
|
resource.TestCheckResourceAttr(
|
2016-05-19 15:51:27 +02:00
|
|
|
"datadog_monitor.foo", "notify_no_data", "false"),
|
2017-02-17 16:08:31 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "new_host_delay", "600"),
|
2016-02-01 12:39:02 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "renotify_interval", "60"),
|
|
|
|
resource.TestCheckResourceAttr(
|
2016-08-22 05:55:26 +02:00
|
|
|
"datadog_monitor.foo", "thresholds.warning", "1.0"),
|
2016-02-01 12:39:02 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
2016-08-22 05:55:26 +02:00
|
|
|
"datadog_monitor.foo", "thresholds.critical", "2.0"),
|
2016-02-01 12:39:02 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "notify_audit", "false"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "timeout_h", "60"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "include_tags", "true"),
|
2016-05-19 10:29:23 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "require_full_window", "true"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "locked", "false"),
|
2016-08-18 17:54:44 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2016-12-07 12:05:57 +01:00
|
|
|
"datadog_monitor.foo", "tags.0", "foo:bar"),
|
2016-08-18 17:54:44 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2016-12-07 12:05:57 +01:00
|
|
|
"datadog_monitor.foo", "tags.1", "baz"),
|
2016-02-01 12:39:02 +01:00
|
|
|
),
|
|
|
|
},
|
2017-02-13 15:31:00 +01:00
|
|
|
{
|
2016-02-01 12:39:02 +01:00
|
|
|
Config: testAccCheckDatadogMonitorConfigUpdated,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckDatadogMonitorExists("datadog_monitor.foo"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "name", "name for monitor bar"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "message", "a different message Notify: @hipchat-channel"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "query", "avg(last_1h):avg:aws.ec2.cpu{environment:bar,host:bar} by {host} > 3"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "escalation_message", "the situation has escalated! @pagerduty"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "type", "metric alert"),
|
|
|
|
resource.TestCheckResourceAttr(
|
2016-05-19 15:51:27 +02:00
|
|
|
"datadog_monitor.foo", "notify_no_data", "true"),
|
2017-02-17 16:08:31 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "new_host_delay", "900"),
|
2016-05-19 15:51:27 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "no_data_timeframe", "20"),
|
2016-02-01 12:39:02 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "renotify_interval", "40"),
|
|
|
|
resource.TestCheckResourceAttr(
|
2016-08-22 05:55:26 +02:00
|
|
|
"datadog_monitor.foo", "thresholds.ok", "0.0"),
|
2016-02-01 12:39:02 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
2016-08-22 05:55:26 +02:00
|
|
|
"datadog_monitor.foo", "thresholds.warning", "1.0"),
|
2016-02-01 12:39:02 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
2016-08-22 05:55:26 +02:00
|
|
|
"datadog_monitor.foo", "thresholds.critical", "3.0"),
|
2016-02-01 12:39:02 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "notify_audit", "true"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "timeout_h", "70"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "include_tags", "false"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "silenced.*", "0"),
|
2016-05-19 10:29:23 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "require_full_window", "false"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "locked", "true"),
|
2016-08-18 17:54:44 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2016-12-07 12:05:57 +01:00
|
|
|
"datadog_monitor.foo", "tags.0", "baz:qux"),
|
2016-08-18 17:54:44 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2016-12-07 12:05:57 +01:00
|
|
|
"datadog_monitor.foo", "tags.1", "quux"),
|
2016-02-01 12:39:02 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-03-22 19:47:08 +01:00
|
|
|
func TestAccDatadogMonitor_TrimWhitespace(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckDatadogMonitorDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-02-13 15:31:00 +01:00
|
|
|
{
|
2016-03-22 19:47:08 +01:00
|
|
|
Config: testAccCheckDatadogMonitorConfigWhitespace,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckDatadogMonitorExists("datadog_monitor.foo"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "name", "name for monitor foo"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "message", "some message Notify: @hipchat-channel"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "type", "metric alert"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "query", "avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo} by {host} > 2"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "notify_no_data", "false"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "renotify_interval", "60"),
|
|
|
|
resource.TestCheckResourceAttr(
|
2016-08-22 05:55:26 +02:00
|
|
|
"datadog_monitor.foo", "thresholds.ok", "0.0"),
|
2016-03-22 19:47:08 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
2016-08-22 05:55:26 +02:00
|
|
|
"datadog_monitor.foo", "thresholds.warning", "1.0"),
|
2016-03-22 19:47:08 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
2016-08-22 05:55:26 +02:00
|
|
|
"datadog_monitor.foo", "thresholds.critical", "2.0"),
|
2016-03-22 19:47:08 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-10-20 02:31:12 +02:00
|
|
|
func TestAccDatadogMonitor_Basic_float_int(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckDatadogMonitorDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-02-13 15:31:00 +01:00
|
|
|
{
|
2016-10-20 02:31:12 +02:00
|
|
|
Config: testAccCheckDatadogMonitorConfig_ints,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckDatadogMonitorExists("datadog_monitor.foo"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "thresholds.warning", "1"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "thresholds.critical", "2"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
|
2017-02-13 15:31:00 +01:00
|
|
|
{
|
2016-10-20 02:31:12 +02:00
|
|
|
Config: testAccCheckDatadogMonitorConfig_ints_mixed,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckDatadogMonitorExists("datadog_monitor.foo"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "thresholds.warning", "1.0"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"datadog_monitor.foo", "thresholds.critical", "3.0"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-02-01 12:39:02 +01:00
|
|
|
func testAccCheckDatadogMonitorDestroy(s *terraform.State) error {
|
|
|
|
client := testAccProvider.Meta().(*datadog.Client)
|
|
|
|
|
|
|
|
if err := destroyHelper(s, client); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckDatadogMonitorExists(n string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
client := testAccProvider.Meta().(*datadog.Client)
|
|
|
|
if err := existsHelper(s, client); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const testAccCheckDatadogMonitorConfig = `
|
|
|
|
resource "datadog_monitor" "foo" {
|
|
|
|
name = "name for monitor foo"
|
|
|
|
type = "metric alert"
|
|
|
|
message = "some message Notify: @hipchat-channel"
|
|
|
|
escalation_message = "the situation has escalated @pagerduty"
|
|
|
|
|
|
|
|
query = "avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo} by {host} > 2"
|
|
|
|
|
|
|
|
thresholds {
|
2016-08-22 05:55:26 +02:00
|
|
|
warning = "1.0"
|
|
|
|
critical = "2.0"
|
2016-02-01 12:39:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
renotify_interval = 60
|
|
|
|
|
|
|
|
notify_audit = false
|
|
|
|
timeout_h = 60
|
2017-02-17 16:08:31 +01:00
|
|
|
new_host_delay = 600
|
2016-02-01 12:39:02 +01:00
|
|
|
include_tags = true
|
2016-05-19 10:29:23 +02:00
|
|
|
require_full_window = true
|
|
|
|
locked = false
|
2016-12-07 12:05:57 +01:00
|
|
|
tags = ["foo:bar", "baz"]
|
2016-02-01 12:39:02 +01:00
|
|
|
}
|
|
|
|
`
|
2016-12-05 10:52:59 +01:00
|
|
|
const testAccCheckDatadogMonitorConfigNoThresholds = `
|
|
|
|
resource "datadog_monitor" "foo" {
|
|
|
|
name = "name for monitor foo"
|
|
|
|
type = "metric alert"
|
|
|
|
message = "some message Notify: @hipchat-channel"
|
|
|
|
escalation_message = "the situation has escalated @pagerduty"
|
|
|
|
|
|
|
|
query = "avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo} by {host} > 2"
|
|
|
|
|
|
|
|
notify_no_data = false
|
|
|
|
renotify_interval = 60
|
|
|
|
|
|
|
|
notify_audit = false
|
|
|
|
timeout_h = 60
|
|
|
|
include_tags = true
|
|
|
|
require_full_window = true
|
|
|
|
locked = false
|
2016-12-08 11:17:42 +01:00
|
|
|
tags = ["foo:bar", "bar:baz"]
|
2016-12-05 10:52:59 +01:00
|
|
|
}
|
|
|
|
`
|
2016-02-01 12:39:02 +01:00
|
|
|
|
2016-10-20 02:31:12 +02:00
|
|
|
const testAccCheckDatadogMonitorConfig_ints = `
|
|
|
|
resource "datadog_monitor" "foo" {
|
|
|
|
name = "name for monitor foo"
|
|
|
|
type = "metric alert"
|
|
|
|
message = "some message Notify: @hipchat-channel"
|
|
|
|
escalation_message = "the situation has escalated @pagerduty"
|
|
|
|
|
|
|
|
query = "avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo} by {host} > 2"
|
|
|
|
|
|
|
|
thresholds {
|
|
|
|
warning = 1
|
|
|
|
critical = 2
|
|
|
|
}
|
|
|
|
|
|
|
|
notify_no_data = false
|
|
|
|
renotify_interval = 60
|
|
|
|
|
|
|
|
notify_audit = false
|
|
|
|
timeout_h = 60
|
|
|
|
include_tags = true
|
|
|
|
require_full_window = true
|
|
|
|
locked = false
|
|
|
|
|
2016-12-07 12:05:57 +01:00
|
|
|
tags = ["foo:bar", "baz"]
|
2016-10-20 02:31:12 +02:00
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
const testAccCheckDatadogMonitorConfig_ints_mixed = `
|
|
|
|
resource "datadog_monitor" "foo" {
|
|
|
|
name = "name for monitor foo"
|
|
|
|
type = "metric alert"
|
|
|
|
message = "some message Notify: @hipchat-channel"
|
|
|
|
escalation_message = "the situation has escalated @pagerduty"
|
|
|
|
|
|
|
|
query = "avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo} by {host} > 3"
|
|
|
|
|
|
|
|
thresholds {
|
|
|
|
warning = 1
|
|
|
|
critical = 3.0
|
|
|
|
}
|
|
|
|
|
|
|
|
notify_no_data = false
|
|
|
|
renotify_interval = 60
|
|
|
|
|
|
|
|
notify_audit = false
|
|
|
|
timeout_h = 60
|
|
|
|
include_tags = true
|
|
|
|
require_full_window = true
|
|
|
|
locked = false
|
|
|
|
|
2016-12-07 12:05:57 +01:00
|
|
|
tags = ["foo:bar", "baz"]
|
2016-10-20 02:31:12 +02:00
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2016-02-01 12:39:02 +01:00
|
|
|
const testAccCheckDatadogMonitorConfigUpdated = `
|
|
|
|
resource "datadog_monitor" "foo" {
|
|
|
|
name = "name for monitor bar"
|
|
|
|
type = "metric alert"
|
|
|
|
message = "a different message Notify: @hipchat-channel"
|
|
|
|
escalation_message = "the situation has escalated @pagerduty"
|
|
|
|
|
|
|
|
query = "avg(last_1h):avg:aws.ec2.cpu{environment:bar,host:bar} by {host} > 3"
|
|
|
|
|
|
|
|
thresholds {
|
2016-08-22 05:55:26 +02:00
|
|
|
ok = "0.0"
|
|
|
|
warning = "1.0"
|
|
|
|
critical = "3.0"
|
2016-02-01 12:39:02 +01:00
|
|
|
}
|
|
|
|
|
2016-05-19 15:51:27 +02:00
|
|
|
notify_no_data = true
|
2017-02-17 16:08:31 +01:00
|
|
|
new_host_delay = 900
|
2016-05-19 15:51:27 +02:00
|
|
|
no_data_timeframe = 20
|
2016-02-01 12:39:02 +01:00
|
|
|
renotify_interval = 40
|
|
|
|
escalation_message = "the situation has escalated! @pagerduty"
|
|
|
|
notify_audit = true
|
|
|
|
timeout_h = 70
|
|
|
|
include_tags = false
|
2016-05-19 10:29:23 +02:00
|
|
|
require_full_window = false
|
|
|
|
locked = true
|
2016-02-01 12:39:02 +01:00
|
|
|
silenced {
|
|
|
|
"*" = 0
|
|
|
|
}
|
2016-12-07 12:05:57 +01:00
|
|
|
tags = ["baz:qux", "quux"]
|
2016-02-01 12:39:02 +01:00
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2016-03-22 19:47:08 +01:00
|
|
|
const testAccCheckDatadogMonitorConfigWhitespace = `
|
|
|
|
resource "datadog_monitor" "foo" {
|
|
|
|
name = "name for monitor foo"
|
|
|
|
type = "metric alert"
|
|
|
|
message = <<EOF
|
|
|
|
some message Notify: @hipchat-channel
|
|
|
|
EOF
|
|
|
|
escalation_message = <<EOF
|
|
|
|
the situation has escalated @pagerduty
|
|
|
|
EOF
|
|
|
|
query = <<EOF
|
|
|
|
avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo} by {host} > 2
|
|
|
|
EOF
|
|
|
|
thresholds {
|
2016-08-22 05:55:26 +02:00
|
|
|
ok = "0.0"
|
|
|
|
warning = "1.0"
|
|
|
|
critical = "2.0"
|
2016-03-22 19:47:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
notify_no_data = false
|
|
|
|
renotify_interval = 60
|
|
|
|
|
|
|
|
notify_audit = false
|
|
|
|
timeout_h = 60
|
|
|
|
include_tags = true
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2016-02-01 12:39:02 +01:00
|
|
|
func destroyHelper(s *terraform.State, client *datadog.Client) error {
|
|
|
|
for _, r := range s.RootModule().Resources {
|
|
|
|
i, _ := strconv.Atoi(r.Primary.ID)
|
|
|
|
if _, err := client.GetMonitor(i); err != nil {
|
|
|
|
if strings.Contains(err.Error(), "404 Not Found") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
return fmt.Errorf("Received an error retrieving monitor %s", err)
|
|
|
|
}
|
|
|
|
return fmt.Errorf("Monitor still exists")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func existsHelper(s *terraform.State, client *datadog.Client) error {
|
|
|
|
for _, r := range s.RootModule().Resources {
|
|
|
|
i, _ := strconv.Atoi(r.Primary.ID)
|
|
|
|
if _, err := client.GetMonitor(i); err != nil {
|
|
|
|
return fmt.Errorf("Received an error retrieving monitor %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|