Skip to content

Instantly share code, notes, and snippets.

@seungjin
Created January 1, 2012 04:51
Show Gist options
  • Save seungjin/1546284 to your computer and use it in GitHub Desktop.
Save seungjin/1546284 to your computer and use it in GitHub Desktop.
zabbix api connection
#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