From a0087dbd1a0b717cd1d521852ebaf1a1ed068537 Mon Sep 17 00:00:00 2001 From: dodger Date: Tue, 20 Jun 2023 09:38:16 +0200 Subject: [PATCH] updates --- check_remote_oracle | 159 +++++++------------------------------------- 1 file changed, 24 insertions(+), 135 deletions(-) diff --git a/check_remote_oracle b/check_remote_oracle index dcdb207..c2bd764 100755 --- a/check_remote_oracle +++ b/check_remote_oracle @@ -100,11 +100,6 @@ SET TIMING OFF" # And BACKUP_METHOD allowed: ${LIGHTGREEN}${KNOWNTYPE[*]}${RESET}\n" # # VERY INITIAL CHECKS -print_revision() { - echo "$1 v$2 (nagios-plugins 2.0)" - printf "%sThe nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute\ncopies of the plugins under the terms of the GNU General Public License.\nFor more information about these matters, see the file named COPYING.\n" | sed -e 's/\n/ /g' -} - # H host # U oracle user # S sid @@ -170,114 +165,6 @@ usage() exit 0 } -print_usage() -{ - echo "Usage: - ${PROGPATH}/${PROGNAME} -H [-U Oracle OS User] --tns - ${PROGPATH}/${PROGNAME} -H [-U Oracle OS User] --db - ${PROGPATH}/${PROGNAME} -H [-U Oracle OS User] --login - ${PROGPATH}/${PROGNAME} -H [-U Oracle OS User] --userslocked - ${PROGPATH}/${PROGNAME} -H [-U Oracle OS User] --ospassword CRITICAL_THRESHOLD WARNING_THRESHOLD - ${PROGPATH}/${PROGNAME} -H [-U Oracle OS User] --sessions CRITICAL_THRESHOLD WARNING_THRESHOLD - ${PROGPATH}/${PROGNAME} -H [-U Oracle OS User] --asessions CRITICAL_THRESHOLD WARNING_THRESHOLD - ${PROGPATH}/${PROGNAME} -H [-U Oracle OS User] --cache CRITICAL_THRESHOLD WARNING_THRESHOLD - ${PROGPATH}/${PROGNAME} -H [-U Oracle OS User] --parsing CRITICAL_THRESHOLD WARNING_THRESHOLD - ${PROGPATH}/${PROGNAME} -H [-U Oracle OS User] --tablespace CRITICAL_THRESHOLD WARNING_THRESHOLD - ${PROGPATH}/${PROGNAME} -H [-U Oracle OS User] --undo CRITICAL_THRESHOLD WARNING_THRESHOLD - ${PROGPATH}/${PROGNAME} -H [-U Oracle OS User] --diskgroup CRITICAL_THRESHOLD WARNING_THRESHOLD - ${PROGPATH}/${PROGNAME} -H [-U Oracle OS User] --asmfs CRITICAL_THRESHOLD WARNING_THRESHOLD - ${PROGPATH}/${PROGNAME} -H [-U Oracle OS User] --dgstats CRITICAL_THRESHOLD WARNING_THRESHOLD - ${PROGPATH}/${PROGNAME} -H [-U Oracle OS User] --fra CRITICAL_THRESHOLD WARNING_THRESHOLD - ${PROGPATH}/${PROGNAME} -H [-U Oracle OS User] --redogen - ${PROGPATH}/${PROGNAME} -H [-U Oracle OS User] --sessionlock - ${PROGPATH}/${PROGNAME} -H [-U Oracle OS User] --totalspace - ${PROGPATH}/${PROGNAME} -H [-U Oracle OS User] --totalspacedelta - ${PROGPATH}/${PROGNAME} -H [-U Oracle OS User] --plsqllines - ${PROGPATH}/${PROGNAME} --help - ${PROGPATH}/${PROGNAME} --version - -" - -} - -print_help() -{ - print_revision $PROGNAME $REVISION - echo "" - print_usage - echo " - Check Oracle status - - --tns SID/IP Address - Check remote TNS server - --db SID - Check remote database (search /bin/ps for PMON process) - --sessions SID - Check remote database concurrent active sessions - --asessions SID - Count sessions on the database (either active or not) per database user - --login SID - Attempt a dummy login and alert if not ORA-01017: invalid username/password - --userslocked SID - Check if there's any user account is locked - --cache - Check remote database for library and buffer cache hit ratios - --parsing - Check remote database for Soft/Hard parse ratios - --tablespace - Check remote database for tablespace capacity in ORACLE_SID - --undo - Check remote database for UNDO tablespace capacity in ORACLE_SID - --fra - Check remote database for FLASH_RECOVERY_AREA capacity in ORACLE_SID - --diskgroup - Check remote database for diskgroup capacity in ORACLE_ASM_SID (Tipically +ASM1/2...) - --dgstats - Dataguard statistics (Apply & Transport Lag). This check is done ON THE STANDBY (the master does not have information on V\$DATAGUARD_STATS. So ORACLE_SID and HOSTNAME must be the STANDBY ones. - --redogen - Daily check for yesterday's redo generation - --sessionlock - Watch for session locks (any lock with return CRITICAL) - --totalspace - Total Space taken by the database Excluding sytem tablespaces. - --totalspacedelta - Delta of the Total Space (Yesterday-thedaybeforeyesterday) - --developers - Number of sessions of the developers. - --help - Print this help screen - --version - Print version and license information - - If the plugin doesn't work, check that the ORACLE_HOME environment - variable is set, that ORACLE_HOME/bin is in your PATH, and the - tnsnames.ora file is locatable and is properly configured on your Oracle server. - - If you want to use a default Oracle home, add in your oratab file: - *:/opt/app/oracle/product/7.3.4:N - " -} - -## getops ### usage() -## getops ### { -## getops ### # Information options -## getops ### case "${1^^}" in -## getops ### "--HELP"|"-H") -## getops ### print_help -## getops ### exit $STATE_OK -## getops ### ;; -## getops ### "--VERSION"|"-V") -## getops ### print_revision $PROGNAME $REVISION -## getops ### exit $STATE_OK -## getops ### ;; -## getops ### *) -## getops ### print_usage -## getops ### exit $STATE_OK -## getops ### ;; -## getops ### esac -## getops ### } - - oraerror_check() { local CHECKTHIS="$*" @@ -290,7 +177,7 @@ oraerror_check() return_values() { - local let VALUE=$1 + local VALUE=$1 if [[ ${VALUE} -gt ${CRITICAL} ]] ; then MSG="CRITICAL" RETURNCODE=${STATE_CRITICAL} @@ -310,7 +197,7 @@ return_values() reverse_return_values() { - local let VALUE=$1 + local VALUE=$1 if [[ ${VALUE} -lt ${CRITICAL} ]] ; then MSG="CRITICAL" RETURNCODE=${STATE_CRITICAL} @@ -337,11 +224,11 @@ get_remote_oraclehome() { #set -x # Hunt down a reasonable ORACLE_HOME - ORATABLIST="$(${SSH} "locate oratab" | egrep "/oratab$" | tr '\n' ' ')" + ORATABLIST="$(${SSH} "locate oratab" | grep -E "/oratab$" | tr '\n' ' ')" for ORATAB in ${ORATABLIST} ; do - ORACLE_HOME=$(${SSH} "cat ${ORATAB}" | egrep "^(${ORACLE_SID}|\*):" | awk -F\: '{print $2}') - if [[ "${ORACLE_HOME}" ]] && [ $($SSH "ls -d ${ORACLE_HOME}" |wc -l) -eq 1 ] ; then + ORACLE_HOME=$(${SSH} "cat ${ORATAB}" | grep -E "^(${ORACLE_SID}|\*):" | awk -F: '{print $2}') + if [[ "${ORACLE_HOME}" ]] && [ "$($SSH "ls -d ${ORACLE_HOME}" |wc -l)" -eq 1 ] ; then return 0 fi done @@ -351,7 +238,8 @@ get_remote_oraclehome() check_tns() { local AUX="${ORAENV} tnsping ${ORACLE_SID}" - local TNSCHECK="$(${SSH} ${AUX})" + local TNSCHECK + TNSCHECK="$(${SSH} "${AUX}")" # echo ${TNSCHECK} if [[ "${TNSCHECK}" =~ .*OK.*\(([0-9]{1,})\ .* ]] ; then return ${STATE_OK} @@ -362,8 +250,9 @@ check_tns() check_db() { - local PMONCHECK="$(${SSH} "ps -ef" | egrep -v grep | grep -c "ora_pmon_${ORACLE_SID}")" - if [ ${PMONCHECK} -ge 1 ] ; then + local PMONCHECK + PMONCHECK="$(${SSH} "ps -ef" | grep -Ev grep | grep -c "ora_pmon_${ORACLE_SID}")" + if [[ ${PMONCHECK} -ge 1 ]] ; then # echo "${ORACLE_SID} OK - ${PMONCHECK} PMON process(es) running" return ${STATE_OK} else @@ -387,8 +276,8 @@ check_login() check_total_sessions() { - local let RETURNCODE=${STATE_UNKNOWN} - local let TOTALSESSIONS=0 + local RETURNCODE=${STATE_UNKNOWN} + local TOTALSESSIONS=0 local QUERY="${NOHEAD} set numf 99999 @@ -417,11 +306,11 @@ and not username in ('SYS', 'PUBLIC', 'NAGIOS' ) check_asessions_v3() { - local let RETURNCODE=${STATE_UNKNOWN} - local let MAXINDEX=0 - local let i=0 - local let x=0 - local let TOTALSESSIONS=0 + local RETURNCODE=${STATE_UNKNOWN} + local MAXINDEX=0 + local i=0 + local x=0 + local TOTALSESSIONS=0 declare -a RESSULTARRAY declare -a RESSULTUSERS @@ -469,10 +358,10 @@ order by 1 check_sharedpool() { - local let RETURNCODE=${STATE_UNKNOWN} - local let SHAREDFREE=0 - local let SHAREDTOTAL=0 - local let SHAREDPERCENT=100 + local RETURNCODE=${STATE_UNKNOWN} + local SHAREDFREE=0 + local SHAREDTOTAL=0 + local SHAREDPERCENT=100 local QUERY="${NOHEAD} SELECT 'shared_pool_total=' || ROUND(SUM(BYTES)/1024/1024) FROM sys.V_\\\$SGASTAT WHERE POOL='shared pool' GROUP BY POOL; @@ -531,7 +420,7 @@ check_developers() # Included SYSTEM in the query's exclusion pattern to avoid reporting backup sessions. check_sessions() { - local let RETURNCODE=${STATE_UNKNOWN} + local RETURNCODE=${STATE_UNKNOWN} local QUERY="${NOHEAD} set numf 99 select count(SES.SID) @@ -561,8 +450,8 @@ and UPPER(SES.USERNAME) not in ( 'SYS','SYSMAN','MDSYS','SYSTEM','NAGIOS', 'DBSN # Included SYSTEM in the query's exclusion pattern to avoid reporting backup sessions. check_activesessions() { - local let RETURNCODE=${STATE_UNKNOWN} - local let TOTALSESSIONS=0 + local RETURNCODE=${STATE_UNKNOWN} + local TOTALSESSIONS=0 local PERFDATA="" local QUERY="${NOHEAD} set numf 999