Generate Nagios Configuration Using Shell Script – 1000 Configs 1 Minute

Are you thinking that configuring Nagios with thousands of hosts is difficult then your assumption is wrong. Just Simply within minute of time you can generate nagios configuration using shell script – 1000 configs will take 1 minute of time.

Really exited right..!! Let’s see the procedure and piece of code will do it for you.

Generate Nagios Configuration Using Shell Script – 1000 Configs 1 Minute

First we have to prepare .csv file with host IP addresses and host names then you can run below shell script it will generate every thing for you.

Conditions to run the shell script

  • .csv file name should be arkit-generate.csv (if your advanced user then change accordingly)
  • Generate One type of configuration files once which means Windows Machines once, Linux Machines and Other Machines once. You have to prepare multiple .csv files based there Operating System type.
  • Create Standard Template as a base
  • In .csv file Server name should not have any space

How to Create .csv file

Open excel sheet and file the data as mentioned below, IP Address in First Column (A) and Host Name in Second Column.

Save the excel file name with arkit-generate.csv (Do not put any other name until unless your not sure)

Then Download below template

Download

of-course you can create your template as per your requirement, If you would like to create your own template then save the template name as Nagios-Template-Linux.cfg

Keep all the files in one directory, then create one file called generate.sh

[root@Arkit ~]# touch generate.sh

Copy below script and paste in newly created file called generate.sh

Nagios Monitoring Tool Implementation: Configure 10000 Hosts in one minute NagiosCore

#!/bin/bash
## Purpose: Generate Nagios Configuration
## Date: 27th Sep 2016
## Author: Ankam Ravi Kumar
## Web Site: https://arkit.co.in
mkdir temp-cfg
cat  arkit-generate.csv | while read LINE
do
    HostIP=`echo $LINE | cut -d, -f1`
    HostName=`echo $LINE | cut -d, -f2`
    sed -e "s/XXXX/$HostName/g; s/ZZZZ/$HostIP/g" Nagios-Template-Linux.cfg > temp-cfg/$HostName.cfg
done

Now provide executable permission to that script file using below command

~]# chmod +x generate.sh~]# ./generate.sh

After completion of script running you can able to see temp-cfg directory

~]# cd temp-cfg

then move the config files to appropriate location to monitor all your Hosts and Services

Default location is /usr/local/nagios/etc/objects/

Related  Articles

Monitoring Windows Clients using Nagios Core

Nagios Core Service Group Configuration

Nagios Core host Group Configuration

Change Nagiosadmin password when you forgot

Thanks for your wonderful Support and Encouragement