Create an external script for Zabbix

Create a script that will collect the data. The script MUST be placed in the location specified in zabbix_server.conf as "ExternalScripts=/some/path". I generally change that to /opt/zabbix. I generally store it in a tab delimited file in the format:


From Zabbix, you can create a sensor that will call the script

  1. Configuration | Hosts
  2. Select the Host
  3. Select Items
  4. Create a new item
  5. Give it a name
  6. Set Type to External Check
  7. For Key, call the name of the script, with parameters in squre brackets (and surrounded by quotes). Thus
    Means call the script named getPDU, with the first parameter pdu1, and the second average. In this case, I'm telling the script I want to read the Average current from pdu1
  8. Fill in the rest of the values as you like. After a while, you will be able to see your values show up.

NOTES: You can graph these values. Just select the items from the list.

You can also use the values in calculated fields, but the syntax is a little strange. For example, if you wanted to multiply voltage by average current (to get power), you have to wrap both parameters in curly braces, and you have to make the system call again, ie


NOTE: to make things more portable, you can use the {HOSTNAME} macro in your definitions, ie


this way, when you want to monitor, say pdu2, you can simply clone pdu1 and change the name.

Real World

Now, how this whole pdu1 and pdu2 thing came about. I had a problem with some very old hardware (APC AP7940) which has totally broken SNMP; you not read the power history with snmp om these. So, I did a kludge. I found they could simply ftp the data log every hour, so I set up a place where it could ftp the data log to, then I wrote a Perl script to process that log.

Pretty basic; I had a key telling me the last log entry I had read, and when I opened the log file the next time, I scanned until I found that entry, then started processing the data after that. I got min, max and a bunch of values which I averaged. I took these and stored them in a data file

min   value
max   value
average  value
count value

stuff like that, where value was what I calculated by processing the log file. Since the AP7940 will only send the log file a minimum of once per hour, I should have 12 new values in each log (I'm saving the values every 5 minutes in the unit).

Now, when Zabbix makes the call, the External script (getPDU) simply opens the summary file I created and finds the line that contains the value I need. Thus, for average, it looks for the line that starts with 'average' and returns the value on the other side of the tab.

Again, pretty much of a kludge, and I only have the granularity of 1 hour, but hey, it works and I'm reading my values.

I've attached the two scripts to this FAQ, however they are poorly documented and sloppily written. For one thing, they should be one script combined as I've done on some other things. I'll work on that. However, they are free for anyone to do anything they want to with.

WARNING: The APC will not overwrite a file when doing the ftp transfer. My solution was to move the log file to .old when I had read it, allowing the PDU to overwrite it again.

Attached files: getPDU, processPDU

Tags: external script, zabbix
Last update:
2015-07-22 06:24
Average rating: 4 (2 Votes)

You can comment this FAQ

Chuck Norris has counted to infinity. Twice.