-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem running plugins on AIX #43
Comments
There is a problem with getopt in AIX. The output in the problem is:
The output in Linux
The output in the TEMP variable was not correctly defined in AIX. However, in Linux it is set in the right way (parameter value parameter value...) I am going to see what can be done. I am not a AIX expert. |
It seems the AIX includes the getopt version that does not support long name parameters. You can install the GNU getopt that support them. In any case, I put a condition in the code that checks the OS before filling the variable. Please tell me if that works. If it does, I will perform the change in the rest of the scripts. For more information: https://stackoverflow.com/questions/27376607/getopt-is-not-working-on-aix-as-it-does-in-linux/27377607#27377607 |
Hi Andres, i installed the GNU getopt and then it worked. Thanks I tried the standard getopt in AIX but don't know if i edited your script TEMP=$(getopt -o d:hi:KTvV --long to TEMP=$(getopt -o d:hi:KTvV ) Mit freundlichen Grüßen / Best regards IT-SystemsSto SE & Co. KGaA Von: Andres Gomez Casanova notifications@github.com It seems the AIX includes the getopt version that does not support long In any case, I put a condition in the code that checks the OS before For more information: — +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Persönlich haftende Gesellschafterin/General Partner: Dr. Max-Burkhard ZwostaFollow us on Sto-Apps |
I modified the scripts in order to work natively in AIX with no need to use GNU getopt |
I tried the scripts on AIX but i can't get them running. AIX Version 7.1 TL2 SP4, Bash 3.2.1, getopt-1.1.4-3
Here is the output with -vvv
./check_database_connection -i /db2/db2ez1 -d EZ1 -vvv
Usage: check_database_connection { -i instanceHomeDirectory -d databaseName [-K]
| -h | -V } [-T][-v]
Note: The test was not executed.|
|
Here the output with debug on
db2ez1> ./check_database_connection -i /db2/db2ez1 -d EZ1 -vvv
Locale to print messages in English. Prevent language problems.
export LANG=en_US
Version of this script.
function print_revision {
echo Andres Gomez Casanova - AngocA
echo v1.1 2013-05-25
}
Function to show the help
function print_usage {
/bin/cat <<__EOT
Usage: ${1} { -i instanceHomeDirectory -d databaseName [-K]
| -h | -V } [-T][-v]
__EOT
}
function print_help {
print_revision
print_usage ${1}
Max 80 chars width.
/bin/cat <<__EOT
This script checks the connectivity to a database.
-d | --database STRING
Database name.
-h | --help
Shows the current documentation.
-i | --instance STRING
Instance home directory. It is usually /home/db2inst1.
-K | --mk
Changes the output to be compatible with Check_MK.
-T | --trace
Trace mode: writes date and output in /tmp.
-v | --verbose
Executes the script in verbose mode (multiple times).
-V | --version
Shows the current version of this script.
__EOT
}
Variable to control the flow execution. Prevent Spaghetti code.
CONTINUE=true
Nagios return codes
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3
This is the returned code.
RETURN=${UNKNOWN}Nagios Output
Text output 80 chars | Optional Perf Data Line 1
Long text Line 1
Long text Line 2 | Optional Perf Data Line 2
Optional Perf Data Line 3
OUTPUT=
PERFORMANCE=
LONG_OUTPUT=
LONG_PERFORMANCE=
PERF_MK="-"
APPL_NAME=$(basename ${0})
basename ${0}
++ basename ./check_database_connection
if [[ ${#} -eq 0 ]] ; then
print_usage ${APPL_NAME}
RETURN=${UNKNOWN}
CONTINUE=false
fi
The following requieres GNU getopt. See the following discusion.
http://stackoverflow.com/questions/402377
TEMP=$(getopt -o d:hi:KTvV --long database:,help,instance:,mk,trace,verbose,version
-n ${APPL_NAME} -- "${@}")
getopt -o d:hi:KTvV --long database:,help,instance:,mk,trace,verbose,version -n ${APPL_NAME} -- "${@}"
++ getopt -o d:hi:KTvV --long database:,help,instance:,mk,trace,verbose,version -n check_database_connection -- -i /db2/db2ez1 -d EZ1 -vvv
if [[ ${?} -ne 0 ]] ; then
print_usage ${APPL_NAME}
RETURN=${UNKNOWN}
CONTINUE=false
fi
if [[ ${CONTINUE} == true ]] ; then
Note the quotes around ${TEMP}: they are essential!
eval set -- "${TEMP}"
HELP=false
VERSION=false
CHECK_MK=false
Verbosity level
VERBOSE=0
Trace activated
TRACE=false
LOG=/tmp/${APPL_NAME}.log
INSTANCE_HOME=
DATABASE_NAME=
while true; do
case "${1}" in
-d | --database ) DATABASE_NAME=$(echo ${2} | cut -d' ' -f1) ; shift 2 ;;
-h | --help ) HELP=true ; shift ;;
-i | --instance ) INSTANCE_HOME=$(echo ${2} | cut -d' ' -f1) ; shift 2 ;;
-K | --mk ) CHECK_MK=true ; shift ;;
-T | --trace ) TRACE=true ; shift ;;
-v | --verbose ) VERBOSE=$(( ${VERBOSE} + 1 )) ; shift ;;
-V | --version ) VERSION=true ; shift ;;
-- ) shift; break ;;
* ) break ;;
esac
done
fi
set -- -- d:hi:KTvV --long database:,help,instance:,mk,trace,verbose,version -n check_database_connection -- -i /db2/db2ez1 -d EZ1 -vvv
++ set -- -- d:hi:KTvV --long database:,help,instance:,mk,trace,verbose,version -n check_database_connection -- -i /db2/db2ez1 -d EZ1 -vvv
if [[ ${TRACE} == true ]] ; then${$ }" >> ${LOG}
echo ">>>>>" >> ${LOG}
date >> ${LOG}
echo "Instance at ${INSTANCE_HOME}" >> ${LOG}
echo "PID
fi
ECHO="help:${HELP}, version:${VERSION}, verbose:${VERBOSE}"
ECHO="${ECHO}, check_mk:${CHECK_MK}"
ECHO="${ECHO}, directory:${INSTANCE_HOME}, database:${DATABASE_NAME}"
if [[ ${VERBOSE} -ge 2 ]] ; then
echo ${ECHO}
fi
if [[ ${TRACE} == true ]] ; then
echo "PARAMS:${ECHO}" >> ${LOG}
fi
if [[ ${CONTINUE} == true && ${HELP} == true ]] ; then
print_help ${APPL_NAME}
RETURN=${UNKNOWN}
CONTINUE=false
fi
if [[ ${CONTINUE} == true && ${VERSION} == true ]] ; then
print_revision ${APPL_NAME}
RETURN=${UNKNOWN}
CONTINUE=false
fi
if [[ ${CONTINUE} == true && ${INSTANCE_HOME} == "" ]] ; then
print_usage ${APPL_NAME}
RETURN=${UNKNOWN}
CONTINUE=false
fi
Usage: check_database_connection { -i instanceHomeDirectory -d databaseName [-K]
| -h | -V } [-T][-v]
if [[ ${CONTINUE} == true && ${DATABASE_NAME} == "" ]] ; then
print_usage ${APPL_NAME}
RETURN=${UNKNOWN}
CONTINUE=false
fi
if [[ ${CONTINUE} == true ]] ; then
if [[ -d ${INSTANCE_HOME} && -e ${INSTANCE_HOME}/sqllib/db2profile ]] ; then
# Load the DB2 profile.
. ${INSTANCE_HOME}/sqllib/db2profile
INSTANCE_NAME=$(db2 get instance | awk '/instance/ {print $7}')
else
OUTPUT="Instance directory is invalid."
RETURN=${UNKNOWN}
CONTINUE=false
fi
fi
if [[ ${CONTINUE} == true ]] ; then$4}' | grep -iw $ {DATABASE_NAME})
COMMAND_DATABASE="db2 list db directory"
if [[ ${VERBOSE} -ge 2 ]] ; then
echo "COMMAND: ${COMMAND_DATABASE}"
fi
DATABASE=$(${COMMAND_DATABASE})
if [[ ${TRACE} == true ]] ; then
echo "RESULT:'${DATABASE}'" >> ${LOG}
fi
DATABASE=$(printf '%s\n' "${DATABASE}" | awk '/Database alias/ {print
if [[ ${VERBOSE} -ge 3 ]] ; then
echo "RESULT:'${DATABASE}'"
fi
if [[ ${DATABASE} == "" ]] ; then
OUTPUT="The database ${DATABASE_NAME} is not cataloged."
RETURN=${UNKNOWN}
CONTINUE=false
fi
fi
if [[ ${CONTINUE} == true ]] ; then$4}' | grep -iw $ {DATABASE_NAME})
COMMAND_ACTIVE="db2 list active databases"
if [[ ${VERBOSE} -ge 2 ]] ; then
echo "COMMAND: ${COMMAND_ACTIVE}"
fi
ACTIVE=$(${COMMAND_ACTIVE})
if [[ ${TRACE} == true ]] ; then
echo "RESULT:'${ACTIVE}'" >> ${LOG}
fi
ACTIVE=$(printf '%s\n' "${ACTIVE}" | awk '/Database name/ {print
if [[ ${VERBOSE} -ge 3 ]] ; then
echo "RESULT:'${ACTIVE}'"
fi
if [[ ${ACTIVE} == "" ]] ; then
OUTPUT_ACTIVE="The database is not active. "
LONG_OUTPUT="${OUTPUT_ACTIVE}"
LONG_PERFORMANCE_1="'Database_Active'=0.2;0.5"
else
OUTPUT_ACTIVE="The database is active. "
LONG_OUTPUT="${OUTPUT_ACTIVE}"
LONG_PERFORMANCE_1="'Database_Active'=0.8;0.5"
fi
COMMAND_CONNECTABLE="db2 -a connect to ${DATABASE_NAME}"
if [[ ${VERBOSE} -ge 2 ]] ; then
echo "COMMAND: ${COMMAND_CONNECTABLE}"
fi
CONNECTABLE=$(${COMMAND_CONNECTABLE})
if [[ ${TRACE} == true ]] ; then
echo "RESULT:'${CONNECTABLE}'" >> ${LOG}
fi
CONNECTABLE=$(printf '%s\n' "${CONNECTABLE}" | awk '/sqlcode/ {print $7}')
if [[ ${VERBOSE} -ge 3 ]] ; then
echo "RESULT:'${CONNECTABLE}'"
fi
if [[ ${CONNECTABLE} -eq 0 ]] ; then
OUTPUT="OK Connection to database ${DATABASE_NAME}. "${OUTPUT_ACTIVE}
RETURN=${OK}
PERFORMANCE="'Connectable_Database'=0.9;0.6;0.3"
elif [[ ${CONNECTABLE} -eq -20157 ]] ; then
OUTPUT="The database is in quiesce mode. "${OUTPUT_ACTIVE}
RETURN=${WARNING}
PERFORMANCE="'Connectable_Database'=0.4;0.6;0.3"
else
OUTPUT="A connection to database ${DATABASE_NAME} was not succesful. "${OUTPUT_ACTIVE}
LONG_OUTPUT="${LONG_OUTPUT} ${CONNECTABLE}"
RETURN=${CRITICAL}
PERFORMANCE="'Connectable_Database'=0.1;0.6;0.3"
fi
Check for HADR Window replay
COMMAND_ROLE="db2 get db cfg for ${DATABASE_NAME}"
if [[ ${VERBOSE} -ge 2 ]] ; then
echo "COMMAND: ${COMMAND_ROLE}"
fi
ROLE=$(${COMMAND_ROLE})
if [[ ${TRACE} == true ]] ; then
echo "RESULT:'${ROLE}'" >> ${LOG}
fi
ROLE=$(printf '%s\n' "${ROLE}" | awk '/HADR database role/ {print $5}')
if [[ ${VERBOSE} -ge 3 ]] ; then
echo "RESULT:'${ROLE}'"
fi
if [[ ${ROLE} == "STANDBY" ]] ; then
COMMAND_REPLAY="db2pd -db wfscpd -hadr"
if [[ ${VERBOSE} -ge 2 ]] ; then
echo "COMMAND: ${COMMAND_REPLAY}"
fi
REPLAY=$(${COMMAND_REPLAY})
if [[ ${TRACE} == true ]] ; then
echo "RESULT:'${REPLAY}'" >> ${LOG}
fi
REPLAY=$(printf '%s\n' "${REPLAY}" | awk '/^Active/ {print "active"}')
if [[ ${VERBOSE} -ge 3 ]] ; then
echo "RESULT:'${REPLAY}'"
fi
if [[ ${REPLAY} == "active" ]] ; then
LONG_PERFORMANCE_2="HADR-replay=0.3;0.5"
else
LONG_PERFORMANCE_2="HADR-replay=0.7;0.5"
fi
fi
LONG_PERFORMANCE="${LONG_PERFORMANCE_1} ${LONG_PERFORMANCE_2}"
if [[ ${LONG_PERFORMANCE_2} == "" ]] ; then
PERF_MK="${PERFORMANCE}|${LONG_PERFORMANCE_1}"
else
PERF_MK="${PERFORMANCE}|${LONG_PERFORMANCE_1}|${LONG_PERFORMANCE_2}"
fi
fi
Prints the output.
if [[ ${OUTPUT} == "" ]] ; then
OUTPUT="Note: The test was not executed."
fi
Builds the output.
if [[ ${CHECK_MK} == true ]] ; thenecho "${RETURN} databaseConnection-${INSTANCE_NAME}-${DATABASE_NAME} ${PERF_MK} ${OUTPUT}"
else
echo -e "${OUTPUT}|${PERFORMANCE}\n${LONG_OUTPUT}|${LONG_PERFORMANCE}"
fi
Note: The test was not executed.|
|
Returns the error code.
if [[ ${VERBOSE} -ge 2 ]] ; thenecho "Return code: ${RETURN}"
fi
if [[ ${TRACE} == true ]] ; then
echo -e "OUTPUT:${OUTPUT}\nPERF:${PERFORMANCE}\nLONG_OUT:${LONG_OUTPUT}\nLONGPERF:${LONG_PERFORMANCE}\nRET_CODE:${RETURN}" >> ${LOG}
date >> ${LOG}
echo -e "<<<<<\n" >> ${LOG}
fi
exit ${RETURN}
Best regards
Stephan
The text was updated successfully, but these errors were encountered: