Manage notification handler for Sensu
This patch adds two things:
- the field 'handler' to an alarm. Now an alarm can be described as
alarm_name:
policy: name_of_policy
alerting: enabled_with_notifications
handler: mail
...
- a new parameter 'notification_handler' to pass the handler that
can now be added to an alarm.
Change-Id: I1e0767b3c1aa664110c97ae5f8fafc47c9682ab9
diff --git a/tests/lua/test_afd.lua b/tests/lua/test_afd.lua
index a54bdfd..478a36c 100644
--- a/tests/lua/test_afd.lua
+++ b/tests/lua/test_afd.lua
@@ -47,19 +47,20 @@
end
function TestAfd:test_inject_afd_metric_without_alarms()
- afd.inject_afd_metric(consts.OKAY, 'node-1', 'foo', {}, false)
+ afd.inject_afd_metric(consts.OKAY, 'node-1', 'foo', {}, false, false, nil)
local alarms = afd.get_alarms()
assertEquals(#alarms, 0)
assertEquals(last_injected_msg.Type, 'afd_metric')
assertEquals(last_injected_msg.Fields.value, consts.OKAY)
assertEquals(last_injected_msg.Fields.hostname, 'node-1')
+ assertEquals(last_injected_msg.Fields.notification_handler, 'mail')
assertEquals(last_injected_msg.Payload, '{"alarms":[]}')
end
function TestAfd:test_inject_afd_metric_with_alarms()
afd.add_to_alarms(consts.CRIT, 'last', 'metric_1', {}, {}, '==', 0, 0, nil, nil, "important message")
- afd.inject_afd_metric(consts.CRIT, 'node-1', 'foo', {}, false)
+ afd.inject_afd_metric(consts.CRIT, 'node-1', 'foo', {}, true, true, 'mail')
local alarms = afd.get_alarms()
assertEquals(#alarms, 0)
@@ -67,6 +68,7 @@
assertEquals(last_injected_msg.Fields.value, consts.CRIT)
assertEquals(last_injected_msg.Fields.hostname, 'node-1')
assertEquals(last_injected_msg.Fields.environment_id, extra.environment_id)
+ assertEquals(last_injected_msg.Fields.notification_handler, 'mail')
assert(last_injected_msg.Payload:match('"message":"important message"'))
assert(last_injected_msg.Payload:match('"severity":"CRITICAL"'))
end
diff --git a/tests/lua/test_gse.lua b/tests/lua/test_gse.lua
index be892f5..b68986d 100644
--- a/tests/lua/test_gse.lua
+++ b/tests/lua/test_gse.lua
@@ -184,36 +184,39 @@
end
function TestGse:test_inject_cluster_metric_for_nova()
- gse.inject_cluster_metric('nova', {key = "val"}, true)
+ gse.inject_cluster_metric('nova', {key = "val"}, true, true, 'mail')
local metric = last_injected_msg
assertEquals(metric.Type, 'gse_metric')
assertEquals(metric.Fields.member, 'nova')
assertEquals(metric.Fields.name, 'cluster_status')
assertEquals(metric.Fields.value, consts.OKAY)
assertEquals(metric.Fields.key, 'val')
+ assertEquals(metric.Fields.notification_handler, 'mail')
assertEquals(metric.Payload, '{"alarms":[]}')
end
function TestGse:test_inject_cluster_metric_for_glance()
- gse.inject_cluster_metric('glance', {key = "val"}, true)
+ gse.inject_cluster_metric('glance', {key = "val"}, false, false, 'mail')
local metric = last_injected_msg
assertEquals(metric.Type, 'gse_metric')
assertEquals(metric.Fields.member, 'glance')
assertEquals(metric.Fields.name, 'cluster_status')
assertEquals(metric.Fields.value, consts.DOWN)
assertEquals(metric.Fields.key, 'val')
+ assertEquals(metric.Fields.notification_handler, 'mail')
assert(metric.Payload:match("glance%-registry endpoints are down"))
assert(metric.Payload:match("glance%-api endpoint is down on node%-1"))
end
function TestGse:test_inject_cluster_metric_for_heat()
- gse.inject_cluster_metric('heat', {key = "val"}, true)
+ gse.inject_cluster_metric('heat', {key = "val"}, true, true, 'mail')
local metric = last_injected_msg
assertEquals(metric.Type, 'gse_metric')
assertEquals(metric.Fields.member, 'heat')
assertEquals(metric.Fields.name, 'cluster_status')
assertEquals(metric.Fields.value, consts.WARN)
assertEquals(metric.Fields.key, 'val')
+ assertEquals(metric.Fields.notification_handler, 'mail')
assert(metric.Payload:match("5xx errors detected"))
assert(metric.Payload:match("1 RabbitMQ node out of 3 is down"))
end