Last active
December 14, 2016 13:55
-
-
Save danielhopkins/7569899 to your computer and use it in GitHub Desktop.
Revisions
-
danielhopkins revised this gist
Nov 21, 2013 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,5 @@ #!/usr/bin/env ruby require 'uri' require 'net/http' require "net/https" -
danielhopkins revised this gist
Nov 21, 2013 . 1 changed file with 13 additions and 10 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,6 @@ #!/usr/bin/env ruby require 'rubygems' require 'uri' require 'net/http' require "net/https" @@ -46,16 +45,20 @@ msg = ARGV[0] || "NO MESSAGE" entity_id = unless options[:entity].nil? ",\"entity_id\": \"#{options[:entity]}\"" end payload = <<-eos { "message_type": "#{options[:msg_type]}", "state_message": "#{msg}", "originating_host": "#{`hostname`.chomp}", "user": "#{`whoami`.chomp}" #{entity_id} } eos proto = options[:use_ssl] ? 'https' : 'http' @@ -64,7 +67,7 @@ https.use_ssl = options[:use_ssl] request = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'}) request.body = payload response = https.request(request) if response.code != '200' -
danielhopkins revised this gist
Nov 20, 2013 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,6 +4,7 @@ require 'json' require 'uri' require 'net/http' require "net/https" require 'optparse' url_path = "integrations/generic/20131114/alert" -
danielhopkins revised this gist
Nov 20, 2013 . 1 changed file with 38 additions and 37 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,62 +4,63 @@ require 'json' require 'uri' require 'net/http' require 'optparse' url_path = "integrations/generic/20131114/alert" options = {} opts = OptionParser.new do |opts| opts.banner = "Usage: vo -k APIKEY [options] msg" opts.on('-k n', '--key APIKEY', 'Api key (required)') do |v| options[:key] = v end options[:server] = 'alert.victorops.com' opts.on('-s', '--server SERVER_NAME', 'An alternate server to send alerts to.') do |v| options[:server] = v end options[:use_ssl] = true opts.on('--[no-]ssl', 'Enable men in the middle?') do |v| options[:use_ssl] = v end options[:msg_type] = :info opts.on('--type TYPE', [:info, :warning, :critical, :acknowledgement, :recovery], 'select message type (info, warning, critical, acknowledgement, recovery)') do |v| options[:msg_type] = v end opts.on('--entity ENTITY', 'entity id, used for incident aggregation') do |v| options[:entity] = v end end opts.parse! if options[:key].nil? puts 'Please specify an api-key' puts opts abort end msg = ARGV[0] || "NO MESSAGE" payload = { :message_type => options[:msg_type], :state_message => msg, :originating_host => `hostname`.chomp, :user => `whoami`.chomp } unless options[:entity].nil? payload[:entity_id] = options[:entity] end proto = options[:use_ssl] ? 'https' : 'http' uri = URI("#{proto}://#{options[:server]}/#{url_path}/#{options[:key]}/everyone") https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = options[:use_ssl] request = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'}) request.body = JSON.generate(payload) -
danielhopkins created this gist
Nov 20, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,73 @@ #!/usr/bin/env ruby require 'rubygems' require 'json' require 'uri' require 'net/http' # Create a .vorc in your homedirectory. # The format of the file is json and has keys # { # "api_key": "xxxx-xxxx-xxxx-xxxx", # "use_ssl": true # } config_file = "#{ENV['HOME']}/.vorc" url_path = "integrations/generic/20131114/alert" unless File.exists?(config_file) puts "No config file, please create a .vorc in your home directory" exit 1 end config = begin JSON.parse(IO.read(config_file)) rescue puts "vorc needs to contain json." exit 1 end api_key = if config.key?('api_key') config['api_key'] else puts 'Please a key "api_key" in your .vorc' exit 1 end server = if config.key?('server') config['server'] else 'alert.victorops.com' end use_ssl = if config.key?('use_ssl') config['use_ssl'] else true end msg = ARGV[0] payload = { :message_type => 'INFO', :state_message => msg, :originating_host => `hostname`.chomp, :user => `whoami`.chomp } proto = use_ssl ? 'https' : 'http' uri = URI("#{proto}://#{server}/#{url_path}/#{config['api_key']}/everyone") https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = use_ssl request = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'}) request.body = JSON.generate(payload) response = https.request(request) if response.code != '200' puts "POST failed with #{response.body}" exit 1 else exit 0 end