#!/bin/bash
#Author : Ranjith Kumar R
#Date : 16th April 2014
#Purpose : Add services into the nagios service group.
echo "Please enter service group name"
read svcgroup
while read server
do
servername=`echo $server | cut -d';' -f1`
OUTPUT=`find /usr/local/nagios -name "$servername"_DB.cfg | grep -i $servername`
RESULT=`echo $?`
if [ "$RESULT" -eq "0" ]; then
OUTPUT1=`cat $OUTPUT | grep -i "$svcgroup" | grep "service_description" | awk '{print $2}' > /tmp/svcgroup.txt`
RESULT1=`echo $?`
if [ "$RESULT1" -eq "0" ]; then
echo "success" > /dev/null
fi
fi
while read service
do
startlinenum=`grep -nr -A 2 -B 14 """$service""" "$OUTPUT" | grep "servicegroups" | cut -d'-' -f1 | head -1`
if [ "$startlinenum" == "" ]; then
continue
fi
format=`echo "$startlinenum"s/DBservices/DBservices,$svcgroup/`
sed "$format" $OUTPUT > "$OUTPUT".temp
mv "$OUTPUT".temp "$OUTPUT"
done < /tmp/svcgroup.txt
done < /usr/local/nagios/libexec/tools/devicelist
rm -rf /tmp/svcgroup.txt
#Author : Ranjith Kumar R
#Date : 16th April 2014
#Purpose : Add services into the nagios service group.
echo "Please enter service group name"
read svcgroup
while read server
do
servername=`echo $server | cut -d';' -f1`
OUTPUT=`find /usr/local/nagios -name "$servername"_DB.cfg | grep -i $servername`
RESULT=`echo $?`
if [ "$RESULT" -eq "0" ]; then
OUTPUT1=`cat $OUTPUT | grep -i "$svcgroup" | grep "service_description" | awk '{print $2}' > /tmp/svcgroup.txt`
RESULT1=`echo $?`
if [ "$RESULT1" -eq "0" ]; then
echo "success" > /dev/null
fi
fi
while read service
do
startlinenum=`grep -nr -A 2 -B 14 """$service""" "$OUTPUT" | grep "servicegroups" | cut -d'-' -f1 | head -1`
if [ "$startlinenum" == "" ]; then
continue
fi
format=`echo "$startlinenum"s/DBservices/DBservices,$svcgroup/`
sed "$format" $OUTPUT > "$OUTPUT".temp
mv "$OUTPUT".temp "$OUTPUT"
done < /tmp/svcgroup.txt
done < /usr/local/nagios/libexec/tools/devicelist
rm -rf /tmp/svcgroup.txt
No comments:
Post a Comment