Skip to content

Commit

Permalink
Flexibility to have multiple hipchat configs
Browse files Browse the repository at this point in the history
Please refer: sensu-plugins/sensu-plugin#66

Currently, the handler assumes that there will be a json file which will have "hipchat" as the top-level key in the json. Due to the same, we can only have one hipchat configuration for using with hipchat.rb.

The above changes the behavior by taking in an optional config json top level key name while invoking the handler (Instead of "hipchat.rb" you invoke "hipchat.rb --jsonConfig <config top level key>" as the handler command).

In this way, we can have multiple handlers defined with different hipchat configurations such as different hipchat rooms or different from fields.

Note: As it is an optional parameter, it will just work fine with the existing hipchat.json method (Backward compatible :) )
  • Loading branch information
abhishekjain88 committed Aug 14, 2014
1 parent f4e06bf commit 0090464
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions handlers/notification/hipchat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@
require 'timeout'

class HipChatNotif < Sensu::Handler

option :jsonConfig,
:description => 'Config Name',
:short => '-j JsonConfig',
:long => '--jsonConfig JsonConfig',
:required => false

def event_name
@event['client']['name'] + '/' + @event['check']['name']
end

def handle
apiversion = settings["hipchat"]["apiversion"] || 'v1'
proxy_url = settings["hipchat"]["proxy_url"]
hipchatmsg = HipChat::Client.new(settings["hipchat"]["apikey"], :api_version => apiversion, :http_proxy => proxy_url)
room = settings["hipchat"]["room"]
from = settings["hipchat"]["from"] || 'Sensu'
jsonConfig = config[:jsonConfig] || 'hipchat'
apiversion = settings[jsonConfig]["apiversion"] || 'v1'
proxy_url = settings[jsonConfig]["proxy_url"]
hipchatmsg = HipChat::Client.new(settings[jsonConfig]["apikey"], :api_version => apiversion, :http_proxy => proxy_url)
room = settings[jsonConfig]["room"]
from = settings[jsonConfig]["from"] || 'Sensu'

message = @event['check']['notification'] || @event['check']['output']

Expand Down

0 comments on commit 0090464

Please sign in to comment.