Skip to content

Commit

Permalink
Add RPC definition of purge-alarms
Browse files Browse the repository at this point in the history
  • Loading branch information
dpino committed Sep 14, 2017
1 parent 750221c commit 506c4f0
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/apps/config/leader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,18 @@ function Leader:rpc_set_alarm_operator_state (args)
if success then return response else return {status=1, error=response} end
end

function Leader:rpc_purge_alarms (args)
local function getter()
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)
if success then return response else return {status=1, error=response} end
end

local function path_parser_for_grammar(grammar, path)
local getter, subgrammar = path_mod.resolver(grammar, path)
return data.data_parser_from_grammar(subgrammar)
Expand Down
47 changes: 47 additions & 0 deletions src/lib/yang/snabb-config-leader-v1.yang
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,51 @@ module snabb-config-leader-v1 {
leaf success { type boolean; description "True if operation succeeded."; }
}
}

grouping filter-input {
description
"Grouping to specify a filter construct on alarm information.";
leaf alarm-status {
type string;
mandatory true;
description
"The clearance status of the alarm.";
}
leaf older-than {
type string;
description "Matches the 'last-status-change' leaf in the alarm.";
}
leaf severity {
type string;
description "Filter based on severity.";
}
leaf operator-state-filter {
type string;
description "Filter based on operator state.";
}
}

rpc purge-alarms {
description
"This operation requests the server to delete entries from the
alarm list according to the supplied criteria. Typically it
can be used to delete alarms that are in closed operator state
and older than a specified time. The number of purged alarms
is returned as an output parameter";
input {
leaf schema { type string; mandatory true; }
leaf revision { type string; }
leaf print-default { type boolean; }
leaf format { type string; }
uses filter-input;
}
output {
uses error-reporting;
leaf purged-alarms {
type uint32;
description "Number of purged alarms.";
}
}
}

}
3 changes: 3 additions & 0 deletions src/program/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ include:
* [`snabb config set-alarm-operator-state`](./set_alarm_operator_state/README):
add a new operator-state to an alarm

* [`snabb config purge-alarms`](./purge_alarms/README):
purge alarms by several criteria

The `snabb config get` et al commands are the normal way that Snabb
users interact with Snabb applications in an ad-hoc fashion via the
command line. `snabb config listen` is the standard way that a NETCONF
Expand Down
32 changes: 32 additions & 0 deletions src/program/config/purge_alarms/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Usage: snabb config purge-alarms [OPTION]... ID STATE
Adds a new operator-state in an alarm.

Available options:
-s, --schema SCHEMA YANG data interface to request.
-r, --revision REVISION Require a specific revision of the YANG module.
-f, --format Selects output format (yang or xpath). Default: yang.
--print-default Forces print out of default values.
-h, --help Displays this message.

Filtering options:
--by-severity [severity-spec/value].
Severity spec: 'is', 'below', 'above'.
Value: 'indeterminate', 'minor', 'warning', 'major', 'critical'.
--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.

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

See https://github.com/Igalia/snabb/blob/lwaftr/src/program/config/README.md
for full documentation.
1 change: 1 addition & 0 deletions src/program/config/purge_alarms/README.inc
60 changes: 60 additions & 0 deletions src/program/config/purge_alarms/purge_alarms.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
-- Use of this source code is governed by the Apache 2.0 license; see COPYING.
module(..., package.seeall)

local common = require("program.config.common")
local lib = require("core.lib")

local function usage(exit_code)
print(require('program.config.purge_alarms.README_inc'))
main.exit(exit_code)
end

local function parse_args (args)
local handlers = {}
local opts = {}
local function table_size (t)
local count = 0
for _ in pairs(t) do count = count + 1 end
return count
end
local function without_opts (args)
local ret = {}
for i=1,#args do
local arg = args[i]
if opts[arg] then
i = i + 2
else
table.insert(ret, arg)
end
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-operator-state'] = function (arg)
opts['operator_state_filter'] = arg
end
args = lib.dogetopt(args, handlers, "", { ['by-older-than']=1,
['by-severity']=1, ['by-operator-state']=1 })
opts.status = table.remove(args, #args)
if table_size(opts) == 0 then usage(1) end
local args = without_opts(args)
return opts, args
end

function run(args)
local l_args, args = parse_args(args)
local opts = { command='purge-alarms', with_path=false, is_config=false }
args = common.parse_command_line(args, opts)
local response = common.call_leader(
args.instance_id, 'purge-alarms',
{ schema = args.schema_name, alarm_status = l_args.status,
older_than = l_args.older_than, severity = l_args.severity,
operator_state_filter = l_args.operator_state_filter,
print_default = args.print_default, format = args.format })
common.print_and_exit(response, "purged_alarms")
end

0 comments on commit 506c4f0

Please sign in to comment.