Skip to main content

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 1.3.6.1.2.1.2.2.18.0 string 0 1000 some description
voip_destination flags 1.3.6.1.2.1.2.2.18.1 string 0 1000 some description
voip_destination type 1.3.6.1.2.1.2.2.18.2 string 0 1000 some description
Here is the sample csv output for the above file.
module_name,oid_name,oid,datatype,start,end,description
voip_destination,status,1.3.6.1.2.1.2.2.18.0,string,0,1000,some description
voip_destination,flags,1.3.6.1.2.1.2.2.18.1,string,0,1000,some description
voip_destination,type,1.3.6.1.2.1.2.2.18.2,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.
module_name,TEST_DATAdex,TEST_DATAmTEST
Linkset,0,TEST_DATA_44TEST
Linkset,1,TEST_DATA_44TEST
IP,0,TEST_DATATEST
IP,1,TEST_DATAlTEST
IP,2,TEST_DATAteTEST

USAGE

usage: zabbix_items_from_csv.py [-h] -o CSV_OID -c CSV_NAME -n HOST_NAME -g
                                HOST_GROUP -i HOST_INTERFACE -a
                                HOST_APPLICATION [-y] [-f]

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
GGSN-1-LONDON -g GGSN-GROUP -i 127.0.0.1 -a GGSN-APP-OIDS -y

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
                        server.
  -i HOST_INTERFACE, --host-interface HOST_INTERFACE
                        SNMP Interface configured on Zabbix server. (Assuming
                        Single Interface in Configured)
  -a HOST_APPLICATION, --host-application HOST_APPLICATION
                        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 :
                        False]
  -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.\
                            generate_items_xml_file_complete(dict_device_1,
                                                            'BLR-DEVICE_1', 'BLR-DEVICE_1',
                                                            '10.12.51.11', '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.\
                            generate_items_xml_file_complete(dict_device_1,
                                                            'CHN-DEVICE_1', 'CHN-DEVICE_1',
                                                            '10.12.51.11', '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.\
                            generate_items_xml_file_complete(dict_device_2,
                                                             'BLR-DEVICE_2', 'BLR-DEVICE_2',
                                                             '12.12.54.66', '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.\
                            generate_items_xml_file_complete(dict_device_2,
                                                             'CHN-DEVICE_2', 'CHN-DEVICE_2',
                                                             '12.12.52.74', 'DEVICE_2')
zabbix_items_from_csv.xml_pretty_me('CHN-DEVICE_2.xml', xml_tree_string_device_2)

Code Location

Comments

Popular posts from this blog

Zabbix History Table Clean Up

Zabbix history table gets really big, and if you are in a situation where you want to clean it up. Then we can do so, using the below steps. Stop zabbix server. Take table backup - just in case. Create a temporary table. Update the temporary table with data required, upto a specific date using epoch . Move old table to a different table name. Move updated (new temporary) table to original table which needs to be cleaned-up. Drop the old table. (Optional) Restart Zabbix Since this is not offical procedure, but it has worked for me so use it at your own risk. Here is another post which will help is reducing the size of history tables - http://zabbixzone.com/zabbix/history-and-trends/ Zabbix Version : Zabbix v2.4 Make sure MySql 5.1 is set with InnoDB as innodb_file_per_table=ON Step 1 Stop the Zabbix server sudo service zabbix-server stop Script. echo "------------------------------------------" echo " 1. Stopping Zabbix Server ...

Installing Zabbix Version 2.4 Offline (Zabbix Server without Internet).

There might be situations where you have a remote/zabbix server which does not have internet connectivity, due to security or other reasons. So we create a custom repo on the remote/zabbix server so that we can install zabbix using rpms Here is how we are planning to do this. Download all the dependency rpms on a machine which has internet connection, using yum-downloadonly or repotrack . Transfer all the rpms to the remote server. Create a repo on the remote server. Update yum configuration. Install. NOTE: This method can be used to install any application, but here we have used zabbix as we had this requirement for a zabbix server. Download dependent rpms . On a machine which has internet connection install the package below. And download all the rpms . Make sure the system are similar (not required to be identical - At-least the OS should be of same version) mkdir /zabbix_rpms yum install yum-downloadonly Downloading all the rpms to location /zabbix_rpms/ ,...

Access Filter in SSSD `ldap_access_filter` [SSSD Access denied / Permission denied ]

Access Filter Setup with SSSD ldap_access_filter (string) If using access_provider = ldap , this option is mandatory. It specifies an LDAP search filter criteria that must be met for the user to be granted access on this host. If access_provider = ldap and this option is not set, it will result in all users being denied access. Use access_provider = allow to change this default behaviour. Example: access_provider = ldap ldap_access_filter = memberOf=cn=allowed_user_groups,ou=Groups,dc=example,dc=com Prerequisites yum install sssd Single LDAP Group Under domain/default in /etc/sssd/sssd.conf add: access_provider = ldap ldap_access_filter = memberOf=cn=Group Name,ou=Groups,dc=example,dc=com Multiple LDAP Groups Under domain/default in /etc/sssd/sssd.conf add: access_provider = ldap ldap_access_filter = (|(memberOf=cn=System Adminstrators,ou=Groups,dc=example,dc=com)(memberOf=cn=Database Users,ou=Groups,dc=example,dc=com)) ldap_access_filter accepts standa...