CHips L MINI SHELL

CHips L pro

Current Path : /opt/zabbix_scripts/
Upload File :
Current File : //opt/zabbix_scripts/wbs.status.sh

#!/bin/bash
# Name: check_wbs_backup.sh
# Author: Paul Jr Fernandez
# Check wbs backup status and timeliness
# Changelog:
# 20150626 1.0 Intial Release

#Defining exit variables
EXIT_OKAY=0
EXIT_WARN=1
EXIT_CRIT=2
EXIT_UNKW=3
EXIT_STAT=$EXIT_UNKW

#Check is the status files contain the word "failed"
grep -irl failed /wbs/status/*.status &> /dev/null
STATUS=$?

#Critical Threshold is 8days and 3hours.
CRIT_THRESHOLD=702000
#Warning Threshold is 7days and 3hours.
WARN_THRESHOLD=615600

#Check the age of the mtime of status files
FILES=( $( ls /wbs/status/*.status ) )
for ((i=0;i<${#FILES[@]};i++))
do
	MTIME=$( stat -c %Y ${FILES[$i]} )
	CTIME=$( date +%s )
	AGE[$i]=$(( $CTIME - $MTIME ))
	DAYS[$i]=$(( ${AGE[$i]} / 86400 ))
	HOURS[$i]=$((((${AGE[$i]} % 86400))/3600))
	MINUTES[$i]=$((((((${AGE[$i]} % 86400))%3600))/60))
	if [ $(( ${AGE[$i]} )) -gt $CRIT_THRESHOLD ]
	then
		FLAG[$i]=2
	elif [ $(( ${AGE[$i]} )) -gt $WARN_THRESHOLD ]
	then
		FLAG[$i]=1
	else
		FLAG[$i]=0
	fi
done


#Output Generation
if [ $STATUS -eq 0 ]
then
	echo "CRITICAL: WBS Backups have failed. Please check /wbs/status/*.status files for further information."
	exit $EXIT_CRIT
fi

if [[ " ${FLAG[@]} " =~ " 2 " ]]
then
	EXIT_STAT=$EXIT_CRIT
	echo -n "CRITICAL:"
	for ((i=0;i<${#FILES[@]};i++))
	do
		FILE_NAME=$( echo ${FILES[$i]} | cut -d/ -f4 )
		echo -n " $FILE_NAME -> Last Backup run was ${DAYS[$i]} days, ${HOURS[$i]} hours and ${MINUTES[$i]} minutes ago."
	done
elif [[ " ${FLAG[@]} " =~ " 1 " ]]
then
	EXIT_STAT=$EXIT_WARN
	echo -n "WARNING:"
	for ((i=0;i<${#FILES[@]};i++))
	do
		FILE_NAME=$( echo ${FILES[$i]} | cut -d/ -f4 )
		echo -n " $FILE_NAME -> Last Backup run was ${DAYS[$i]} days, ${HOURS[$i]} hours and ${MINUTES[$i]} minutes ago."
	done
else
	EXIT_STAT=$EXIT_OKAY
	echo -n "OK:"
	for ((i=0;i<${#FILES[@]};i++))
	do
		FILE_NAME=$( echo ${FILES[$i]} | cut -d/ -f4 )
		echo -n " $FILE_NAME -> Last Backup run was ${DAYS[$i]} days, ${HOURS[$i]} hours and ${MINUTES[$i]} minutes ago."
	done
fi

echo ""
exit $EXIT_STAT

Copyright 2K16 - 2K18 Indonesian Hacker Rulez