Created
May 21, 2012 20:59
-
-
Save dallasmarlow/2764651 to your computer and use it in GitHub Desktop.
nagios service commands
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
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