Skip to content

Commit

Permalink
Merge pull request snabbco#947 from dpino/decouple-alarms-declaration
Browse files Browse the repository at this point in the history
Decouple alarms declaration
  • Loading branch information
dpino authored Sep 19, 2017
2 parents 5c5918b + a7d8bac commit ff9e2d9
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 29 deletions.
14 changes: 5 additions & 9 deletions src/apps/ipv4/arp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,16 @@ local ipv4 = require("lib.protocol.ipv4")
local alarms = require("lib.yang.alarms")

alarms.add_to_inventory {
[{alarm_type_id='arp-resolution', alarm_type_qualifier=''}] = {
resource={'external-interface'},
[{alarm_type_id='arp-resolution'}] = {
resource={'nic-v4'},
has_clear=true,
description='Raise up if ARP app cannot resolve IP address'
description='Raise up if ARP app cannot resolve IP address',
}
}
local resolve_alarm = alarms.declare_alarm {
[{resource='external-interface', alarm_type_id='arp-resolution', alarm_type_qualifier=''}] = {
[{resource='nic-v4', alarm_type_id='arp-resolution'}] = {
perceived_severity = 'critical',
alarm_text =
'Make sure you can resolve external-interface.next-hop.ip address '..
'manually. If it cannot be resolved, consider setting the MAC '..
'address of the next-hop directly. To do it so, set '..
'external-interface.next-hop.mac to the value of the MAC address.',
alarm_text = 'Make sure you can ARP resolve IP addresses on NIC',
},
}

Expand Down
12 changes: 4 additions & 8 deletions src/apps/lwaftr/ndp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,16 @@ local ipv6 = require("lib.protocol.ipv6")
local alarms = require("lib.yang.alarms")

alarms.add_to_inventory {
[{alarm_type_id='ndp-resolution', alarm_type_qualifier=''}] = {
resource={'internal-interface'},
[{alarm_type_id='ndp-resolution'}] = {
resource={'nic-v6'},
has_clear=true,
description='Raise up if NDP app cannot resolve IPv6 address'
}
}
local resolve_alarm = alarms.declare_alarm {
[{resource='internal-interface', alarm_type_id='ndp-resolution', alarm_type_qualifier=''}] = {
[{resource='nic-v6', alarm_type_id='ndp-resolution'}] = {
perceived_severity = 'critical',
alarm_text =
'Make sure you can resolve internal-interface.next-hop.ip address '..
'manually. If it cannot be resolved, consider setting the MAC '..
'address of the next-hop directly. To do it so, set '..
'internal-interface.next-hop.mac to the value of the MAC address.',
alarm_text = 'Make sure you can NDP resolve IP addresses on NIC',
},
}

Expand Down
34 changes: 22 additions & 12 deletions src/lib/yang/alarms.lua
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,21 @@ end

function declare_alarm (alarm)
assert(table_size(alarm) == 1)
local key
for k, v in pairs(alarm) do
key = alarm_keys:normalize(k)
alarm_list:new(key, v)
local function create_or_update (key, src)
local dst = alarm_list:lookup(key)
if dst then
-- Extend or overwrite existing alarm values.
for k, v in pairs(src) do
dst[k] = v
end
alarm_list:new(key, dst)
else
alarm_list:new(key, src)
end
end
local k, v = next(alarm)
local key = alarm_keys:normalize(k)
create_or_update(key, v)
function alarm:raise (args)
alarm_codec.raise_alarm(key, args)
end
Expand Down Expand Up @@ -531,7 +541,7 @@ function selftest ()
assert(state.alarm_list.number_of_alarms == 0)

-- Raising an alarm when alarms is empty, creates an alarm.
local key = alarm_keys:fetch('external-interface', 'arp-resolution')
local key = alarm_keys:fetch('nic-v4', 'arp-resolution')
raise_alarm(key)
local alarm = assert(state.alarm_list.alarm[key])
assert(table_size(alarm.status_change) == 1)
Expand Down Expand Up @@ -614,10 +624,10 @@ function selftest ()
assert(t.minor.total == 1)

-- Compress alarms.
local key = alarm_keys:fetch('external-interface', 'arp-resolution')
local key = alarm_keys:fetch('nic-v4', 'arp-resolution')
local alarm = state.alarm_list.alarm[key]
assert(table_size(alarm.status_change) == 4)
compress_alarms({resource='external-interface'})
compress_alarms({resource='nic-v4'})
assert(table_size(alarm.status_change) == 1)

-- Set operator state change on non existent alarm should fail.
Expand All @@ -636,13 +646,13 @@ function selftest ()
assert(purge_alarms({alarm_status = 'any'}) == 0)

-- Purge alarms filtering by older_than.
local key = alarm_keys:fetch('external-interface', 'arp-resolution')
local key = alarm_keys:fetch('nic-v4', 'arp-resolution')
raise_alarm(key)
sleep(1)
assert(purge_alarms({older_than={age_spec='seconds', value='1'}}) == 1)

-- Purge alarms by severity.
local key = alarm_keys:fetch('external-interface', 'arp-resolution')
local key = alarm_keys:fetch('nic-v4', 'arp-resolution')
raise_alarm(key)
assert(table_size(state.alarm_list.alarm) == 1)
assert(purge_alarms({severity={sev_spec='is', value='minor'}}) == 0)
Expand All @@ -652,13 +662,13 @@ function selftest ()
raise_alarm(key, {perceived_severity='minor'})
assert(purge_alarms({severity={sev_spec='is', value='minor'}}) == 1)

raise_alarm(alarm_keys:fetch('external-interface', 'arp-resolution'))
raise_alarm(alarm_keys:fetch('internal-interface', 'ndp-resolution'))
raise_alarm(alarm_keys:fetch('nic-v4', 'arp-resolution'))
raise_alarm(alarm_keys:fetch('nic-v6', 'ndp-resolution'))
assert(table_size(state.alarm_list.alarm) == 2)
assert(purge_alarms({severity={sev_spec='above', value='minor'}}) == 2)

-- Purge alarms by operator_state_filter.
local key = alarm_keys:fetch('external-interface', 'arp-resolution')
local key = alarm_keys:fetch('nic-v4', 'arp-resolution')
raise_alarm(key)
assert(table_size(state.alarm_list.alarm) == 1)
local success = set_operator_state(key, {state='ack'})
Expand Down
25 changes: 25 additions & 0 deletions src/program/lwaftr/alarms.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module(..., package.seeall)

local alarms = require("lib.yang.alarms")

alarms.declare_alarm {
[{resource='nic-v4', alarm_type_id='arp-resolution', alarm_type_qualifier=''}] = {
perceived_severity = 'critical',
alarm_text =
'Make sure you can resolve external-interface.next-hop.ip address '..
'manually. If it cannot be resolved, consider setting the MAC '..
'address of the next-hop directly. To do it so, set '..
'external-interface.next-hop.mac to the value of the MAC address.',
},
}

alarms.declare_alarm {
[{resource='nic-v6', alarm_type_id='ndp-resolution', alarm_type_qualifier=''}] = {
perceived_severity = 'critical',
alarm_text =
'Make sure you can resolve internal-interface.next-hop.ip address '..
'manually. If it cannot be resolved, consider setting the MAC '..
'address of the next-hop directly. To do it so, set '..
'internal-interface.next-hop.mac to the value of the MAC address.',
},
}
4 changes: 4 additions & 0 deletions src/program/lwaftr/setup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ function lwaftr_app(c, conf, device)
next_ip = convert_ipv4(iexternal_interface.next_hop.ip),
alarm_notification = conf.alarm_notification })

if conf.alarm_notification then
require('program.lwaftr.alarms')
end

local preprocessing_apps_v4 = { "reassemblerv4" }
local preprocessing_apps_v6 = { "reassemblerv6" }
local postprocessing_apps_v4 = { "fragmenterv4" }
Expand Down

0 comments on commit ff9e2d9

Please sign in to comment.