Archive for the ‘Nagios’ Category

nagios script to check dns servers status

Monday, June 7th, 2010
#!/bin/bash
###################################
#Purpose:################################################################
###(a) Monitor if all your name server is online:        Status :Done ####
###(b) Monitor if all name server has same zone record : Staus : Ongoing##
###(c) Monitor the Response time of Dns server         : Status : Ongoing#
#########################################################################
 
#Status check variables for nagios script#####
#####################################
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4
 
#####################################
##Declaration of vairables###########
#####################################
 
declare -rx  CMD_HOST="/usr/bin/host";
declare -rx CMD_AWK="/bin/awk"
declare  -rx CMD_CAT="/bin/cat"
declare -rx CMD_GREP="/bin/grep"
declare -rx CMD_DIG="/usr/bin/dig"
ZONE=$1;  # This value will captuer zone record prvided as parameter from script.
#############################################################
#Command to use : host -t ns fosiul.co.uk | awk '{print $4}'#
#############################################################
NUMBER_OF_DNSSrv=$($CMD_HOST -t ns $ZONE | $CMD_AWK '{print $4}' )
s=0
for i in $NUMBER_OF_DNSSrv
do
###########################################################
###Now Find out if all the name server is running##########
##########################################################
 
############Command#######################
########dig @dnserver ############
DNS_LIVE_RESULT=$($CMD_DIG @$i | $CMD_GREP -c  'connection timed out')
 
if [ $DNS_LIVE_RESULT -gt 0 ]
 
        then
         OFFLINE_ARRAY[$s]=$i
          ((s+=1))
fi
done
if [ ${#OFFLINE_ARRAY[*]} -eq 0 ]
then
 echo "All servers are online"
 exit $STATUS_OK
else
 s=0
  echo -n "Following servers are offline: "
  while [ $s -lt ${#OFFLINE_ARRAY[*]} ]
   do
    echo -n "${OFFLINE_ARRAY[$s]} "
    ((s+=1))
   done
   echo
  exit $STATE_CRITICAL
fi
 
 
 
done

configure nrpe(nagios) to listen on different port

Thursday, April 15th, 2010

Purpose : Some times Isp Or vps provider they block port 5666 Or for any reason if you want to configure nrpe to listen different port example 15666, follow as bellow:

On the Remote host(linux-vps) :

1. Change the Port number in : /etc/xinetd.d/nrpe

# default: on
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
        flags           = REUSE
        socket_type     = stream
       port            = 15666
        wait            = no
        user            = nagios
        group           = nagios
        server          = /usr/local/nagios/bin/nrpe
        server_args     = -c /usr/local/nagios/etc/nrpe.cfg --inetd
        log_on_failure  += USERID
        disable         = no
        only_from       = 127.0.0.1 ip.of.nagios.server
}

2. Change port number : vi /etc/services

nrpe            15666/tcp                        # NRPE

3. Change port number in : /usr/local/nagios/etc/nrpe.cfg

server_port=15666

4 . Restart nrpe daemon : service xinetd restart

On the server(nagiosserver) :
Purpose : Example, I have more then 10 linux server. 9 of them listen port 5666 , but only one of them listen port 15666 . So I need to create a different set of commands for nagios server to connect that nrpe client on different port.

1. Create a command in command.cgi file ( /usr/local/nagios/etc/objects/commands.cgi)

#This is slightly modified from check_nrpe command
#Because Vps company they blocked port 5666
#So i had to configure linuxvps server to listen on port  15666, So
#I need to create a different command to connect to different port
 
define command{
command_name check_nrpe_vps
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -p 15666 -c $ARG1$
}

2. Now call this check_nrpe_vps commands from host definition file
Example : host definition file for linuxvps is : linuxvps.cgi ( /usr/local/nagios/etc/objects/linuxvps.cgi)

   define service{
   use generic-service
   host_name linuxvps
   service_description CPU Load
  check_command check_nrpe_vps!check_load
}

3. now Call this linuxvps.cgi from nagios.cfg file

  cfg_file=/usr/local/nagios/etc/objects/linuxvps.cfg

4. restart the nagios.
So now this nagios server will connect to nrpe client via 15666 port.