# # VARIABLES # # Unalias everything - just in case. unalias -a # Start time. # date +"%s" does not work on AIX 5.2. # STARTTIME=`date +"%s" 2>/dev/null` STARTTIME=`perl -le 'print time' 2>/dev/null` STARTTIMEERRPT=`perl -MPOSIX -le 'print strftime "%m%d%H%M%y",localtime(time)'` if [ -z "${STARTTIME}" ] ; then echo "Perl is not working properly. Aborting." exit 1 fi export STARTTIME mydate=`date +"%m/%d/%Y"` mytime=`date +"%H:%M:%S"` export mydate mytime # Clear the list of scripts. unset ScriptsList export ScriptsList # Helper variable for scripts. let mins=0 export mins # Clear the list of email addresses. unset eMailList export eMailList # The variable counters to store results for each return code. let TOTALNR=0 #TOTAL let OKNR=0 #OK let WARNNR=0 #WARNING let ERRORNR=0 #ERROR export TOTALNR OKNR WARNNR ERRORNR # The hostname. MY_HOST_NAME=`uname -a | awk '{ print $2 }'` export MY_HOST_NAME # The default file location. myoutput=checkall_${MY_HOST_NAME} OUTPUT=${myoutput}.log export myoutput unset LogFile export LogFile export csvon=false export htmlon=false export logfileon=true export email100=false export basic=false # Width of output - default set to 130 characters. let mywidth=130 export mywidth # Write descriptions to output? Default set to false. writedesc=false export writedesc # Suppress all checks that have returncode 0? Default set to false. suppressok=false export suppressok # Default set verbose to false. verboseon=false export verboseon # # End of VARIABLES # # # FUNCTIONS # # Function filler is used to display a line of comments up to ${mywidth}. filler(){ # Export character so perl can use it. export mychar=${1} if [ "${verboseon}" = "true" ] ; then perl -e 'print $ENV{"mychar"} x $ENV{"mywidth"};printf("n")' fi if [ "${logfileon}" = "true" ] ; then perl -e 'print $ENV{"mychar"} x $ENV{"mywidth"};printf("n")' >> ${OUTPUT} fi # Function filler is not used for CSV and HTML output. } # Function verbose is used to get this script to log in a consistent way. verbose(){ string=${1} unset mytimestamp mytimestamp=${2} if [ -z "${mytimestamp}" ] ; then mytimestamp=`date "+%Y-%m-%d %H:%M:%S"` fi [ "${verboseon}" = "true" ] && echo "${mytimestamp}: ${string}" | fold -w ${mywidth} [ "${logfileon}" = "true" ] && echo "${mytimestamp}: ${string}" | fold -w ${mywidth} >> ${OUTPUT} # verbose is not used with CSV and HTML file output } # Function verbosehtml is used to get this script to log in a consistent way for HTML output. verbosehtml(){ [ "${htmlon}" = "true" ] && echo "" >> ${OUTPUT} ${1} ${2}
}
# Function verbosehtmlwarning is used to get this script to log in a consistent way for HTML outputi for warning messages.
verbosehtmlwarning(){
[ "${htmlon}" = "true" ] && echo "" >> ${OUTPUT} ${1} ${2}
}
# Function description displays the description of the check script being run.
description(){
if [ "${writedesc}" = "true" ] ; then
echo
[ "${verboseon}" = "true" ] && echo "Description:" && echo "------------" && echo && grep -p'**' ${file} DESCRIPTIONS | grep -v "^ script_name" | sed "s/script_description: //g" | sed "s/
//g" | fold -w ${mywidth}
fi
}
# Function descriptionlog is used to log a script description to the log file.
descriptionlog(){
if [ "${writedesc}" = "true" ] ; then
[ "${logfileon}" = "true" ] && ( echo && echo "Description:" && echo "------------" && echo && grep -p'**' ${file} DESCRIPTIONS | grep -v "^ script_name" | sed "s/script_description: //g" | sed "s/
//g" | fold -w ${mywidth} ) >> ${OUTPUT}
fi
}