Skip to content

Instantly share code, notes, and snippets.

@heffergm
Created January 22, 2012 12:31
Show Gist options
  • Save heffergm/1656917 to your computer and use it in GitHub Desktop.
Save heffergm/1656917 to your computer and use it in GitHub Desktop.
send prowl alerts via m/monit
#!/usr/bin/env /usr/local/rvm/wrappers/ruby-1.9.2-p290@puppet/ruby
## Used by M/Monit to send prowl alerts
require 'rubygems'
require 'optparse'
# everyone's API keys
contact_info = {
"grant"=>{"key"=>"my_api_key"}
}
# Parse opts
options = {}
optparse = OptionParser.new do |opts|
opts.banner = "Usage: prowly.rb [-r|--recipient] [-e|--event] [-d|--description] [-p|--priority]"
options[:recipient] = nil
opts.on( '-r', '--recipient RECIPIENT', 'Who to message.' ) do |recipient|
options[:recipient] = recipient
end
options[:event] = nil
opts.on( '-e', '--event EVENT', 'Event title.' ) do |event|
options[:event] = event
end
options[:description] = nil
opts.on( '-d', '--description DESCRIPTION', 'Event description.' ) do |description|
options[:description] = description
end
options[:priority] = nil
opts.on( '-p', '--priority PRIORITY', 'Event priority' ) do |priority|
options[:priority] = priority.upcase
end
options[:application] = nil
opts.on( '-a', '--application APPLICATION', 'Application that triggered the event' ) do |application|
options[:application] = application
end
opts.on( '-h', '--help', 'Display this screen' ) do
puts opts
exit
end
end
optparse.parse!
# All opts are required
if options[:recipient] == nil
STDERR.puts "Must specify a recipient. Exiting."
abort
elsif options[:event] == nil
STDERR.puts "Must specify an event. Exiting."
abort
elsif options[:description] == nil
STDERR.puts "Must specify a description. Exiting."
abort
elsif options[:priority] == nil
STDERR.puts "Must specify a priority. Exiting."
abort
elsif options[:application] == nil
STDERR.puts "Must specify an originating application. Exiting."
abort
end
# Check that we have that contact's API key and fire the alert
if contact_info.has_key?("#{options[:recipient]}")
%x[prowly -k #{contact_info["#{options[:recipient]}"]['key']} -e "#{options[:event]}" -d "#{options[:description]}" -p "#{options[:priority]}" -a "#{options[:application]}"]
else
STDERR.puts "I can't find that contact! Exiting."
abort
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment