|
4 | 4 | # for details |
5 | 5 | # |
6 | 6 | # This will send the check status (0,1,2,3) to a graphite metric when a check event state changes |
7 | | -# Based on handler-graphite-notify.rb |
8 | | -# See http://imansson.wordpress.com/2012/11/26/why-sensu-is-a-monitoring-router-some-cool-handlers/ |
| 7 | +# Based on handler-graphite-notify.rb. |
| 8 | +# Config by default is graphite_status but can be called with a specific json config |
| 9 | +# using the -j option. This allows multiple graphite handlers to be configured. |
9 | 10 |
|
10 | 11 | require 'sensu-handler' |
11 | 12 | require 'simple-graphite' |
12 | 13 |
|
13 | 14 | class Resolve < Sensu::Handler |
| 15 | + option :json_config, |
| 16 | + description: 'Config Name', |
| 17 | + short: '-j JsonConfig', |
| 18 | + long: '--json_config JsonConfig', |
| 19 | + required: false, |
| 20 | + default: 'graphite_status' |
14 | 21 | # override filters from Sensu::Handler. not appropriate for metric handlers |
15 | 22 | def filter; end |
16 | 23 |
|
17 | 24 | def handle |
18 | | - port = settings['graphite_notify']['port'] ? settings['graphite_notify']['port'].to_s : '2003' |
19 | | - graphite = Graphite.new(host: settings['graphite_notify']['host'], port: port) |
| 25 | + json_config = config[:json_config] |
| 26 | + port = settings[json_config]['port'] ? settings[json_config]['port'].to_s : '2003' |
| 27 | + graphite = Graphite.new(host: settings[json_config]['host'], port: port) |
20 | 28 | return unless graphite |
21 | 29 | prop = @event['check']['status'] |
22 | | - message = "#{settings['graphite_notify']['prefix']}.#{@event['client']['name'].tr('.', '_')}.#{@event['check']['name']}" |
| 30 | + message = "#{settings[json_config]['prefix']}.#{@event['client']['name'].tr('.', '_')}.#{@event['check']['name']}" |
23 | 31 | message += " #{prop} #{graphite.time_now + rand(100)}" |
24 | 32 | begin |
25 | 33 | graphite.push_to_graphite do |graphite_socket| |
26 | 34 | graphite_socket.puts message |
27 | 35 | end |
28 | | - rescue => e |
29 | | - error_msg = "Can't connect to #{settings['graphite_notify']['host']}:#{port} and send message #{message}: #{e}'" |
| 36 | + rescue ETIMEDOUT |
| 37 | + error_msg = "Can't connect to #{settings[json_config]['host']}:#{port} and send message #{message}'" |
30 | 38 | raise error_msg |
31 | 39 | end |
32 | 40 | end |
|
0 commit comments