Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
nagios plugins to: verify a list of files aren't too old, that no failed rsync files are lingering, and there are no zero-sized files.
#!/bin/sh
#
# copy each .dump and .sql file in $1 to $2
#
BACKUPDIR=$1
COPYDIR=$2
GLOBALS="globals"
cd ${BACKUPDIR}
# redirect to /dev/null to supress error messages when there is no .dump file
FILES=`ls *.dump *sql 2>/dev/null`
echo creating the databases for $FILES
for i in $FILES
do
echo cp -p $i ${COPYDIR}
cp -p $i ${COPYDIR}
done
#!/bin/sh
LIST_OF_FILES="/usr/home/dan/bin/list.files.check"
FILES=`/bin/cat ${LIST_OF_FILES}`
BACKUPDIR="/usr/home/dan/backups"
# 26 and 48 hours
WARN_PRIMARY=93600
CRIT_PRIMARY=172800
# 72 and 96 hours
WARN_SECONDARY=259200
CRIT_SECONDARY=345600
if [ $1 == 'primary' ]
then
WARN=$WARN_PRIMARY
CRIT=$CRIT_PRIMARY
else
WARN=$WARN_SECONDARY
CRIT=$CRIT_SECONDARY
fi
#default to all OK
answer=0
reply=""
for file in ${FILES}
do
if [ $1 == 'rotated' ]
then
dir=`/usr/bin/dirname ${file}`
file=`/usr/bin/basename ${file}`
file="${dir}/old-backups/${file}.0"
fi
# echo $file
result=`/usr/local/libexec/nagios/check_file_age -w ${WARN} -c ${CRIT} -f ${BACKUPDIR}/${file}`
success=$?
if [ $success == 0 ]
then
# all good
else if [ $success == 1 ]
then
# warning
if [ $answer -lt $success ]
then
answer=$success
fi
reply="$reply $result"
else
# critical
if [ $answer -lt $success ]
then
answer=$success
fi
reply="$reply $result"
fi
fi
# echo $success
done
if [ $answer == 0 ]
then
echo 'All OK'
else
echo $reply
fi
return $answer
#!/bin/sh
BACKUPDIR="/usr/home/dan/backups"
# 12 and 24 hours
WARN=43200
CRIT=86400
# nothing to report
response=""
# all good
success=0
#default to all OK
answer=0
reply=""
# lists of files which are rsyncing, warning, or critical
rsyncing=""
warning=""
crtical=""
FILES="`/usr/bin/find ${BACKUPDIR} -name '.*' | /usr/bin/egrep -v '/.NOBACKUP$|^.$'`"
answer=$?
# if any of these files are over two hours old, raise a warning
for file in ${FILES}
do
result=`/usr/local/libexec/nagios/check_file_age -w ${WARN} -c ${CRIT} -f ${file}`
success=$?
if [ $success == 0 ]
then
# all good
rsyncing="$rsyncing $result"
else if [ $success == 1 ]
then
# warning
if [ $answer -lt $success ]
then
answer=$success
fi
response="$response $result"
else
# critical
if [ $answer -lt $success ]
then
answer=$success
fi
response="$response $result"
fi
fi
done
if [ $success -eq 0 ]
then
if [ "$rsyncing" == "" ]
then
echo OK
else
echo OK. Files syncing: $rsyncing
fi
else
echo $response
fi
return $success
#!/bin/sh
BACKUPDIR="/usr/home/dan/backups"
# 12 and 24 hours
WARN=43200
CRIT=86400
# nothing to report
response=""
# all good
success=0
#default to all OK
answer=0
reply=""
# lists of files which are rsyncing, warning, or critical
rsyncing=""
warning=""
crtical=""
FILES="`/usr/bin/find ${BACKUPDIR} -size 0 | /usr/bin/grep -v /.NOBACKUP`"
answer=$?
# if any of these files are over two hours old, raise a warning
for file in ${FILES}
do
result=`/usr/local/libexec/nagios/check_file_age -w ${WARN} -c ${CRIT} -f ${file}`
success=$?
if [ $success == 0 ]
then
# all good
rsyncing="$rsyncing $result"
else if [ $success == 1 ]
then
# warning
if [ $answer -lt $success ]
then
answer=$success
fi
response="$response $result"
else
# critical
if [ $answer -lt $success ]
then
answer=$success
fi
response="$response $result"
fi
fi
done
if [ $success -eq 0 ]
then
echo OK. Files syncing: $rsyncing
else
echo $response
fi
return $success
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.