Skip to content

Commit

Permalink
provider/datadog hashicorp#9026: Make thresholds optional. (hashicorp…
Browse files Browse the repository at this point in the history
  • Loading branch information
ojongerius authored and Gustavo Mateus committed Dec 6, 2016
1 parent b288d6d commit 0e16dbf
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 6 deletions.
4 changes: 2 additions & 2 deletions builtin/providers/datadog/resource_datadog_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func resourceDatadogMonitor() *schema.Resource {
// Options
"thresholds": &schema.Schema{
Type: schema.TypeMap,
Required: true,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ok": &schema.Schema{
Expand All @@ -69,7 +69,7 @@ func resourceDatadogMonitor() *schema.Resource {
},
"critical": &schema.Schema{
Type: schema.TypeFloat,
Required: true,
Optional: true,
},
},
},
Expand Down
59 changes: 59 additions & 0 deletions builtin/providers/datadog/resource_datadog_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,42 @@ func TestAccDatadogMonitor_Basic(t *testing.T) {
})
}

func TestAccDatadogMonitor_BasicNoTreshold(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDatadogMonitorDestroy,
Steps: []resource.TestStep{
resource.TestStep{
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(
"datadog_monitor.foo", "tags.foo", "bar"),
resource.TestCheckResourceAttr(
"datadog_monitor.foo", "tags.bar", "baz"),
),
},
},
})
}

func TestAccDatadogMonitor_Updated(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down Expand Up @@ -255,6 +291,29 @@ resource "datadog_monitor" "foo" {
}
}
`
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
tags {
"foo" = "bar"
"bar" = "baz"
}
}
`

const testAccCheckDatadogMonitorConfig_ints = `
resource "datadog_monitor" "foo" {
Expand Down
25 changes: 21 additions & 4 deletions website/source/docs/providers/datadog/r/monitor.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,27 @@ The following arguments are supported:
Email notifications can be sent to specific users by using the same '@username' notation as events.
* `escalation_message` - (Optional) A message to include with a re-notification. Supports the '@username'
notification allowed elsewhere.
* `thresholds` - (Required) Thresholds by threshold type:
* `ok`
* `warning`
* `critical`
* `thresholds` - (Optional)
* Metric alerts:
A dictionary of thresholds by threshold type. Currently we have two threshold types for metric alerts: critical and warning. Critical is defined in the query, but can also be specified in this option. Warning threshold can only be specified using the thresholds option.
Example usage:
```
thresholds {
critical = 90
warning = 80
}
```
* Service checks:
A dictionary of thresholds by status. Because service checks can have multiple thresholds, we don't define them directly in the query.
Default values:
```
thresholds {
ok = 1
critical = 1
warning = 1
}
```

* `notify_no_data` (Optional) A boolean indicating whether this monitor will notify when data stops reporting. Defaults
to true.
* `no_data_timeframe` (Optional) The number of minutes before a monitor will notify when data stops reporting. Must be at
Expand Down

0 comments on commit 0e16dbf

Please sign in to comment.