Merge pull request 'getops_switch' (#1) from getops_switch into master

Reviewed-on: dodger/nagios_oracle_check_plugin#1
This commit is contained in:
dodger 2022-05-12 12:27:31 +02:00
commit 78252cc2de

View File

@ -7,6 +7,39 @@
# #
# GRANTS for nagios user
# CREATE USER NAGIOS IDENTIFIED BY SOMEPASSWORD;
# GRANT CONNECT, RESOURCE TO NAGIOS ;
# GRANT SELECT ON V_$ARCHIVED_LOG to nagios ;
# GRANT SELECT ON V_$ASM_DISKGROUP to nagios ;
# GRANT SELECT ON V_$DATAGUARD_STATS to nagios ;
# GRANT SELECT ON V_$LOCK to nagios ;
# GRANT SELECT ON V_$LOG_HISTORY to nagios ;
# GRANT SELECT ON V_$PROCESS to nagios ;
# GRANT SELECT ON V_$SESSION to nagios ;
# GRANT SELECT ON V_$SESSION_WAIT to nagios ;
# GRANT SELECT ON V_$SQLAREA to nagios ;
# GRANT SELECT ON V_$SYSSTAT to nagios ;
# GRANT SELECT ON V_$controlfile to nagios ;
# GRANT SELECT ON V_$librarycache to nagios ;
# GRANT SELECT ON V_$lock to nagios ;
# GRANT SELECT ON V_$log to nagios ;
# GRANT SELECT ON V_$log_history to nagios ;
# GRANT SELECT ON V_$parameter to nagios ;
# GRANT SELECT ON V_$recovery_file_dest to nagios ;
# GRANT SELECT ON V_$session to nagios ;
# GRANT SELECT ON V_$sysstat to nagios ;
# GRANT SELECT ON DBA_DATA_FILES TO NAGIOS ;
# GRANT SELECT ON DBA_EXTENTS TO NAGIOS ;
# GRANT SELECT ON DBA_UNDO_EXTENTS TO NAGIOS ;
# GRANT SELECT ON dba_data_files TO NAGIOS ;
# GRANT SELECT ON dba_free_space TO NAGIOS ;
# GRANT SELECT ON dba_objects TO NAGIOS ;
# GRANT SELECT ON dba_source TO NAGIOS ;
# GRANT SELECT ON dba_temp_files TO NAGIOS ;
######################################################################## ########################################################################
# #
# CONSTANTS # CONSTANTS
@ -25,11 +58,21 @@ REVISION="6.6.6"
# colors # colors
LIGHTGREEN="\033[1;32m" BOLD="\e[1m"
GREEN="\e[32m"
LIGHTGREEN="${BOLD}${GREEN}"
RED="\033[1;31m"
LIGHTRED="\033[1;31m" LIGHTRED="\033[1;31m"
BLUE="\e[34m"
LIGHTBLUE="${BOLD}${BLUE}"
YELLOW="\e[33m"
LIGHTYELLOW="${BOLD}${YELLOW}"
WHITE="\033[0;37m" WHITE="\033[0;37m"
RESET="\033[0;00m" RESET="\033[0;00m"
DEBUG=0
NOHEAD="SET HEAD OFF NOHEAD="SET HEAD OFF
SET PAGES 0 SET PAGES 0
SET FEED OFF" SET FEED OFF"
@ -64,6 +107,71 @@ print_revision() {
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' 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
# W warning
# C critical
# t tns
# d db
# l login
# o ospassword <- NOT NECESSARY
# s sessions
# c cache
# p parsing
# b tablespace
# u undo
# g diskgroup
# f FRA
# r redogen
# k locks
# a dgstats
# o totalspace
usage()
{
echo -e "${LIGHTBLUE}USAGE${RESET}
Mandatory options:
-H destination_hostname
-U oracle_linux_user
-S ORACLE_SID
Optional arguments (required for some checks):
-W warning
-C critical
Checks:
-t
Check remote TNS server
-d
Check remote database (search /bin/ps for PMON process)
-s
Check remote database concurrent active sessions
-l
Attempt a dummy login and alert if not ORA-01017: invalid username/password
-c
Check remote database for library and buffer cache hit ratios
-p
Check remote database for Soft/Hard parse ratios
-b
Check remote database for ALL tablespaces capacity
-u
Check remote database for UNDO tablespace capacity
-f
Check remote database for FLASH_RECOVERY_AREA capacity
-d
Check remote database for diskgroup capacity in ORACLE_ASM_SID (Tipically +ASM1/2...)
-a
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.
-r
Daily check for yesterday's redo generation
-k
Watch for session locks (any lock with return CRITICAL)
-o
Total Space taken by the database Excluding sytem tablespaces.
"
exit 0
}
print_usage() print_usage()
{ {
echo "Usage: echo "Usage:
@ -152,24 +260,24 @@ print_help()
" "
} }
usage() ## getops ### usage()
{ ## getops ### {
# Information options ## getops ### # Information options
case "${1^^}" in ## getops ### case "${1^^}" in
"--HELP"|"-H") ## getops ### "--HELP"|"-H")
print_help ## getops ### print_help
exit $STATE_OK ## getops ### exit $STATE_OK
;; ## getops ### ;;
"--VERSION"|"-V") ## getops ### "--VERSION"|"-V")
print_revision $PROGNAME $REVISION ## getops ### print_revision $PROGNAME $REVISION
exit $STATE_OK ## getops ### exit $STATE_OK
;; ## getops ### ;;
*) ## getops ### *)
print_usage ## getops ### print_usage
exit $STATE_OK ## getops ### exit $STATE_OK
;; ## getops ### ;;
esac ## getops ### esac
} ## getops ### }
oraerror_check() oraerror_check()
@ -224,6 +332,9 @@ reverse_return_values()
# get_remote_oraclehome look for ORACLE_SID on oratab
# so if you don't have ORACLE_SID in the oratab file, it will avoid
# you can add a pseudo dummy line there...
get_remote_oraclehome() get_remote_oraclehome()
{ {
#set -x #set -x
@ -1301,8 +1412,7 @@ select
( select nvl(sum(bytes),0)/1024/1024 temp_size from dba_temp_files ) + ( select nvl(sum(bytes),0)/1024/1024 temp_size from dba_temp_files ) +
( select sum(bytes)/1024/1024 redo_size from sys.v_\\\$log ) + ( select sum(bytes)/1024/1024 redo_size from sys.v_\\\$log ) +
( select sum(BLOCK_SIZE*FILE_SIZE_BLKS)/1024/1024 controlfile_size from v\\\$controlfile) TOTAL_MB ( select sum(BLOCK_SIZE*FILE_SIZE_BLKS)/1024/1024 controlfile_size from v\\\$controlfile) TOTAL_MB
from from dual
dual;
/" /"
;; ;;
"redogen" ) "redogen" )
@ -1438,10 +1548,6 @@ check_userslocked()
check_seqapply() check_seqapply()
{ {
# if [[ ! ${ORACLE_SID^^} = "BAVEL12SGDN" ]] ; then
# echo "CRITICAL - ${ORACLE_SID} Not avalaible for sequece apply check"
# return ${STATE_CRITICAL}
# fi
if [[ "${ORACLE_SID}" =~ (.*)GDN$ ]] ; then if [[ "${ORACLE_SID}" =~ (.*)GDN$ ]] ; then
local AUXSID=${BASH_REMATCH[1]} local AUXSID=${BASH_REMATCH[1]}
#echo ${AUXSID} #echo ${AUXSID}
@ -1491,6 +1597,31 @@ ORDER BY 1;
} }
printmsg()
{
echo -e "$*"
}
abort_message()
{
local let ABORTCODE=1
[[ ${EXITCODE} -ne 0 ]] && ABORTCODE=${EXITCODE}
printmsg "${LIGHTRED}ERROR${RESET}: $*"
exit ${ABORTCODE}
}
# debug_me uses variable ${DEBUG}
debug_me()
{
if [[ "${DEBUG}" && ${DEBUG} -eq 0 ]] ; then
echo -e "${LIGHTBLUE}DEBUG: ${RESET}$*"
fi
}
######################################################################## ########################################################################
# #
# / FUNCTIONS # / FUNCTIONS
@ -1507,27 +1638,25 @@ ORDER BY 1;
PROGNAME=$(basename $0) PROGNAME=$(basename $0)
PROGPATH=$(dirname $0) PROGPATH=$(dirname $0)
## getops ###[ $# -le 1 ] && usage $*
[ $# -le 1 ] && usage $* ## getops ###
## getops ###REMOTE_SERVER=$2 && shift 2
## getops ###
REMOTE_SERVER=$2 && shift 2 ## getops ###if [[ ! ${REMOTE_SERVER} ]]
## getops ###then
if [[ ! ${REMOTE_SERVER} ]] ## getops ### echo "No remote server specified!!!"
then ## getops ### exit ${STATE_UNKNOWN}
echo "No remote server specified!!!" ## getops ###fi
exit ${STATE_UNKNOWN} ## getops ###
fi ## getops #### Checking for non-standard user to connect
## getops ###if [[ "${1}" = "-U" ]]
# Checking for non-standard user to connect ## getops ###then
if [[ "${1}" = "-U" ]] ## getops ### ORACLE_OSUSER=$2 && shift 2
then ## getops ###else
ORACLE_OSUSER=$2 && shift 2 ## getops ### ORACLE_OSUSER="oracle"
else ## getops ###fi
ORACLE_OSUSER="oracle" ## getops ###
fi ## getops ###SSH="ssh ${ORACLE_OSUSER}@${REMOTE_SERVER} -xq"
SSH="ssh ${ORACLE_OSUSER}@${REMOTE_SERVER} -xq"
ORACLEUSER="NAGIOS" ORACLEUSER="NAGIOS"
ORACLEUSERPASSWORD="D2HSHBFMO5IINME9I9WT" ORACLEUSERPASSWORD="D2HSHBFMO5IINME9I9WT"
@ -1544,57 +1673,137 @@ ORACLEUSERPASSWORD="D2HSHBFMO5IINME9I9WT"
# #
######################################################################## ########################################################################
# CLEANING THE COMMAND
COMMAND="${1:2}"
ORACLE_SID="$2"
[[ ! "${COMMAND}" || ! "${ORACLE_SID}" ]] && print_usage && exit ${STATE_UNKNOWN}
while getopts "H:U:S:W:C:tdloscpbugfrhkaDF" arg; do
case $arg in
# H host
H)
REMOTE_SERVER=${OPTARG}
;;
# U oracle user
U)
ORACLE_OSUSER="${OPTARG}"
;;
# S sid
S)
ORACLE_SID="${OPTARG}"
;;
# W warning
W)
WARNING="${OPTARG}"
;;
# C critical
C)
CRITICAL="${OPTARG}"
;;
# t tns
t)
COMMAND="tns"
;;
# d db
d)
COMMAND="db"
;;
# l login
l)
COMMAND="login"
;;
# o ospassword <- not necessary
# o totalspace
o)
#COMMAND="ospassword"
COMMAND="totalspace"
;;
# s sessions
s)
COMMAND="sessions"
;;
# c cache
c)
COMMAND="cache"
;;
# p parsing
p)
COMMAND="parsing"
;;
# b tablespace
b)
#COMMAND="tablespace"
COMMAND="alltablespacesspace"
;;
# u undo
u)
COMMAND="undo"
;;
# g diskgroup
g)
COMMAND="diskgroup"
;;
# f FRA
f)
COMMAND="fra"
;;
# r redogen
r)
COMMAND="redogen"
;;
# k sessionlock
k)
COMMAND="sessionlock"
;;
# a dgstats
a)
COMMAND="dgstats"
;;
h)
usage
;;
F)
MAYTHEFORCEBEWITHYOU=true
echo -e "${LIGHTBLUE}The force is strong in you?${RESET}"
;;
D)
DEBUG=0
;;
*)
usage
;;
esac
done
if [ $# -eq 3 ] ; then # mandatory ops
#ospassword check if [[ ! "${REMOTE_SERVER}" ]] ; then
# the values are REVERSE as it use reverse_return_values debug_me "No REMOTE_SERVER"
CRITICAL=$2 usage
WARNING=$3
if [[ "${WARNING}" && ${CRITICAL} ]] ; then
if [[ ${CRITICAL} -gt ${WARNING} ]] ; then
echo "UNKNOWN - ${COMMAND} CRITICAL level is bigger than WARNING (reverse check)"
exit $STATE_UNKNOWN
fi fi
if [[ ! "${ORACLE_OSUSER}" ]] ; then
debug_me "No ORACLE_OSUSER"
usage
fi fi
else if [[ ! "${ORACLE_SID}" ]] ; then
if [ $# -eq 4 ] ; then debug_me "No ORACLE_SID"
CRITICAL=$3 usage
WARNING=$4
elif [ $# -eq 5 ] ; then
TSDG=$3
CRITICAL=$4
WARNING=$5
fi fi
if [[ "${WARNING}" && ${CRITICAL} ]] ; then if [[ ! "${WARNING}" || ! "${CRITICAL}" ]] ; then
if [[ ${WARNING} -gt ${CRITICAL} ]] ; then debug_me "no warning or critical, maybe this will fail"
echo "UNKNOWN - ${COMMAND} Warning level is less than Critical"
exit $STATE_UNKNOWN
fi fi
if [[ ! "${COMMAND}" ]] ; then
debug_me "No COMMAND received"
usage
fi fi
fi SSH="ssh ${ORACLE_OSUSER}@${REMOTE_SERVER} -xq"
# if the check is not for asmfs, then a ORACLE_HOME is necessary
if ! [[ "${COMMAND}" = "asmfs" || "${COMMAND}" = "ospassword" ]] ; then
get_remote_oraclehome get_remote_oraclehome
RES=$?
if [ ${RES} -ne ${STATE_OK} ] ; then
echo "CRITICAL - No ORACLE_HOME found"
exit $STATE_UNKNOWN
fi
#
fi
# SQLPLUS FOR CONNECTIONS # SQLPLUS FOR CONNECTIONS
SQLPLUS="sqlplus -s '${ORACLEUSER}/${ORACLEUSERPASSWORD}@${ORACLE_SID}'" SQLPLUS="sqlplus -s '${ORACLEUSER}/${ORACLEUSERPASSWORD}@${ORACLE_SID}'"
ORAENV="ORACLE_HOME=${ORACLE_HOME};PATH=$PATH:$ORACLE_HOME/bin;LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib;export ORACLE_HOME PATH LD_LIBRARY_PATH;" ORAENV="ORACLE_HOME=${ORACLE_HOME};PATH=$PATH:$ORACLE_HOME/bin;LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib;export ORACLE_HOME PATH LD_LIBRARY_PATH;"
debug_me "${SSH}"
debug_me "${SQLPLUS}"
debug_me "${ORAENV}"
debug_me "${COMMAND}"
case "${COMMAND}" in case "${COMMAND}" in
@ -1674,7 +1883,6 @@ case "${COMMAND}" in
RES=$? RES=$?
;; ;;
"dgstats") "dgstats")
# dataguard_stats
dataguard_stats_new dataguard_stats_new
RES=$? RES=$?
;; ;;