Skip to content

Commit

Permalink
Merge pull request #129 from dtan4/accept-null-no-data-timeframe
Browse files Browse the repository at this point in the history
Accept "null" in monitor NoDataTimeframe
  • Loading branch information
ojongerius authored Nov 28, 2017
2 parents fb5f8a6 + faa77e9 commit a117c6a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
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

0 comments on commit a117c6a

Please sign in to comment.