Sending in the data

In some cases, there might be custom data sources where none of the previously discussed methods would work sufficiently well. A script could run for a very long time, or we could have a system without the Zabbix agent but with the capability to push data. Zabbix offers a way to send data to a special item type, Zabbix trapper, using a command-line utility, Zabbix sender. The easiest way to explain how it works might be to set up a working item like that:

  1. Navigate to Configuration | Hosts, click on Items next to A test host, click on Create item, then fill in the following:
    • Name: Amount of persons in the room
    • Type: Zabbix trapper
    • Key: room.persons
  1. When you're done, click on the Add button at the bottom.

We now have to determine how data can be passed into this item, and this is where zabbix_sender comes in. On the Zabbix server, execute the following:

$ zabbix_sender --help
If you've installed from a distribution, then zabbix_sender needs to be installed first from the repository.

We won't reproduce the output here, as it's somewhat lengthy. Instead, let's see which parameters are required for the most simple operation, sending a single value from the command line:

  • -z is to specify the Zabbix server
  • -s is to specify the hostname, as configured in Zabbix
  • -k is for the key name
  • -o is for the value to send

Note that the hostname is the hostname in the Zabbix host properties—not the IP, not the DNS, and not the visible name. Let's try to send a value:

$ zabbix_sender -z 127.0.0.1 -s "A test host" -k room.persons -o 1  
As usual, the hostname is case sensitive. The same applies to the item key.

This command should succeed and show the following output:

info from server: "processed: 1; failed: 0; total: 1; seconds spent: 0.000046"
sent: 1; skipped: 0; total: 1  
If you're very quick with running this command after adding the item, the trapper item might not be in the Zabbix server configuration cache. Make sure to wait at least one minute after adding the item.

Let's send another value—again using zabbix_sender:

$ zabbix_sender -z 127.0.0.1 -s "A test host" -k room.persons -o 2

This one should also succeed, and now we should take a look at Monitoring | Latest data over at the frontend. We can see that the data has successfully arrived and the change is properly recorded:

Now we could try being smart. Let's pass a different data type to Zabbix:

$ zabbix_sender -z 127.0.0.1 -s "A test host" -k room.persons -o nobody

We're now trying to pass a string to the Zabbix item even though, in the frontend, its data type is set to an integer:

info from server: "processed: 0; failed: 1; total: 1; seconds spent: 0.000074"
sent: 1; skipped: 0; total: 1
  

Zabbix didn't like that, though. The data we provided was rejected because of the data type mismatch, so it's clear that any process that's passing the data is responsible for the data contents and formatting.

Now, security-concerned people would probably ask—who can send data to items of the trapper type? zabbix_sender can be run on any host by anybody, and it's enough to know the hostname and item key.

It's possible to restrict this in a couple of ways—for one of them, see Configuration | Hosts, click on Items next to A test host, and click on Amount of persons in the room in the Name column. Look at one of the last few properties, Allowed hosts. We can specify an IP address or DNS name here, and any data for this item will be allowed from the specified host only:

Several addresses can be supplied by separating them with commas. In this field, user macros are supported as well. We discussed user macros in Chapter 8, Simplifying Complex Configurations with Templates.

Another option to restrict who can send the data to trapper items is by using the authentication feature with PSK or SSL certificates. That's discussed in Chapter 18, Encrypting Zabbix Traffic.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.185.180