sar – nagios – pnp4nagios

Iniziamo dal Problema…. e finiamo con la soluzione 😉
Il Problema é che serve vedere lo stato dei server, e le query SNMP no bastano piú. allora installiamo sysstat sui server.
Ma poi io voglio vedere i grafici, e noi usiamo nagios/pnp4nagios.
Allora cosa fare? spediamo i file sar ogni ora verso il server nagios.

intanto ogni minuto lanciamo il collection “/etc/cron.d/sysstat”:

*/1 * * * * root /usr/lib64/sa/sa1 1 1

poi ogni ora lanciamo i file : “/etc/cron.hourly/sarmail”

#!/bin/sh
#
# send sar output as mail
#
# if called before 1am send yesterdays data else todays data
# if an argument is given, override default with the day specified
#
ADDRESSEE="sarmail"
TARGET="firma.it"

if [ ! -z "$1" ]; then
SAR="/var/log/sa/sa`echo $1 | tr -dc '0-9' | awk '{printf("%02d",$1)}`"
elif [ `date +%H` -lt 1 ]; then
SAR=`ls -1rt /var/log/sa/sa[0-9][0-9] | tail -2 | head -1`
else
SAR=`ls -1rt /var/log/sa/sa[0-9][0-9] | tail -1`
fi
[ ! -f $SAR ] && echo "File not found: $SAR" && exit 2

sar -A -f $SAR | sed "s/ CPU i000/INTR i000/" | /bin/mailx -s "`hostname` `basename ${SAR}`" ${ADDRESSEE}@${TARGET}

poi nel server di destinazione si fa una casella mail che fa un pipe su na command.
sarmail: "|/usr/local/bin/sar2rrd"

#!/bin/sh
#
#

SARDIR=/tmp/sardir
DATE=`date "+%d"`
MONTH=`date "+%b"`
HTM_DIR=/var/lib/pnp4nagios/

while read subject host saname ; do
[ "$subject" = "Subject:" ] && break
done

[ ! -d /${SARDIR}/$host ] && mkdir -p /${SARDIR}/$host
sfdate="`echo $saname|sed s/sa//g`"
if [ $sfdate != $DATE ];then
DATE=`TZ=$TZ+24 date "+%d"`
MONTH=`TZ=$TZ+24 date "+%b"`
fi
cat > /${SARDIR}/$host/${host}.$saname

umask 0022

OPTION=" -t MDY -v -S 60"
# make sure file exists
if [ -f $SARDIR/$host/${host}.$saname ];then
if [ -d $HTM_DIR/$host ]; then
OPTION=$OPTION" -C"
OFFSET=10
DATE=`rrdtool last $HTM_DIR/$host/proc_s.rrd`
START_DATE=`expr $DATE + $OFFSET`
DATE_D=`date -d @$START_DATE +'%m-%d-%Y'`
DATE_T=`date -d @$START_DATE +'%H:%M:%S'`
OPTION=$OPTION" -s $DATE_D -w $DATE_T"
fi
[ ! -d $HTM_DIR/$host ] && mkdir -p $HTM_DIR/$host && chmod 777 $HTM_DIR/$host

/usr/local/bin/sar2rrd-palma2.pl -d $HTM_DIR/_HOST_/ -i $HTM_DIR/_HOST_/ -x $HTM_DIR/_HOST_/ -f $SARDIR/$host/${host}.${saname} $OPTION
fi

questo trasforma da file sar a rrd!!!!

Leave a Reply

Your email address will not be published.