Last active
January 17, 2017 13:53
-
-
Save travisdmathis/3824375 to your computer and use it in GitHub Desktop.
This file contains 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.111" | |
@api="/zabbix/api_jsonrpc.php" | |
### Login Details | |
@user="user" | |
@pass="pass" | |
### JSON Auth_Token Data Block | |
@json_auth_data ={ | |
"jsonrpc" => "2.0", | |
"method" => "user.login", | |
"params" => {"user" => @user,"password" => @pass}, | |
"id" => "1" | |
}.to_json | |
### Collect auth_token and store as variable @auth_token | |
def authenticate | |
req = Net::HTTP::Post.new(@api, initheader = {'Content-Type' =>'application/json'}) | |
req.body = @json_auth_data | |
response = Net::HTTP.new(@server).start {|http| http.request(req) } | |
response.body | |
end | |
result = authenticate | |
auth = JSON.parse(result) | |
@auth_token = auth['result'] | |
pp @auth_token | |
### JSON Host_Create Data Block | |
@json_host_create_data ={ | |
"jsonrpc" => "2.0", | |
"method" => "host.create", | |
"params" => {"host" => "test", "interfaces" => [{ "type" => 1,"main" => 1,"useip" => 1,"ip" => "111.111.111.111", "dns" => "","port" => "10050" }],"groups" => [{"groupid" => "9"}],"templates" => [{"templateid" => "10001"}]}, | |
"auth" => @auth_token, | |
"id" => "1" | |
} | |
### Create Host in Zabbix | |
def create_host | |
req = Net::HTTP::Post.new(@api, initheader = {'Content-Type' =>'application/json'}) | |
req.body = @json_host_create_data | |
response = Net::HTTP.new(@server).start {|http| http.request(req) } | |
response.body | |
end | |
#### ERROR | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment