Skip to content
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

Closed
StephanKeller76 opened this issue Dec 9, 2014 · 4 comments
Closed

Problem running plugins on AIX #43

StephanKeller76 opened this issue Dec 9, 2014 · 4 comments
Assignees

Comments

@StephanKeller76
Copy link

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

  • export LANG=en_US
  • 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

  • CONTINUE=true

Nagios return codes

OK=0

  • OK=0
    WARNING=1
  • WARNING=1
    CRITICAL=2
  • CRITICAL=2
    UNKNOWN=3
  • UNKNOWN=3

    This is the returned code.

    RETURN=${UNKNOWN}
  • RETURN=3

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=

  • OUTPUT=
    PERFORMANCE=
  • PERFORMANCE=
    LONG_OUTPUT=
  • LONG_OUTPUT=
    LONG_PERFORMANCE=
  • LONG_PERFORMANCE=
    PERF_MK="-"
  • PERF_MK=-

APPL_NAME=$(basename ${0})
basename ${0}
++ basename ./check_database_connection

  • APPL_NAME=check_database_connection

if [[ ${#} -eq 0 ]] ; then
print_usage ${APPL_NAME}
RETURN=${UNKNOWN}
CONTINUE=false
fi

  • [[ 5 -eq 0 ]]

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

  • TEMP='-- 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

  • [[ 0 -ne 0 ]]

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

  • [[ true == true ]]
  • eval 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
    ++ set -- -- d:hi:KTvV --long database:,help,instance:,mk,trace,verbose,version -n check_database_connection -- -i /db2/db2ez1 -d EZ1 -vvv
  • HELP=false
  • VERSION=false
  • CHECK_MK=false
  • VERBOSE=0
  • TRACE=false
  • LOG=/tmp/check_database_connection.log
  • INSTANCE_HOME=
  • DATABASE_NAME=
  • true
  • case "${1}" in
  • shift
  • break

if [[ ${TRACE} == true ]] ; then
echo ">>>>>" >> ${LOG}
date >> ${LOG}
echo "Instance at ${INSTANCE_HOME}" >> ${LOG}
echo "PID ${$}" >> ${LOG}
fi

  • [[ false == true ]]

ECHO="help:${HELP}, version:${VERSION}, verbose:${VERBOSE}"

  • ECHO='help:false, version:false, verbose:0'
    ECHO="${ECHO}, check_mk:${CHECK_MK}"
  • ECHO='help:false, version:false, verbose:0, check_mk:false'
    ECHO="${ECHO}, directory:${INSTANCE_HOME}, database:${DATABASE_NAME}"
  • ECHO='help:false, version:false, verbose:0, check_mk:false, directory:, database:'

if [[ ${VERBOSE} -ge 2 ]] ; then
echo ${ECHO}
fi

  • [[ 0 -ge 2 ]]

if [[ ${TRACE} == true ]] ; then
echo "PARAMS:${ECHO}" >> ${LOG}
fi

  • [[ false == true ]]

if [[ ${CONTINUE} == true && ${HELP} == true ]] ; then
print_help ${APPL_NAME}
RETURN=${UNKNOWN}
CONTINUE=false
fi

  • [[ true == true ]]
  • [[ false == true ]]

if [[ ${CONTINUE} == true && ${VERSION} == true ]] ; then
print_revision ${APPL_NAME}
RETURN=${UNKNOWN}
CONTINUE=false
fi

  • [[ true == true ]]
  • [[ false == true ]]

if [[ ${CONTINUE} == true && ${INSTANCE_HOME} == "" ]] ; then
print_usage ${APPL_NAME}
RETURN=${UNKNOWN}
CONTINUE=false
fi

  • [[ true == true ]]
  • [[ '' == '' ]]
  • print_usage check_database_connection
  • /bin/cat
    Usage: check_database_connection { -i instanceHomeDirectory -d databaseName [-K]
    | -h | -V } [-T][-v]
  • RETURN=3
  • CONTINUE=false

if [[ ${CONTINUE} == true && ${DATABASE_NAME} == "" ]] ; then
print_usage ${APPL_NAME}
RETURN=${UNKNOWN}
CONTINUE=false
fi

  • [[ false == true ]]

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

  • [[ false == true ]]

if [[ ${CONTINUE} == true ]] ; then
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 $4}' | grep -iw ${DATABASE_NAME})
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

  • [[ false == true ]]

if [[ ${CONTINUE} == true ]] ; then
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 $4}' | grep -iw ${DATABASE_NAME})
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

  • [[ false == true ]]

Prints the output.

if [[ ${OUTPUT} == "" ]] ; then
OUTPUT="Note: The test was not executed."
fi

  • [[ '' == '' ]]
  • OUTPUT='Note: The test was not executed.'

    Builds the output.

    if [[ ${CHECK_MK} == true ]] ; then
    echo "${RETURN} databaseConnection-${INSTANCE_NAME}-${DATABASE_NAME} ${PERF_MK} ${OUTPUT}"
    else
    echo -e "${OUTPUT}|${PERFORMANCE}\n${LONG_OUTPUT}|${LONG_PERFORMANCE}"
    fi
  • [[ false == true ]]
  • echo -e 'Note: The test was not executed.|\n|'
    Note: The test was not executed.|
    |

    Returns the error code.

    if [[ ${VERBOSE} -ge 2 ]] ; then
    echo "Return code: ${RETURN}"
    fi
  • [[ 0 -ge 2 ]]
    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
  • [[ false == true ]]
    exit ${RETURN}
  • exit 3

Best regards
Stephan

@angoca angoca self-assigned this Dec 9, 2014
@angoca
Copy link
Owner

angoca commented Dec 9, 2014

There is a problem with getopt in AIX.

The output in the problem is:

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
+ TEMP='-- d:hi:KTvV --long database:,help,instance:,mk,trace,verbose,version -n check_database_connection -- -i /db2/db2ez1 -d EZ1 -vvv '

The output in Linux

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 ${APPL_NAME} -- "${@}"
++ getopt -o d:hi:KTvV --long database:,help,instance:,mk,trace,verbose,version -n nagios -- -i /home/db2inst1 -d sample
+ TEMP=' -i '\''/home/db2inst1'\'' -d '\''sample'\'' --'

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.

@angoca
Copy link
Owner

angoca commented Dec 9, 2014

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

@StephanKeller76
Copy link
Author

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
correct.

TEMP=$(getopt -o d:hi:KTvV --long
database:,help,instance:,mk,trace,verbose,version
-n ${APPL_NAME} -- "${@}")

to

TEMP=$(getopt -o d:hi:KTvV )

Mit freundlichen Grüßen / Best regards
Stephan Keller
Senior System Engineer

IT-Systems

Sto SE & Co. KGaA
Ehrenbachstr. 1, D-79780 Stühlingen
FOI - IT Infrastruct./Architect. & Operations
Tel: +49-77 44-57 16 63
Fax: +49-77 44-57 26 63
Mobile: +49-170-45 71 498
www.sto.com & www.sto.de

Von: Andres Gomez Casanova notifications@github.com
An: angoca/monitor-db2-with-nagios
monitor-db2-with-nagios@noreply.github.com
Kopie: StephanKeller76 s.keller@sto.com
Datum: 09.12.2014 15:12
Betreff: Re: [monitor-db2-with-nagios] Problem running plugins on AIX
(#43)

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


Reply to this email directly or view it on GitHub.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Sto SE & Co. KGaA, Ehrenbachstr.1, D-79780 Stuehlingen
Sitz der Gesellschaft/Head Office: D-79780 Stuehlingen
Handelsregister/Registration: Amtsgericht Freiburg i.Br. HRB 711236
USt-ID/Tax ID: DE142834082
Aufsichtsratsvorsitzender/Chairman Supervisory Board:
Dr. Max-Burkhard Zwosta

Persönlich haftende Gesellschafterin/General Partner:
STO Management SE
Sitz der Gesellschaft/Head Office: D-79780 Stuehlingen
Handelsregister/Registration: Amtsgericht Freiburg i.Br. HRB 709900
Vorstand/Board: Jochen Stotmeister (Vorsitzender/Chairman),
Gerd Stotmeister, Rolf Woehrle, Rainer Huettenberger
Aufsichtsratsvorsitzender/Chairman Supervisory Board:

Dr. Max-Burkhard Zwosta

Follow us on Sto-Apps

@angoca
Copy link
Owner

angoca commented Feb 2, 2016

I modified the scripts in order to work natively in AIX with no need to use GNU getopt

@angoca angoca closed this as completed Feb 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants