Skip to content

Commit

Permalink
Fix nits
Browse files Browse the repository at this point in the history
  • Loading branch information
dpino committed Sep 14, 2017
1 parent 506c4f0 commit 27874ea
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/apps/config/leader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,14 @@ function Leader:rpc_set_alarm_operator_state (args)
end

function Leader:rpc_purge_alarms (args)
local function getter()
local function purge()
if args.schema ~= self.schema_name then
return false, ("Purge-alarms operation not supported in"..
"'%s' schema"):format(args.schema)
end
return { purged_alarms = alarms.purge_alarms(args) }
end
local success, response = pcall(getter)
local success, response = pcall(purge)
if success then return response else return {status=1, error=response} end
end

Expand Down
6 changes: 3 additions & 3 deletions src/lib/yang/alarms.lua
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ function purge_alarms (args)
local function by_older_than (alarm, args)
local older_than = assert(args.older_than)
if type(older_than) == 'string' then
local age_spec, value = older_than:match("([%w]+)/([%d]+)")
local age_spec, value = older_than:match("([%w]+):([%d]+)")
older_than = {value = value, age_spec = age_spec}
end
assert(type(older_than) == 'table')
Expand All @@ -332,7 +332,7 @@ function purge_alarms (args)
local function by_severity (alarm, args)
local severity = assert(args.severity)
if type(severity) == 'string' then
local sev_spec, value = severity:match("([%w]+)/([%w]+)")
local sev_spec, value = severity:match("([%w]+):([%w]+)")
severity = {sev_spec = sev_spec, value = value}
end
assert(type(severity) == 'table' and severity.sev_spec and severity.value,
Expand All @@ -358,7 +358,7 @@ function purge_alarms (args)
local operator_state = assert(args.operator_state_filter)
local state, user
if type(operator_state) == 'string' then
state, user = operator_state:match("([%w]+)/([%w]+)")
state, user = operator_state:match("([%w]+):([%w]+)")
if not state then
state, user = operator_state, operator_state
end
Expand Down
14 changes: 7 additions & 7 deletions src/program/config/purge_alarms/README
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ Available options:
-h, --help Displays this message.

Filtering options:
--by-severity [severity-spec/value].
--by-severity [severity-spec:value].
Severity spec: 'is', 'below', 'above'.
Value: 'indeterminate', 'minor', 'warning', 'major', 'critical'.
--by-older-than [age-spec/value].
--by-older-than [age-spec:value].
Age spec: 'seconds', 'minutes', 'hours', 'days', 'weeks'.
Value: integer.
--by-operator-state-filter [state/user].
State: 'none', 'ack', 'closed', 'shelved', 'un-shelved'.
User: string.
--by-operator-state-filter [state:user].
State (optional): 'none', 'ack', 'closed', 'shelved', 'un-shelved'.
User (optional): string.

Given an instance identifier and an alarm state ('any', 'cleared' or 'not-cleared')
remove all alarms that match the filtering options.

Typical usage:

$ sudo ./snabb config purge-alarms lwaftr any
$ sudo ./snabb config purge-alarms --by-severity above/minor lwaftr any
$ sudo ./snabb config purge-alarms --by-older-than minutes/5 lwaftr cleared
$ sudo ./snabb config purge-alarms --by-severity above:minor lwaftr any
$ sudo ./snabb config purge-alarms --by-older-than minutes:5 lwaftr cleared

See https://github.com/Igalia/snabb/blob/lwaftr/src/program/config/README.md
for full documentation.
10 changes: 3 additions & 7 deletions src/program/config/purge_alarms/purge_alarms.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,10 @@ local function parse_args (args)
end
return ret
end
handlers['by-older-than'] = function (arg)
opts['older_than'] = arg
end
handlers['by-severity'] = function (arg)
opts['severity'] = arg
end
handlers['by-older-than'] = function (arg) opts.older_than = arg end
handlers['by-severity'] = function (arg) opts.severity = arg end
handlers['by-operator-state'] = function (arg)
opts['operator_state_filter'] = arg
opts.operator_state_filter = arg
end
args = lib.dogetopt(args, handlers, "", { ['by-older-than']=1,
['by-severity']=1, ['by-operator-state']=1 })
Expand Down

0 comments on commit 27874ea

Please sign in to comment.