This commit is contained in:
dodger 2023-06-20 09:38:16 +02:00
parent 4fcc3b900b
commit a0087dbd1a
Signed by: dodger
GPG Key ID: F6701F6CB4D1C826

View File

@ -100,11 +100,6 @@ SET TIMING OFF"
# And BACKUP_METHOD allowed: ${LIGHTGREEN}${KNOWNTYPE[*]}${RESET}\n" # And BACKUP_METHOD allowed: ${LIGHTGREEN}${KNOWNTYPE[*]}${RESET}\n"
# # VERY INITIAL CHECKS # # 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 # H host
# U oracle user # U oracle user
# S sid # S sid
@ -170,114 +165,6 @@ usage()
exit 0 exit 0
} }
print_usage()
{
echo "Usage:
${PROGPATH}/${PROGNAME} -H <Hostname/IP address> [-U Oracle OS User] --tns <ORACLE_SID>
${PROGPATH}/${PROGNAME} -H <Hostname/IP address> [-U Oracle OS User] --db <ORACLE_SID>
${PROGPATH}/${PROGNAME} -H <Hostname/IP address> [-U Oracle OS User] --login <ORACLE_SID>
${PROGPATH}/${PROGNAME} -H <Hostname/IP address> [-U Oracle OS User] --userslocked <ORACLE_SID>
${PROGPATH}/${PROGNAME} -H <Hostname/IP address> [-U Oracle OS User] --ospassword CRITICAL_THRESHOLD WARNING_THRESHOLD
${PROGPATH}/${PROGNAME} -H <Hostname/IP address> [-U Oracle OS User] --sessions <ORACLE_SID> CRITICAL_THRESHOLD WARNING_THRESHOLD
${PROGPATH}/${PROGNAME} -H <Hostname/IP address> [-U Oracle OS User] --asessions <ORACLE_SID> CRITICAL_THRESHOLD WARNING_THRESHOLD
${PROGPATH}/${PROGNAME} -H <Hostname/IP address> [-U Oracle OS User] --cache <ORACLE_SID> CRITICAL_THRESHOLD WARNING_THRESHOLD
${PROGPATH}/${PROGNAME} -H <Hostname/IP address> [-U Oracle OS User] --parsing <ORACLE_SID> CRITICAL_THRESHOLD WARNING_THRESHOLD
${PROGPATH}/${PROGNAME} -H <Hostname/IP address> [-U Oracle OS User] --tablespace <ORACLE_SID> <TABLESPACE> CRITICAL_THRESHOLD WARNING_THRESHOLD
${PROGPATH}/${PROGNAME} -H <Hostname/IP address> [-U Oracle OS User] --undo <ORACLE_SID> CRITICAL_THRESHOLD WARNING_THRESHOLD
${PROGPATH}/${PROGNAME} -H <Hostname/IP address> [-U Oracle OS User] --diskgroup <ORACLE_SID> <DISKGROUP> CRITICAL_THRESHOLD WARNING_THRESHOLD
${PROGPATH}/${PROGNAME} -H <Hostname/IP address> [-U Oracle OS User] --asmfs <ASMFS_PATH> CRITICAL_THRESHOLD WARNING_THRESHOLD
${PROGPATH}/${PROGNAME} -H <Hostname/IP address> [-U Oracle OS User] --dgstats <ORACLE_SID> CRITICAL_THRESHOLD WARNING_THRESHOLD
${PROGPATH}/${PROGNAME} -H <Hostname/IP address> [-U Oracle OS User] --fra <ORACLE_SID> CRITICAL_THRESHOLD WARNING_THRESHOLD
${PROGPATH}/${PROGNAME} -H <Hostname/IP address> [-U Oracle OS User] --redogen <ORACLE_SID>
${PROGPATH}/${PROGNAME} -H <Hostname/IP address> [-U Oracle OS User] --sessionlock <ORACLE_SID>
${PROGPATH}/${PROGNAME} -H <Hostname/IP address> [-U Oracle OS User] --totalspace <ORACLE_SID>
${PROGPATH}/${PROGNAME} -H <Hostname/IP address> [-U Oracle OS User] --totalspacedelta <ORACLE_SID>
${PROGPATH}/${PROGNAME} -H <Hostname/IP address> [-U Oracle OS User] --plsqllines <ORACLE_SID>
${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() oraerror_check()
{ {
local CHECKTHIS="$*" local CHECKTHIS="$*"
@ -290,7 +177,7 @@ oraerror_check()
return_values() return_values()
{ {
local let VALUE=$1 local VALUE=$1
if [[ ${VALUE} -gt ${CRITICAL} ]] ; then if [[ ${VALUE} -gt ${CRITICAL} ]] ; then
MSG="CRITICAL" MSG="CRITICAL"
RETURNCODE=${STATE_CRITICAL} RETURNCODE=${STATE_CRITICAL}
@ -310,7 +197,7 @@ return_values()
reverse_return_values() reverse_return_values()
{ {
local let VALUE=$1 local VALUE=$1
if [[ ${VALUE} -lt ${CRITICAL} ]] ; then if [[ ${VALUE} -lt ${CRITICAL} ]] ; then
MSG="CRITICAL" MSG="CRITICAL"
RETURNCODE=${STATE_CRITICAL} RETURNCODE=${STATE_CRITICAL}
@ -337,11 +224,11 @@ get_remote_oraclehome()
{ {
#set -x #set -x
# Hunt down a reasonable ORACLE_HOME # 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 for ORATAB in ${ORATABLIST} ; do
ORACLE_HOME=$(${SSH} "cat ${ORATAB}" | egrep "^(${ORACLE_SID}|\*):" | awk -F\: '{print $2}') 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 if [[ "${ORACLE_HOME}" ]] && [ "$($SSH "ls -d ${ORACLE_HOME}" |wc -l)" -eq 1 ] ; then
return 0 return 0
fi fi
done done
@ -351,7 +238,8 @@ get_remote_oraclehome()
check_tns() check_tns()
{ {
local AUX="${ORAENV} tnsping ${ORACLE_SID}" local AUX="${ORAENV} tnsping ${ORACLE_SID}"
local TNSCHECK="$(${SSH} ${AUX})" local TNSCHECK
TNSCHECK="$(${SSH} "${AUX}")"
# echo ${TNSCHECK} # echo ${TNSCHECK}
if [[ "${TNSCHECK}" =~ .*OK.*\(([0-9]{1,})\ .* ]] ; then if [[ "${TNSCHECK}" =~ .*OK.*\(([0-9]{1,})\ .* ]] ; then
return ${STATE_OK} return ${STATE_OK}
@ -362,8 +250,9 @@ check_tns()
check_db() check_db()
{ {
local PMONCHECK="$(${SSH} "ps -ef" | egrep -v grep | grep -c "ora_pmon_${ORACLE_SID}")" local PMONCHECK
if [ ${PMONCHECK} -ge 1 ] ; then 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" # echo "${ORACLE_SID} OK - ${PMONCHECK} PMON process(es) running"
return ${STATE_OK} return ${STATE_OK}
else else
@ -387,8 +276,8 @@ check_login()
check_total_sessions() check_total_sessions()
{ {
local let RETURNCODE=${STATE_UNKNOWN} local RETURNCODE=${STATE_UNKNOWN}
local let TOTALSESSIONS=0 local TOTALSESSIONS=0
local QUERY="${NOHEAD} local QUERY="${NOHEAD}
set numf 99999 set numf 99999
@ -417,11 +306,11 @@ and not username in ('SYS', 'PUBLIC', 'NAGIOS' )
check_asessions_v3() check_asessions_v3()
{ {
local let RETURNCODE=${STATE_UNKNOWN} local RETURNCODE=${STATE_UNKNOWN}
local let MAXINDEX=0 local MAXINDEX=0
local let i=0 local i=0
local let x=0 local x=0
local let TOTALSESSIONS=0 local TOTALSESSIONS=0
declare -a RESSULTARRAY declare -a RESSULTARRAY
declare -a RESSULTUSERS declare -a RESSULTUSERS
@ -469,10 +358,10 @@ order by 1
check_sharedpool() check_sharedpool()
{ {
local let RETURNCODE=${STATE_UNKNOWN} local RETURNCODE=${STATE_UNKNOWN}
local let SHAREDFREE=0 local SHAREDFREE=0
local let SHAREDTOTAL=0 local SHAREDTOTAL=0
local let SHAREDPERCENT=100 local SHAREDPERCENT=100
local QUERY="${NOHEAD} local QUERY="${NOHEAD}
SELECT 'shared_pool_total=' || ROUND(SUM(BYTES)/1024/1024) FROM sys.V_\\\$SGASTAT WHERE POOL='shared pool' GROUP BY POOL; 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. # Included SYSTEM in the query's exclusion pattern to avoid reporting backup sessions.
check_sessions() check_sessions()
{ {
local let RETURNCODE=${STATE_UNKNOWN} local RETURNCODE=${STATE_UNKNOWN}
local QUERY="${NOHEAD} local QUERY="${NOHEAD}
set numf 99 set numf 99
select count(SES.SID) 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. # Included SYSTEM in the query's exclusion pattern to avoid reporting backup sessions.
check_activesessions() check_activesessions()
{ {
local let RETURNCODE=${STATE_UNKNOWN} local RETURNCODE=${STATE_UNKNOWN}
local let TOTALSESSIONS=0 local TOTALSESSIONS=0
local PERFDATA="" local PERFDATA=""
local QUERY="${NOHEAD} local QUERY="${NOHEAD}
set numf 999 set numf 999