Commit ecd2aa97 authored by Vitaly Lipatov's avatar Vitaly Lipatov

add nagios-monit.sh

parent e794fd68
#!/bin/bash
SERVER=$1
VZ=$2
if [ $# -ne 2 ]
then
echo -e "\nUsage:\n./nagios-monit.sh HOSTNAME CTID\nor\n./nagios-monit.sh HOSTNAME all\n"
exit 1
fi
createblock() {
SERVER=$1
VZ=$2
IP=$(ssh $SERVER " vzlist -a|tr -s ' '|cut -b2-|grep '^$VZ '|cut -f 4 -d' ' ")
if [ x$IP = x ]
then
echo "Connection error to $SERVER or no such CTID "
exit 2
fi
if [ $IP = - ]
then
echo " WARNING: The ip address of vz$VZ is unknown, correct it manually"
IP=''
fi
NAME=$(ssh $SERVER " vzlist -a|tr -s ' '|cut -b2-|grep '^$VZ '|cut -f 5 -d' ' ")
if [ $NAME = - ]
then
echo " WARNING: The CTID name of vz$VZ is not defined, used the CTID instead "
NAME="vz$VZ"
fi
cat <<EOF > /tmp/nagiosblock
define service {
use local-service-http-monitor
host_name $SERVER
notifications_enabled 1
service_description MONIT-$NAME
check_command check_nrpe_arg!check_monit_unisite!$IP
}
EOF
scp -q /tmp/nagiosblock nagios:/tmp/nagiosblock
ssh nagios cat /tmp/nagiosblock \>\> /etc/nagios/objects/$SERVER-monit.cfg
rm -f /tmp/nagiosblock
ssh nagios rm -f /tmp/nagiosblock
echo "vz$VZ - DONE"
}
NRPECHECK=$(ssh $SERVER grep -c check_monit_unisite /etc/nagios/nrpe.cfg)
if [ 0${NRPECHECK} -eq 0 ]
then
echo
echo "WARNING: there is no nrpe command 'check_monit_unisite found"
echo 'Add to /etc/nagios/nrpe.cfg:'
echo 'command[check_monit_unisite]=/usr/lib64/nagios/plugins/check_monit.py -H $ARG1$ -u monit -P <password>'
echo
else
echo
echo "The nrpe command check_monit_unisite found - OK"
echo
fi
if [ $VZ = all ]
then
VZLIST=$(ssh $SERVER ' vzlist -a|tr -s " "|cut -f2 -d" "|grep -v CTID ')
for i in $VZLIST
do
VZ=$i
createblock $SERVER $VZ
done
else
createblock $@
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment