double-z
10/1/2013 - 12:36 AM

sensu_standalone_check.rb

# installs a standalone sensu check

#   sensu_standalone_check "unicorn_master" do
#     command "#{node.sensu.directory}/plugins/processes/check-procs.rb"
#     arguments "-f #{deploy_to}/shared/pids/unicorn.pid"
#   end

define :sensu_standalone_check, :interval => 60, :enable => true, :owner => "root", :mode => 0644 do
  include_recipe "sensu::_config"

  if params[:enable]
    command = params[:command] || File.join(node.sensu.directory, "plugins", params[:plugin])
    command << " " << params[:arguments] if params[:arguments]
    
    check_params = params.dup
    [:enable, :plugin, :arguments, :name].each { |k| check_params.delete(k) }

    check_params[:standalone] = true

    file File.join(node.sensu.directory, "conf.d", "#{params[:name]}.json") do
      content JSON.pretty_generate({ "checks" => { params[:name] => check_params }})
      mode params[:mode]
      owner params[:owner]
      notifies :updated, resources(:sensu_config => node.name), :immediately
    end
  else
    file File.join(node.sensu.directory, "conf.d", "#{params[:name]}.json") do
      action :delete
      notifies :updated, resources(:sensu_config => node.name), :immediately
    end
  end
end