Closed blysik closed 8 years ago
Such a method already exists. For example: /etc/moira/config.yml
- type: script
name: myscript
exec: /home/vagrant/script-test.rb /home/vagrant/moira-script.log ${contact_value}
config.json
{
"api_url": "/api",
"contacts": [
{"type": "mail", "validation": "^.+@.+\\..+$", "icon": "email"},
{"type": "myscript", "title": "it is my ruby script"}
]
}
test-script.rb
#!/usr/bin/ruby
require 'json'
logfile = ARGV.shift
if !logfile
puts "Bad file name"
exit 1
end
contact_value = ARGV.shift
if !contact_value
puts "contact must be exist"
exit 1
end
if !STDIN.tty? then
message = JSON.parse(STDIN.read)
else
puts "STDIN: empty"
exit 1
end
File.open(logfile, 'a') do | file |
file.write("Contact from AGRS: #{contact_value}\n")
file.write("STDIN:\n")
file.write(message)
file.write("\n")
end
moira-script.log
Contact from AGRS: myContact
STDIN:
{"events"=>[{"timestamp"=>1462535904, "metric"=>"", "value"=>0, "state"=>"EXCEPTION", "trigger_id"=>"1d425713-294d-41f1-904a-311e9fd270f8", "sub_id"=>"98edd5c3-737b-4e44-80a6-33811d3469f6", "old_state"=>"OK", "msg"=>""}], "trigger"=>{"id"=>"1d425713-294d-41f1-904a-311e9fd270f8", "name"=>"Random", "targets"=>["randomWalkFunction(DevOps.moira.cache.received.total.one-minute)"], "warn_value"=>200, "error_value"=>10, "__notifier_trigger_tags"=>["Moira"]}, "contact"=>{"type"=>"myscript", "value"=>"myContact", "id"=>"a4508897-91dc-43cf-8994-c94e3d5bba83"}, "throttled"=>false, "timestamp"=>0}
Great! If I'm reading this correctly, the script can be sent multiple events, with a single trigger. Quick question about an event: What are the values for 'state'? OK, WARN, EXCEPTION ?
Sorry, read the docs better. State appears to be: OK, WARN, ERROR, NODATA, EXCEPTION
Allow a notifier type of 'shell exec'. This would let users configure the use of arbitrary, command-line notification tools. (In my case, I'd love to simply use the alerta cli tool.)