Home > HOWTOs > Zabbix Item Creation using OID and Name CSV files.

Zabbix Item Creation using OID and Name CSV files.

This script is to create a xml import file from a csv file.
We use 2 csv file for this.
  1. First is the OID csv file. This OID file will contain all the range of OIDs which can be configured on the device. OID CSV will be similar to the CSV sample given below.
  2. Information (Name) configured in those OIDs above, with index. This file contains all the configuration information done on the device. Will give the index of the configured variable.

CSV format as below

Below is the OID csv file. (We will called it OID CSV File)
module_name oid_name oid datatype start end description
voip_destination status string 0 1000 some description
voip_destination flags string 0 1000 some description
voip_destination type string 0 1000 some description
Here is the sample csv output for the above file.
voip_destination,status,,string,0,1000,some description
voip_destination,flags,,string,0,1000,some description
voip_destination,type,,string,0,1000,some description
Below is name (configured) oid information, in the OIDs above. (We will called it NAME CSV File).
We use the name_table.module-name below to join with the table above with oid_table.module_name.
module_name index name
voip_destination 0 test_data_44test
linkset 1 test_data_44tes
ip 0 test_datatest
Here is the sample csv output for the above file.


usage: zabbix_items_from_csv.py [-h] -o CSV_OID -c CSV_NAME -n HOST_NAME -g

This script is to Generate xml import file for Zabbix from CSV files.We need
two CSV files.1. OID file, gives all the OIDs in the device.2. Name file,
gives all names configured for the above OIDs in the Device.

Example : python -o oid_list_with_range_processed.csv -c oid_names_configured.csv -n

optional arguments:
-h, --help show this help message and exit
-o CSV_OID, --csv-oid CSV_OID
OID file, Gives all OIDs on the device
-c CSV_NAME, --csv-name CSV_NAME
Name file, gives all names configured for the above
OIDs in the Device.
-n HOST_NAME, --host-name HOST_NAME
Host name as given in Zabbix server.
-g HOST_GROUP, --host-group HOST_GROUP
Host Group which the host belongs to, as in Zabbix
SNMP Interface configured on Zabbix server. (Assuming
Single Interface in Configured)
Application Name in the Zabbix Server. (To organize
all items being imported)
-y, --only-name Create xml items which are present in the name file.
i.e create items which are configured in the device
already, Rest of the OIDs are Ignored. [Default :
-f, --include-first-line
Include First line (Header) in the CSV file input,
[Default : False]

Code Usage :

import zabbix_items_from_csv

# Limit reading to first 10 Lines.
complete_list_dict_device_1 = zabbix_items_from_csv.reader_csv_file('oid_list_with_range_processed.csv', 10)
complete_list_name_dict_device_1 = zabbix_items_from_csv.read_csv_name_module('oid_names.csv')
dict_device_1 = zabbix_items_from_csv.merge_csv_data(complete_list_dict_device_1, complete_list_name_dict_device_1, True)
xml_tree_string_device_1 = zabbix_items_from_csv.\
'', 'DEVICE_1')
zabbix_items_from_csv.xml_pretty_me('BLR-DEVICE_1.xml', xml_tree_string_device_1)
xml_tree_string_device_1 = zabbix_items_from_csv.\
'', 'DEVICE_1')
zabbix_items_from_csv.xml_pretty_me('CHN-DEVICE_1.xml', xml_tree_string_device_1)

# Read all the lines from the csv file.
complete_list_dict_device_2 = zabbix_items_from_csv.reader_csv_file('oid_list_with_range_processed.csv')
complete_list_name_dict_device_2 = zabbix_items_from_csv.read_csv_name_module('oid_names.csv')
dict_device_2 = zabbix_items_from_csv.merge_csv_data(complete_list_dict_device_2, complete_list_name_dict_device_2)
xml_tree_string_device_2 = zabbix_items_from_csv.\
'', 'DEVICE_2')
zabbix_items_from_csv.xml_pretty_me('BLR-DEVICE_2.xml', xml_tree_string_device_2)
xml_tree_string_device_2 = zabbix_items_from_csv.\
'', 'DEVICE_2')
zabbix_items_from_csv.xml_pretty_me('CHN-DEVICE_2.xml', xml_tree_string_device_2)

Code Location

Categories: HOWTOs
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: