Created
October 2, 2012 22:26
-
-
Save travisdmathis/3823722 to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env ruby | |
| require 'net/http' | |
| require 'rubygems' | |
| require 'json' | |
| require 'pp' | |
| ### Server Details | |
| @server="198.61.203." | |
| @api="/zabbix/api" | |
| ### Login Details | |
| @user="admin" | |
| @pass="" | |
| @json_auth_data ={ | |
| "user" => @user, | |
| "password" => @pass, | |
| "id" => "1" | |
| }.to_json | |
| def authenticate | |
| req = Net::HTTP::Post.new(@api, initheader = {'Content-Type' =>'application/json'}) | |
| req.basic_auth @user, @pass | |
| req.body = @json_auth_data | |
| response = Net::HTTP.new(@server).start {|http| http.request(req) } | |
| puts "Response #{response.code} #{response.message}: | |
| #{response.body}" | |
| end | |
| auth = authenticate | |
| pp auth | |
| ############ ERROR ################ | |
| Response 301 Moved Permanently: | |
| <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> | |
| <html><head> | |
| <title>301 Moved Permanently</title> | |
| </head><body> | |
| <h1>Moved Permanently</h1> | |
| <p>The document has moved <a href="http://198.61.203./zabbix/api/">here</a>.</p> | |
| <hr> | |
| <address>Apache/2.2.22 (Ubuntu) Server at 198.61.203. Port 80</address> | |
| </body></html> | |
| nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment