zbxapi example?

561 views
Skip to first unread message

dan

unread,
Mar 1, 2012, 11:28:13 AM3/1/12
to zab...@googlegroups.com
Thanks for your work on the Zabbix API.

Can you point me to simple examples of Ruby code using the zbxapi gem? I did a little googling and didn't see anything.

Probably zabcon uses it, but a) that's a large beast, b) it doesn't work on my system (OS X, lion):

Unable to find a default configuration file
x86_64-darwin11.2.0
Runtime error detected
(RuntimeError): Unbalanced String: help commands

Top 10 items in backtrace
1: /Users/foo/.rvm/gems/ruby-1.9.3-p0/gems/zabcon-0.0.370/libs/utility_items.rb:101:in `split2'
...

dan

unread,
Mar 1, 2012, 11:38:14 AM3/1/12
to zab...@googlegroups.com
I see zbxapi.rb can be run as a command-line program. However, when I try it throws an error (see below).

$ ruby /Users/foo/.rvm/gems/ruby-1.9.3-p0/gems/zbxapi-0.1.369/zbxapi.rb 
Performing login
/Users/foo/.rvm/gems/ruby-1.9.3-p0/gems/zbxapi-0.1.369/zbxapi.rb:101:in `initialize': undefined method `+' for #<ZabbixAPI:0x00000104857988> (NoMethodError)
from /Users/foo/.rvm/gems/ruby-1.9.3-p0/gems/zbxapi-0.1.369/zbxapi.rb:102:in `new'
from /Users/foo/.rvm/gems/ruby-1.9.3-p0/gems/zbxapi-0.1.369/zbxapi.rb:102:in `initialize'
from /Users/foo/.rvm/gems/ruby-1.9.3-p0/gems/zbxapi-0.1.369/zbxapi.rb:344:in `new'
from /Users/foo/.rvm/gems/ruby-1.9.3-p0/gems/zbxapi-0.1.369/zbxapi.rb:344:in `<top (required)>'
from /Users/foo/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/foo/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/foo/.rvm/gems/ruby-1.9.3-p0/gems/zbxapi-0.1.369/api_classes/subclass_base.rb:27:in `<top (required)>'
from /Users/foo/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/foo/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/foo/.rvm/gems/ruby-1.9.3-p0/gems/zbxapi-0.1.369/api_classes/application.rb:27:in `<top (required)>'
from /Users/foo/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/foo/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/foo/.rvm/gems/ruby-1.9.3-p0/gems/zbxapi-0.1.369/zbxapi.rb:48:in `<main>

Andrew Nelson

unread,
Mar 1, 2012, 12:06:09 PM3/1/12
to zab...@googlegroups.com
Zabcon is the program the Gem was designed for, however there are some examples in the test cases found here:
http://trac.red-tux.net/browser/trunk/ruby/api/api_tests

You can call the gem by:

require "zbxapi"

server = ZabbixAPI.new("http://zabbix.example.com")
server.login(<user>,<password>)

result=server.user.get({"extendoutput"=>true,"limit"=>100})

If there is not direct coverage of the API in the library you can directly access the API:

The following follows the following api example:
http://www.zabbix.com/documentation/1.8/api/map/get
server.raw_api("map.get",{"filter"=>{"name"=>["zabbix"]},
   "select_selements"=>"extended",
   "select_links"=>"extend",
   "output"=>"extend"})

Most of my development of Zabcon is done on Mac and Linux (Fedora) using Ruby 1.8.7.
--
You received this message because you are subscribed to the Google Groups "Zabcon" group.
To view this discussion on the web visit https://groups.google.com/d/msg/zabcon/-/LX4mqfg84OUJ.
To post to this group, send email to zab...@googlegroups.com.
To unsubscribe from this group, send email to zabcon+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/zabcon?hl=en.

Dan F

unread,
Mar 1, 2012, 1:42:43 PM3/1/12
to zab...@googlegroups.com
Thanks for your reply.

I suspect neither zabcon.rb nor zbxapi.rb work with Ruby 1.9.3. Since 1.9.3 was released Oct 2011 and is rumored to be "100% compatible" with upcoming Ruby 2.0, I am unlikely to move backwards.

I have hacked pieces out of zbxapi.rb and gotten a simple raw_api() working for me. I can make that script available if desired. Now I have to learn the Zabbix model well enough to ask it for data. Pointers welcome.
Reply all
Reply to author
Forward
0 new messages