Created
January 1, 2012 04:51
-
-
Save seungjin/1546284 to your computer and use it in GitHub Desktop.
zabbix api connection
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
#curl -i -X POST -H 'Content-Type: application/json' -d '{"params": {"password": "mypassword", "user": "myuser"}, "jsonrpc": "2.0", "method": "user.authenticate"}' http://0.0.0.0/zabbix/api_jsonrpc.php | |
require 'net/http' | |
require 'json' | |
def post | |
host = '0.0.0.0' | |
port = '80' | |
path = '/zabbix/api_jsonrpc.php' | |
data = { | |
"jsonrpc" => "2.0", | |
"method" => "user.authenticate", | |
"params" => { | |
"user" => "myuser", | |
"password" => "mypassword" | |
} | |
}.to_json | |
req = Net::HTTP::Post.new(path, initheader = {'Content-Type' =>'application/json'}) | |
req.body = data | |
response = Net::HTTP.new(host, port).start {|http| http.request(req) } | |
#puts "Response #{response.code} #{response.message}: #{response.body}" | |
if response.code == '200' | |
return response['set-cookie'] | |
end | |
end | |
thepost = post | |
puts thepost.split(", ")[0].split("=")[1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment