Skip to content

Zabbix Sender and Trapper

Video Lecture

Zabbix Sender and Trapper

Description

zabbix_sender is a command line utility for sending data to Zabbix server.

You don't need to have Zabbix server, proxy or an agent running on the same OS to use the zabbix_sender utility, but you do need to make sure you have the correct version for your operating system.

Download the appropriate Zabbix version and repository for your operating system. I am using Zabbix 6 LTS on Ubuntu 20.04.

wget https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.0-1+ubuntu20.04_all.deb
dpkg -i zabbix-release_6.0-1+ubuntu20.04_all.deb
apt update

Now to install the zabbix_sender executable.

sudo apt install zabbix-sender

For help use

zabbix_sender -h

zabbix_sender is used to send data to your Zabbix server and can be called from either the command line or from a scripting language capable of running shell commands.

Example,

zabbix_sender -z 127.0.0.1 -s "Linux DB3" -k db.connections -o 43

On Zabbix, you need to create a host and add a Zabbix Trapper item to receive and process the zabbix_sender message.

Then you can use the zabbix_sender binary to send data to that trapper item any time you need.

Example Sender and Trapper script

This script will generate a new random number every second and send it to a host configured on Zabbix server.

1st create a new item on your host using the Zabbix UI.

Property Value
Name rnd
Type Zabbix Trapper
key rnd
Type of information Numeric (unsigned)

We can test the new Zabbix Trapper item,

zabbix_sender -z <Zabbix server/proxy IP or Domain name> -s "<host name as written in Zabbix>" -k rnd -o 123

Next create a new python script

sudo nano rnd.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
import subprocess
import random
import time

while 1:
    rnd = random.randint(0, 100)

    cmd = 'zabbix_sender -z <Zabbix Server/Proxy IP or Domain name> -s "<Host name in Zabbix UI>" -k rnd -o ' + str(rnd)
    print(cmd)

    process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
    output, error = process.communicate()
    print(output)

    time.sleep(1)

Start it

python3 rnd.py

Troubleshooting

Error "processed: 0; failed: 1; total: 1;"

Q. You try Zabbix Sender and you get processed: 0; failed: 1; total: 1;

A. There are many reasons. Have a break, come back after an hour and double check everything. Add the -vv option to your query to show a more verbose error message. I.e.,

zabbix_sender -vv -z <Zabbix Server/Proxy IP or Domain name> -s "<host name as written in Zabbix>" -k rnd -o 123

Zabbix Agent is monitored by proxy

Q. The Zabbix Agent where the trapper item exists, is monitored by proxy.

A. Don't use the parameter -z <Zabbix SERVER IP or Domain name>, but -z <Zabbix PROXY IP or Domain name>.

Also make sure your Zabbix proxy is aware of the new Zabbix trapper item for the host that it is monitoring by refreshing the proxies' config cache.

sudo zabbix_proxy -R config_cache_reload

Invalid Value Type

Q. The Zabbix UI shows an error similar to Value of type "string" is not suitable for value type "Numeric (unsigned)".

A. Your Trapper item is set to Numeric (Unsigned), but you sent it a float, string, or negative number.

Comments