Skip to content

Instantly share code, notes, and snippets.

@dallasmarlow
Created May 21, 2012 20:59
Show Gist options
  • Save dallasmarlow/2764651 to your computer and use it in GitHub Desktop.
Save dallasmarlow/2764651 to your computer and use it in GitHub Desktop.
nagios service commands
require 'net/https'
require 'uri'
config = {
nagios: {
url: 'https://nagios.domain.tld/nagios/cgi-bin/cmd.cgi',
auth: ['user', 'password'], # basic auth
command_types: [22, 23], # enable / disable
},
retry_limit: 3,
}
uri = URI.parse config[:nagios][:url]
http = Net::HTTP.new uri.host, uri.port
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
post = Net::HTTP::Post.new uri.request_uri
post.basic_auth *config[:nagios][:auth]
post.set_form_data :cmd_typ => config[:command_types].first, # enable
:cmd_mod => 2,
:host => host,
:service => service,
:btnSubmit => 'Commit'
http.request post
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment