express42 / zabbixapi

Ruby wrapper to Zabbix API
MIT License
131 stars 128 forks source link

Action API (NoMethodError) #69

Closed sburns90 closed 7 years ago

sburns90 commented 7 years ago

I think there is a problem in the 'actions' section of this zabbixapi ruby wrapper. I have been trying to create an action using: zbx.actions.create

But I keep getting the following error:

1
10001
./action-template-test.rb:14:in `<main>': undefined method `actions' for #<ZabbixApi:0x000000020e44b0> (NoMethodError)

The first two numbers: 1 and 10001 I have displayed just so I know that I am actually connected to the server and able to run queries on it.

I get the same error if I run: zbx.action.create

Any ideas on what is going on or what I can do to get this to run?

Here is the code that I am running:

#!/usr/bin/env ruby

require "zabbixapi"

zbx = ZabbixApi.connect(
                :url => 'http://localhost/zabbix/api_jsonrpc.php',
                :user => 'Admin',
                :password => 'zabbix'
)

puts zbx.hostgroups.get_id( :name => "Templates")
puts zbx.templates.get_id( :host => "Template OS Linux" )

zbx.actions.create(
  :name => "Register ALL - Hosts",
  :eventsource => '2',                    # event source is a triggerid
  :status => '0',                         # action is enabled
  :esc_period => '120',                   # how long each step should take
  :filter => {
      :evaltype => '2',                   # perform 'and' between the conditions
      :conditions => [
          {
              :conditiontype => '22',
              :operator => '2',
              :value => '.'
          },
          {
              :conditiontype => '22',
              :operator => '2',
              :value => '-'
          }
      ]
  },
  :operations => [
      {
          :operationtype => '2'              # send message
      },
      {
          :operationtype => '6',
          :optemplate => [
                { :templateid => zbx.templates.get_id( :host => "Template OS Linux" ) },
                { :templateid => zbx.templates.get_id( :host => "Template Debian" ) }
          ]
      }
  ]
)
jrbeilke commented 7 years ago

Which version of the zabbixapi gem are you using @sburns90 ? I can't seem to replicate this with v3.0

sburns90 commented 7 years ago

OK. Well that is definitely a user error on my part. smh :( I just installed v3.0 and it worked flawlessly.

I originally installed v2.4.7 as the 1st paragraph in the readme led me to believe I needed the 2.4.x version.

3.0.x (api version 3.0.x) /zabbixapi 2.4.x master
3.2.x (api version 3.2.x) /zabbixapi 2.4.x master

This was reinforced when I saw install instructions of: gem install zabbixapi -v 2.4.7

May want to change that in the readme file.

Thanks for the help. Sorry about that.