Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept "null" in monitor NoDataTimeframe #129

Merged
merged 2 commits into from
Nov 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions integration/monitors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,26 @@ func TestMonitorGet(t *testing.T) {
}
}

func TestMonitorGetWithoutNoDataTimeframe(t *testing.T) {
monitors, err := client.GetMonitors()
if err != nil {
t.Fatalf("Retrieving monitors failed when it shouldn't: %s", err)
}
num := len(monitors)

monitor := createTestMonitorWithoutNoDataTimeframe(t)
defer cleanUpMonitor(t, *monitor.Id)

monitors, err = client.GetMonitors()
if err != nil {
t.Fatalf("Retrieving monitors failed when it shouldn't: %s", err)
}

if num+1 != len(monitors) {
t.Fatalf("Number of monitors didn't match expected: %d != %d", len(monitors), num+1)
}
}

func TestMonitorMuteUnmute(t *testing.T) {
monitor := createTestMonitor(t)
defer cleanUpMonitor(t, *monitor.Id)
Expand Down Expand Up @@ -135,6 +155,27 @@ func getTestMonitor() *datadog.Monitor {
}
}

func getTestMonitorWithoutNoDataTimeframe() *datadog.Monitor {

o := &datadog.Options{
NotifyNoData: datadog.Bool(false),
NotifyAudit: datadog.Bool(false),
Locked: datadog.Bool(false),
NewHostDelay: datadog.Int(600),
RequireFullWindow: datadog.Bool(true),
Silenced: map[string]int{},
}

return &datadog.Monitor{
Message: datadog.String("Test message"),
Query: datadog.String("avg(last_15m):avg:system.disk.in_use{*} by {host,device} > 0.8"),
Name: datadog.String("Test monitor"),
Options: o,
Type: datadog.String("metric alert"),
Tags: make([]string, 0),
}
}

func createTestMonitor(t *testing.T) *datadog.Monitor {
monitor := getTestMonitor()
monitor, err := client.CreateMonitor(monitor)
Expand All @@ -145,6 +186,16 @@ func createTestMonitor(t *testing.T) *datadog.Monitor {
return monitor
}

func createTestMonitorWithoutNoDataTimeframe(t *testing.T) *datadog.Monitor {
monitor := getTestMonitorWithoutNoDataTimeframe()
monitor, err := client.CreateMonitor(monitor)
if err != nil {
t.Fatalf("Creating a monitor failed when it shouldn't: %s", err)
}

return monitor
}

func cleanUpMonitor(t *testing.T, id int) {
if err := client.DeleteMonitor(id); err != nil {
t.Fatalf("Deleting a monitor failed when it shouldn't. Manual cleanup needed. (%s)", err)
Expand Down
2 changes: 1 addition & 1 deletion monitors.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type NoDataTimeframe int

func (tf *NoDataTimeframe) UnmarshalJSON(data []byte) error {
s := string(data)
if s == "false" {
if s == "false" || s == "null" {
*tf = 0
} else {
i, err := strconv.ParseInt(s, 10, 32)
Expand Down