Add Linux Host to Nagios Monitoring Server (Complete Script)

In this post, I have created a script which involves all the steps which we perform while adding Linux host in Nagios monitoring server.

Download script here: plugin-nrpe-install script

#!/bin/bash

Path1=/opt/softwares/nagios-plugins-2.1.1  ## this path may varies with the current veriosn
Path2=/opt/softwares/nrpe-2.15                   ##  of plugin and nrpe.

echo -e "\e[1;32mNagios Client Installation...\e[0m"

Packages="wget gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel"
for pkg in $Packages; do

if [ -z $(rpm -qa $pkg) ];
then
echo -e "\e[1;31m$pkg not installed\e[0m"
echo "$pkg" >> /tmp/notinstalled.txt
else
echo -e "\e[1;32m$pkg installed\e[0m"
fi
done
##############################################
for i in `cat /tmp/notinstalled.txt`;
   do
   /usr/bin/yum install $i -y
#    echo "$i is not installed."
#   echo -e "\e[1;32mAll the Packages are installed\e[0m"
   >/tmp/notinstalled.txt
done
##############################################
USERID="nagios"
ID='/usr/bin/id'
/bin/egrep  -i "^${USERID}:" /etc/passwd
if [ $? -eq 0 ]; then
   echo -e "\e[1;32mUser $USERID exists in /etc/passwd \e[0m"
   echo -e "\e[1;32mNagios ID is $ID nagios \e[0m"
else
   echo -e "\e[1;32mUser $USERID does not exists in /etc/passwd \e[0m"
   echo  -e "\e[1;32mAdding user Nagios \e[0m"
   useradd nagios
   echo "nagios123" | passwd nagios --stdin
fi
##########################################
echo -e "\e[1;32mDownloading the nagios and nrpe plugins\e[0m"
mkdir /opt/softwares/
cd /opt/softwares/
/usr/bin/wget "http://www.nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz" && tar xf nagios-plugins-2.1.1.tar.gz
/usr/bin/wget --no-check-certificate "https://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz" && tar xf nrpe-2.15.tar.gz
################################################
if [ ! -d "/usr/local/nagios" ]
then
    echo -e "\e[1;31Directory "/usr/local/nagios" does not exists.\e[0m"
    echo -e "\e[1;32Instaling nagios plugins\e[0m"
    cd $Path1
    ./configure
    make
    make install
    /bin/chown nagios.nagios /usr/local/nagios
    /bin/chown -R nagios.nagios /usr/local/nagios/libexec
    sleep 5
    echo -e "\e[1;32mInstalling xinetd package\e[0m"
    yum install xinetd -y
###########################################
    echo -e "\e[1;32mInstalling nrpe plugin\e[0m"
    cd $Path2
    ./configure
    make all
    make install-plugin
    make install-daemon
    make install-daemon-config
    make install-xinetd
    sleep 5
/bin/sed -i 's/127.0.0.1/127.0.0.1 localhost 192.168.1.207/g' /etc/xinetd.d/nrpe
 ## Higlighted IP will be replaced with your Nagios server IP      
/bin/echo "nrpe            5666/tcp                #NRPE" >> /etc/services

    service xinetd start
    chkconfig xinetd on
/bin/netstat -tlpn | grep xinetd
/usr/local/nagios/libexec/check_nrpe -H localhost
/bin/echo -e "\e[1;32mNAGIOS CLIENT SUCCESSFULLY INSTALLED\e[0m"
else
    echo -e "\e[1;32mDirectory /usr/local/nagios exists.\e[0m"
fi


Refernce Link: Tecmint

Any Changes/Suggestions are appreciated.

No comments:

Post a Comment