Sha256: 9363d9ae7172342db56fc209e6a37e27ed2021dfba43a0fe88b589f3983a031f
Contents?: true
Size: 1.8 KB
Versions: 21
Compression:
Stored size: 1.8 KB
Contents
#!/usr/bin/env ruby RUBIX_ROOT = File.expand_path('../../lib', __FILE__) $: << RUBIX_ROOT unless $:.include?(RUBIX_ROOT) require 'rubix' require 'configliere' Settings.use :commandline Settings.use :env_var Settings.define :pretty, :description => "Pretty print output", :required => true, :type => :boolean, :default => false Settings.define :url, :description => "URL for the Zabbix API", :required => true, :default => 'http://localhost/api_jsonrpc.php' Settings.define :username, :description => "Username for the Zabbix API", :required => true, :env_var => "ZABBIX_API_USERNAME", :default => 'admin' Settings.define :password, :description => "Password for the Zabbix API", :required => true, :env_var => "ZABBIX_API_PASSWORD", :default => 'zabbix' Settings.define :server_error_sleep, :description => "Seconds to sleep after a 50x error from the server", :required => true, :type => Integer, :default => 1 def Settings.usage %Q{usage: #{raw_script_name} [...--param=val...] METHOD PARAMS} end begin Settings.resolve! rescue RuntimeError => e puts e.message Settings.dump_help exit(1) end if Settings.rest.size < 2 Settings.dump_help exit(1) end method = Settings.rest[0] json_params = Settings.rest[1] begin Rubix.connect(Settings[:url], Settings[:username], Settings[:password]) params = JSON.parse(json_params) response = Rubix.connection.request(method, params) if Settings[:pretty] puts JSON.pretty_generate(response.parsed) else puts response.parsed.to_json end rescue JSON::ParserError => e puts "Invalid JSON -- #{e.message}" exit(1) rescue Rubix::Error => e puts e.message exit(1) end
Version data entries
21 entries across 21 versions & 1 rubygems