1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
defmodule Exdatadog.Monitors.Test do
@moduledoc """
Tests Exdatadog.Monitors
"""
use ExUnit.Case
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
@cassette_dir "test/fixture/vcr_cassettes/monitors"
alias Exdatadog.Client
import Exdatadog.Monitors
doctest Exdatadog.Monitors
@lint {Credo.Check.Design.AliasUsage, false}
setup_all do
ExVCR.Config.cassette_library_dir(@cassette_dir)
end
test "can get montior details" do
client = Client.new()
expected = {200,
%{"created" => "2015-12-18T16:34:14.014039+00:00",
"id" => 91_879,
"message" => "We may need to add web hosts if this is consistently high.",
"modified" => "2015-12-18T16:34:14.014039+00:00",
"multi" => false,
"name" => "Bytes received on host0",
"options" => %{"notify_audit" => false,
"notify_no_data" => false,
"silenced" => %{}},
"org_id" => 1499,
"query" => "avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 100",
"type" => "metric alert"
}}
use_cassette "details" do
assert details(91_879, client) == expected
end
end
test "can get monitor details with group_states" do
client = Client.new()
expected = {200,
%{"created" => "2015-12-18T16:34:14.014039+00:00",
"id" => 91_879,
"message" => "We may need to add web hosts if this is consistently high.",
"modified" => "2015-12-18T16:34:14.014039+00:00",
"multi" => false,
"name" => "Bytes received on host0",
"options" => %{"no_data_timeframe" => 20,
"notify_audit" => false,
"notify_no_data" => false,
"silenced" => %{}},
"org_id" => 1499,
"query" => "avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 100",
"type" => "metric alert",
"state" => %{
"groups" => %{
"host:host0" => %{
"last_nodata_ts" => nil,
"last_notified_ts" => 1_481_909_160,
"last_resolved_ts" => 1_481_908_200,
"last_triggered_ts" => 1_481_909_160,
"name" => "host:host0",
"status" => "Alert",
"triggering_value" => %{
"from_ts" => 1_481_909_037,
"to_ts" => 1_481_909_097,
"value" => 1_000}
}
}
}
}
}
use_cassette "details_with_group_states" do
assert details(91_879, ~w(alert warn), client) == expected
end
end
end
|