Created
January 3, 2013 20:33
-
-
Save juanje/4446963 to your computer and use it in GitHub Desktop.
Example of Chef hanfler for sending run fails to Pushover (notifications to iPhone and Android)
https://pushover.net/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cookbook/files/default/pushover_handler.rb | |
require "net/https" | |
module MyOrg | |
class PushOver < Chef::Handler | |
def initialize(config={}) | |
@config = config | |
end | |
def report | |
return unless run_status.failed? | |
return if @config.empty? | |
# The Node is available as +node+ | |
title = "Failed node #{node.name}" | |
# +run_status+ is a value object with all of the run status data | |
message = run_status.formatted_exception | |
url = URI.parse("https://api.pushover.net/1/messages.json") | |
req = Net::HTTP::Post.new(url.path) | |
req.set_form_data({ | |
:token => @config[:app_token], | |
:user => @config[:user_key], | |
:title => title, | |
:message => message, | |
}) | |
https = Net::HTTP.new(url.host, url.port) | |
https.use_ssl = true | |
# It should be OpenSSL::SSL::VERIFY_PEER, but it wasn't working | |
https.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
https.start {|http| http.request(req) } | |
Chef::Log.info("Myorg::PushOver sending Pushover notification") | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cookbook/recipes/reports.rb | |
pushover_report_path = "#{node['chef_handler']['handler_path']}/pushover_handler.rb" | |
cookbook_file pushover_report_path | |
include_recipe "chef_handler::default" | |
chef_handler 'MyOrg::PushOver' do | |
source pushover_report_path | |
arguments :app_token => node['myorg']['pushover']['app_token'], | |
:user_key => node['myorg']['pushover']['user_key'] | |
action :enable | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"run_list": ["recipe[myorg::reports]", "recipe[myorg::foo]"] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment