Michael Spector
Michael Spector

Reputation: 37009

How to create a new Zabbix event from Ruby script?

Is this possible to generate a new Zabbix event from a Ruby script? I was suggested to use zabbix_sender script, but I couldn't find any example.

Also, I couldn't find any API related to the events creation.

Upvotes: 0

Views: 1800

Answers (2)

riemann
riemann

Reputation: 565

Zabbix API does not allow item value updates by design.

I have investigated couple options* and my preferred way to update Zabbix item value from Ruby is using this approach found in miyucy's gist:

Example with simple error handler:

s = Zabbix::Sender.new 'zabbix_server', 10051

zabbix_resp = s.send('host', item_key, value)

if zabbix_resp["response"] != "success" or zabbix_resp["info"].split(';')[1] != " failed: 0"
  puts "error: zabbix responded with #{zabbix_resp} when trying to update #{item_key}"
end

*One example of alternative way - calling zabbix_sender binary

Upvotes: 1

nudzo
nudzo

Reputation: 18574

First of all create some item of type zabbix trapper and then you can send some values to its name by zabbix_sender. You can send one value, or more collected data with timestamps. Here are docs.

Alternatively you can write own zabbix trap sender. Protocol is quite easy. I done the same in Python... no external commands.

Upvotes: 1

Related Questions