How to use CSV module of Zaf

Do you have lot of devices and you want to monitor them not only physically but from inventory point of view?

Do you have CMDB and you want to correlate data from it into Zabbix? Zaf CSV plugin is here for you!

This example will show how to use this plugin and demonstrate its capabilities.

Let us use example CSV file devices.csv which contains data

Name,Primary IP,Type,Status,OS,OS Version,Platform
host1,1.2.3.4,server,verified,Windows,10,win64
host2,2.3.4.5,server,verified,Ubuntu,14.4,linux64
host3,2.3.4.6,workstation,verified,Ubuntu,14.4,linux64

Format of CSV file is not important because CSV module can select any column of it so it is highly customizable.

Now we want to create all this devices in Zabbix. To do so, we have to create auto registration action in Zabbix frontend. Best way how to do it is to use some specific metadata to be able to classify discovered hosts into right groups and templates. You can find more info about hosts autoregistration in Zabbix manual pages. Let us use metadata value "ZAF".

Now we want to do magic. Zaf csv register will read data from devices.csv and get field 'Name' from it. For each line it will try to register host with name (lowercased) and metadata 'ZAF'. Metadata can be any column too, using some of macros below.

zaf install csv

zaf csv register
Missing arguments!
register file.csv delim host metadata
host and metadata are strings where:
{COLUMN:x} is replaced by value of column x
{column:x} is replaced by lowercased value of column x
x can be column index (x starts with zero) or header name.
CSV must include header line.

zaf csv register devices.csv ',' {column:Name} ZAF

# To use more sophisticated action, you can prepend hosts with some prefix or append some postfix. Macros are powerful! 

#zaf csv register devices.csv ',' test_{column:Name} ZAF
#zaf csv register devices.csv ',' {column:Name}_postfix ZAF

#To use metadata specific per host (to classify by OS)
#zaf csv register devices.csv ',' test_{column:Name} 'ZAF:{column:OS}'




If autoregistration process is OK, we should see all hosts in Zabbix frontend with needed templates linked in. For our example, you have to define two trapper items for that hosts with name os and platform. Of course you can create your own keys and templates.

Next to this, we want to show data generated from CSV suitable for zabbix_sender.

zaf csv send
Missing arguments!
send file.csv delim mode hostfield [item1=field1] [item2=field2] ...
mode is stdout or send,
hostfield is host for item to send,
itemx is key for item to send,
fieldx is data to send send,
In hostfield, itemx and fieldx are replaced this macros:
{COLUMN:x} is replaced by value of column x
{column:x} is replaced by lowercased value of column x
x can be column index (x starts with zero) or header name.
CSV must include header line.

zaf csv send data.csv ',' 'stdout' {COLUMN:Name} 'os={column:OS}' 'platform=Platform'

host1 os windows
host1 platform Platform
host2 os ubuntu
host2 platform Platform
host3 os ubuntu
host3 platform Platform

If data seems to be OK (format host key value), it is almost done:


zaf csv send data.csv ',' 'send' {COLUMN:Name} 'os={column:OS}' 'platform=Platform'

And all data will be sent into Zabbix. Of cource, you can do automatic inventory with this tool and you can run it in regular intervals with cron.

Enjoy!

:)

 

Recent comments

No comments available.

Who's new

  • radimk
  • limo