If Exists, find_or_create returns error. #7

Open
rvalente opened this Issue Aug 21, 2012 · 4 comments

Comments

Projects
None yet
2 participants
Contributor

rvalente commented Aug 21, 2012

In this example I will use IRB to connect and create a HG that does not exist. Then I will back out of IRB, run it again, and it will error out.

pry> host_group = Rubix::HostGroup.find_or_create(:name => "My Zabbix Hosts")
=> #<Rubix::HostGroup:0x105a4ffa0
 @id=44,
 @name="My Zabbix Hosts",
 @properties={:name=>"My Zabbix Hosts"}>

Exit out of IRB

pry> exit

Hop back into IRB and run the same command again after connecting.

pry> host_group = Rubix::HostGroup.find_or_create(:name => "My Zabbix Hosts")
NoMethodError: undefined method `map' for nil:NilClass
Owner

dhruvbansal commented Aug 21, 2012

I cannot reproduce this. What Rubix version are you using? Here's a pry session with latest:


dhruv@silicon:/p/i/rubix$ pry -e 'require "rubix" ; Rubix.connect("http://localhost:8080/api_jsonrpc.php", "admin", "zabbix")'
=> #<Rubix::Connection:0x00000001f982f0
 @password="zabbix",
 @request_id=0,
 @server=#<Net::HTTP localhost:8080 open=false>,
 @uri=#<URI::HTTP:0x00000001f97d00 URL:http://localhost:8080/api_jsonrpc.php>,
 @username="admin">
[2] pry(main)> host_group = Rubix::HostGroup.find_or_create(:name => "My Zabbix Hosts")
host_group = Rubix::HostGroup.find_or_create(:name => "My Zabbix Hosts")
I, [2012-08-21T12:18:27.832025 #6322]  INFO -- : Created Zabbix HostGroup My Zabbix Hosts
=> #<Rubix::HostGroup:0x00000001f92648
 @id=409,
 @name="My Zabbix Hosts",
 @properties={:name=>"My Zabbix Hosts"}>
[3] pry(main)> exit
exit
dhruv@silicon:/p/i/rubix$ pry -e 'require "rubix" ; Rubix.connect("http://localhost:8080/api_jsonrpc.php", "admin", "zabbix")'
=> #<Rubix::Connection:0x000000022f0bc8
 @password="zabbix",
 @request_id=0,
 @server=#<Net::HTTP localhost:8080 open=false>,
 @uri=#<URI::HTTP:0x000000022f0128 URL:http://localhost:8080/api_jsonrpc.php>,
 @username="admin">
[2] pry(main)> host_group = Rubix::HostGroup.find_or_create(:name => "My Zabbix Hosts")
host_group = Rubix::HostGroup.find_or_create(:name => "My Zabbix Hosts")
=> #<Rubix::HostGroup:0x000000022eb038
 @host_ids=[],
 @id=409,
 @name="My Zabbix Hosts",
 @properties={:id=>409, :name=>"My Zabbix Hosts", :host_ids=>[]}>
[3] pry(main)> 
Contributor

rvalente commented Aug 21, 2012

I am running the latest stable version of Rubix.

$gem search rubix
rubix (0.5.13)

What version of Zabbix are you using?
I am running Zabbix Server 2.0.2 (Latest Stable)

Thanks,
Ron

Contributor

rvalente commented Aug 21, 2012

Here is your exact pry session in my environment.

No Host Group named "My Zabbix Hosts".

$ pry -e 'require "rubix" ; Rubix.connect("http://zabbix/api_jsonrpc.php", "admin", "password")'
=> #<Rubix::Connection:0x007fe932cd3d90
 @password="password",
 @request_id=0,
 @server=#<Net::HTTP zabbix:80 open=false>,
 @uri=
  #<URI::HTTP:0x007fe932cd3a70 URL:http://zabbix/api_jsonrpc.php>,
 @username="admin">
[2] pry(main)> host_group = Rubix::HostGroup.find_or_create(:name => "My Zabbix Hosts")
I, [2012-08-21T13:38:28.626185 #24547]  INFO -- : Created Zabbix HostGroup My Zabbix Hosts
=> #<Rubix::HostGroup:0x007fe932906f28
 @id=45,
 @name="My Zabbix Hosts",
 @properties={:name=>"My Zabbix Hosts"}>
[3] pry(main)> exit

Now Host Group "My Zabbix Hosts" exists.

$ pry -e 'require "rubix" ; Rubix.connect("http://zabbix/api_jsonrpc.php", "admin", "password")'
=> #<Rubix::Connection:0x007f89dbce2400
 @password="password",
 @request_id=0,
 @server=#<Net::HTTP zabbix:80 open=false>,
 @uri=
  #<URI::HTTP:0x007f89dbcf7b20 URL:http://zabbix/api_jsonrpc.php>,
 @username="admin">
[2] pry(main)> host_group = Rubix::HostGroup.find_or_create(:name => "My Zabbix Hosts")
NoMethodError: undefined method `map' for nil:NilClass
from /Users/userid/.rvm/gems/ruby-1.9.3-p194/gems/rubix-0.5.13/lib/rubix/models/host_group.rb:51:in `build'
[3] pry(main)>
Owner

dhruvbansal commented Aug 21, 2012

Oh man! I bet it's the Zabbix server version! I've only ever tested Rubix with Zabbix <2.0. There are some serious changes to the API introduced in 2.0 that Rubix doesn't know how to deal with.

It's on my plate for Rubix 0.6 to support Zabbix 2.0 but it's not happened yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment