Created
December 19, 2012 06:26
-
-
Save matsumotory/4334810 to your computer and use it in GitHub Desktop.
Sample: zabbix 2.0 API client for mruby
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
$cat mrbgems/g/mruby-zabbix/example/zabbix-api-client.rb | |
config = { | |
:url => "http://127.0.0.1/zabbix/api_jsonrpc.php", | |
:ua => "mruby-zabbix", | |
:user => "api-admin", | |
:pass => "api-admin", | |
} | |
z = Zabbix::Client.new(config) | |
data = { | |
:method => "get", | |
:object => "host", | |
:params => { | |
:output => "extend", | |
:filter => { | |
:host => "example.com", | |
}, | |
}, | |
} | |
puts "request: #{JSON::stringify(data)}" | |
puts "response: #{z.post(data)["body"]}" | |
$ mruby mrbgems/g/mruby-zabbix/example/zabbix-api-client.rb | |
request: {"object":"host","params":{"output":"extend","filter":{"host":"example.com"}},"method":"get"} | |
response: {"jsonrpc":"2.0","result":[{"maintenances":[],"hostid":"10085","proxy_hostid":"0","host":"example.com","status":"0","disable_until":"0","error":"","available":"1","errors_from":"0","lastaccess":"0","ipmi_authtype":"4","ipmi_privilege":"4","ipmi_username":"USERID","ipmi_password":"PASSW0RD","ipmi_disable_until":"0","ipmi_available":"0","snmp_disable_until":"0","snmp_available":"0","maintenanceid":"0","maintenance_status":"0","maintenance_type":"0","maintenance_from":"0","ipmi_errors_from":"0","snmp_errors_from":"0","ipmi_error":"","snmp_error":"","jmx_disable_until":"0","jmx_available":"0","jmx_errors_from":"0","jmx_error":"","name":"example"}],"id":2} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment