Zabbix – Zabbix LLD using zabbix_sender

I have recently been looking into monitoring our backup solution using PowerShell and Zabbix. I came across a solution that kind of worked and was intermittent due to the script timing out, and upping the timeout also has other performance implications.

Looking at how the script worked it was producing some JSON that was then being parsed by Zabbix to provide the LLD.

Example of output (re-formatted)

{
	"data":[
		{
			"{#JOBID}":"3d2ddd75-7276-41d0-bce2-6c25fce5d1c9",
			"{#JOBNAME}":"A Backup Job",
			"{#JOBSCHEDULED}":"True"
		}
	]
}

To get LLD working with the zabbix_sender we need to be able to send the JSON to the Zabbix server. This is where the problems began as sending the JSON from the command line using the -o/--value option failed.

The way to get it to work is to get zabbix_sender to use a temporary input file and send the data that way.

To set this up, set your discovery rule so that the type is “Zabbix trapper”

Example

Zabbix Discovery Rule Screenshot

Then setup your script/program to output the required JSON into a temporary file formatted in the following way.

<hostname> <itemkey> <JSON/value>

E.g.

TestHost TestItem[Discover] {"data":[{"{#JOBID}":"3d2ddd75-7276-41d0-bce2-6c25fce5d1c9","{#JOBNAME}":""A Backup Job","{#JOBSCHEDULED}":"True"}]}

Or

- TestItem[Discover] {"data":[{"{#JOBID}":"3d2ddd75-7276-41d0-bce2-6c25fce5d1c9","{#JOBNAME}":""A Backup Job","{#JOBSCHEDULED}":"True"}]}

Note1: The JSON/value must be on the same line as the hostname and itemkey.
Note2: Specifying a “-” for the hostname uses the hostname from the configuration file or from the command line.

Once you have the temporary file above use zabbix_sender and execute it using one of the following command lines.

zabbix_sender -c <Zabbix Agent Config File> -i <Temporary File>
zabbix_sender -s <Host Name> -c <Zabbix Agent Config File> -i <Temporary File>
zabbix_sender -z <Zabbix Server IP/Hostname> -i <Temporary File>
zabbix_sender -s <Host Name> -z <Zabbix Server IP/Hostname> -i <Temporary File>

e.g.

zabbix_sender -c zabbix_agentd.conf -i C:\Temp\TestJSON.tmp
zabbix_sender -s TestHost -c zabbix_agentd.conf -i C:\Temp\TestJSON.tmp
zabbix_sender -z ZabbixServer -i C:\Temp\TestJSON.tmp
zabbix_sender -s TestHost -z ZabbixServer -i C:\Temp\TestJSON.tmp

Whilst testing I would suggest also adding the -vv option to the command line to get debugging information. For example I found that I had to add the -s option to the command line, as there seems to be a bug in the zabbix_sender code where it doesn’t use the HostnameItem when Hostname is undefined.

And last but not least the discovery prototypes need setting up within Zabbix, which I wont cover here as it’s covered in the Zabbix manuals.