-
Notifications
You must be signed in to change notification settings - Fork 298
/
set_alarm_operator_state.lua
44 lines (40 loc) · 1.45 KB
/
set_alarm_operator_state.lua
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
-- 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 function usage(exit_code)
print(require("program.config.set_alarm_operator_state.README_inc"))
main.exit(exit_code)
end
local function parse_args (args)
if #args < 4 or #args > 5 then usage(1) end
local alarm_type_id, alarm_type_qualifier = (args[3]):match("([%w]+)/([%w]+)")
if not alarm_type_id then
alarm_type_id, alarm_type_qualifier = args[3], ''
end
local ret = {
key = {
resource = args[2],
alarm_type_id = alarm_type_id,
alarm_type_qualifier = alarm_type_qualifier,
},
state = args[4],
text = args[5] or '',
}
-- Remove all arguments except first one.
for i=2,#args do
table.remove(args, #args)
end
return ret
end
function run(args)
local l_args = parse_args(args)
local opts = { command='set-alarm-operator-state', with_path=false, is_config=false }
args = common.parse_command_line(args, opts)
local response = common.call_leader(
args.instance_id, 'set-alarm-operator-state',
{ schema = args.schema_name, revision = args.revision_date,
resource = l_args.key.resource, alarm_type_id = l_args.key.alarm_type_id,
alarm_type_qualifier = l_args.key.alarm_type_qualifier,
state = l_args.state, text = l_args.text })
common.print_and_exit(response, "success")
end