vadv / zabbixapi Goto Github PK
View Code? Open in Web Editor NEWRuby module for work with zabbix api
Ruby module for work with zabbix api
It looks like a recent refactor removed support for HTTP Basic auth.
Hi, when my zabbix version form 1.8 to 2.0.6 ,the template.mass_remove function do not work. it only delete the template info, but the item/stigger still exist.
For some reason the downloaded gem from rubygems.org still has the old version of zabbixapi.rb file and the gem errors out.
RuntimeError:
unknown Api version!
Here is the code:
case @client.api_version
when "1.3", "1.2"
apidir = "1.8"
when "2.0.4"
apidir = "2.0"
else
raise "unknown Api version!"
It appears that the create method will collapse lists/arrays and only keep the last value. For example, I was trying to add a host to multiple hostgroups:
hostid = zabbix.hosts.create_or_update(
:host => host.fqdn,
:interfaces => interfaces,
:groups => [ {:group_id => 1}, {:group_id =>2} ]
)
With debug turned on, I could see the call create with multiple group hashes in the params:
[DEBUG] Call create with parametrs: {:host=>"foo", :interfaces=>[{:type=>1, :main=>1, :ip=>"192.168.1.1", :dns=>"foo", :port=>10050, :useip=>0}], :groups=>[{:groupid=>"1"}, {:groupid=>"2"}]}
but then I would see the request being created with just the second id group id:
[DEBUG] Send request: {"method":"host.create","params":[{"host":foo","interfaces":[{"type":1,"main":1,"ip":"192.168.1.1","dns":"foo","port":10050,"useip":0}],"status":0,"available":1,"groups":[{"groupid":"2"}], "auth":"......................", "id":69893, "jsonrpc":"2.0"}
I think I tracked it down to the merge_params in basic_func.rb (i'm using 2.0, but I presume 1.8 is like this too). I think this line is what does it ...
JSON.parse(result.gsub('},{', ','))
If I understand, the intent here is to let JSON do the merging of the default and given params into a single JSON doc and then reparse it. But it picks up and does the substiution on lists of hashes for things like groups, templates, macros, etc. ... and leaves only one in the list.
I know this isn't a proper PR, but this seems to work for me (and it gets JSON out of the picture too ... might be a little faster.)
def stringify_keys(obj)
return obj.inject({}){|memo,(k,v)| memo[k.to_s] = stringify_keys(v); memo} if obj.is_a? Hash
return obj.inject([]){|memo,v | memo << stringify_keys(v); memo} if obj.is_a? Array
obj
end
def merge_params(params)
stringify_keys(default_options.merge(params))
end
I presume you were also using the JSON conversion for converting all the symbols to strings too. If I'm wrong about the reasoning behind the JSON maneuvers, then this works too:
def merge_params(params)
new_params = default_options.merge(params)
JSON.parse(JSON.generate(new_params).to_s)
end
When in instantiating ZabbixApi.connect in pry (an enhanced irb), I get the following exception.
zabbixapi-0.5.6/lib/zabbixapi/2.0/classes/triggers.rb:42: invalid regular expression; there's no previous pattern, to which '{' would define cardinality at 1: /{(\d_)}/
zabbixapi-0.5.6/lib/zabbixapi/2.0/classes/triggers.rb:47: invalid regular expression; there's no previous pattern, to which '{' would define cardinality at 1: /{._:/
No exception if I escape the curly braces and parens but I can't quite tell what was intended so escaping might be incorrect (at least in line 42).
ruby 1.8.7 (2012-06-29 patchlevel 370) [i686-darwin11.4.2]
Until someone releases ruby-1.9.3 rpms for the enterprise linux's they won't get newer than 1.8.7 if they can't use rvm
NoMethodError: undefined method use_ssl=' for #<#<Class:0x7f332fb12b78> zabbix.example.com:443 open=false> from /usr/lib64/ruby/gems/1.8/gems/zabbixapi-0.5.7/lib/zabbixapi/client.rb:55:in
http_request'
from /usr/lib64/ruby/gems/1.8/gems/zabbixapi-0.5.7/lib/zabbixapi/client.rb:77:in _request' from /usr/lib64/ruby/gems/1.8/gems/zabbixapi-0.5.7/lib/zabbixapi/client.rb:83:in
api_request'
from /usr/lib64/ruby/gems/1.8/gems/zabbixapi-0.5.7/lib/zabbixapi/client.rb:23:in auth' from /usr/lib64/ruby/gems/1.8/gems/zabbixapi-0.5.7/lib/zabbixapi/client.rb:35:in
initialize'
from /usr/lib64/ruby/gems/1.8/gems/zabbixapi-0.5.7/lib/zabbixapi.rb:22:in new' from /usr/lib64/ruby/gems/1.8/gems/zabbixapi-0.5.7/lib/zabbixapi.rb:22:in
initialize'
from /usr/lib64/ruby/gems/1.8/gems/zabbixapi-0.5.7/lib/zabbixapi.rb:10:in new' from /usr/lib64/ruby/gems/1.8/gems/zabbixapi-0.5.7/lib/zabbixapi.rb:10:in
connect'
from (irb):4
from /usr/lib64/ruby/1.8/x86_64-linux/rbconfig.rb:169
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.