getops first version

This commit is contained in:
dodger 2022-05-11 18:14:55 +02:00
parent 0dd36a05bd
commit ac6ec92e03
Signed by: dodger
GPG Key ID: F6701F6CB4D1C826

View File

@ -25,11 +25,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 +74,50 @@ 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
# s sessions
# c cache
# p parsing
# b tablespace
# u undo
# g diskgroup
# f FRA
# r redogen
usage()
{
echo -e "${LIGHTBLUE}USAGE${RESET}
# H host
# U oracle user
# S sid
# W warning
# C critical
# t tns
# d db
# l login
# o ospassword
# s sessions
# c cache
# p parsing
# b tablespace
# u undo
# g diskgroup
# f FRA
# r redogen
"
exit 0
}
print_usage() print_usage()
{ {
echo "Usage: echo "Usage:
@ -152,24 +206,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()
@ -1438,10 +1492,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}
@ -1507,27 +1557,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,52 +1592,131 @@ ORACLEUSERPASSWORD="D2HSHBFMO5IINME9I9WT"
# #
######################################################################## ########################################################################
# CLEANING THE COMMAND
COMMAND="${1:2}"
ORACLE_SID="$2"
[[ ! "${COMMAND}" || ! "${ORACLE_SID}" ]] && print_usage && exit ${STATE_UNKNOWN}
if [ $# -eq 3 ] ; then # H host
#ospassword check # U oracle user
# the values are REVERSE as it use reverse_return_values # S sid
CRITICAL=$2 # W warning
WARNING=$3 # C critical
# t tns
# d db
# l login
# o ospassword
# s sessions
# c cache
# p parsing
# b tablespace
# u undo
# g diskgroup
# f FRA
# r redogen
if [[ "${WARNING}" && ${CRITICAL} ]] ; then while getopts "H:U:S:W:C:tdloscpbugfrhDF" arg; do
if [[ ${CRITICAL} -gt ${WARNING} ]] ; then case $arg in
echo "UNKNOWN - ${COMMAND} CRITICAL level is bigger than WARNING (reverse check)" # H host
exit $STATE_UNKNOWN H)
fi REMOTE_SERVER=${OPTARG}
fi ;;
else # U oracle user
if [ $# -eq 4 ] ; then U)
CRITICAL=$3 ORACLE_OSUSER="${OPTARG}"
WARNING=$4 ;;
elif [ $# -eq 5 ] ; then # S sid
TSDG=$3 S)
CRITICAL=$4 ORACLE_SID="${OPTARG}"
WARNING=$5 ;;
fi # W warning
if [[ "${WARNING}" && ${CRITICAL} ]] ; then W)
if [[ ${WARNING} -gt ${CRITICAL} ]] ; then WARNING="${OPTARG}"
echo "UNKNOWN - ${COMMAND} Warning level is less than Critical" ;;
exit $STATE_UNKNOWN # C critical
fi C)
fi CRITICAL="${OPTARG}"
;;
# t tns
t)
COMMAND="tns"
;;
# d db
d)
COMMAND="db"
;;
# l login
l)
COMMAND="login"
;;
# o ospassword
o)
COMMAND="ospassword"
;;
# s sessions
s)
COMMAND="sessions"
;;
# c cache
c)
COMMAND="cache"
;;
# p parsing
p)
COMMAND="parsing"
;;
# b tablespace
b)
COMMAND="tablespace"
;;
# u undo
u)
COMMAND="undo"
;;
# g diskgroup
g)
COMMAND="diskgroup"
;;
# f FRA
f)
COMMAND="fra"
;;
# r redogen
r)
COMMAND="redogen"
;;
h)
usage
;;
F)
MAYTHEFORCEBEWITHYOU=true
echo -e "${LIGHTBLUE}The force is strong in you?${RESET}"
;;
D)
DEBUG=0
;;
*)
usage
;;
esac
done
# mandatory ops
if [[ ! "${REMOTE_SERVER}" ]] ; then
usage
fi
if [[ ! "${ORACLE_OSUSER}" ]] ; then
usage
fi
if [[ ! "${ORACLE_SID}" ]] ; then
usage
fi
if [[ ! "${WARNING}" || ! "${CRITICAL}" ]] ; then
usage
fi fi
# if the check is not for asmfs, then a ORACLE_HOME is necessary
if ! [[ "${COMMAND}" = "asmfs" || "${COMMAND}" = "ospassword" ]] ; then
get_remote_oraclehome SSH="ssh ${ORACLE_OSUSER}@${REMOTE_SERVER} -xq"
RES=$?
if [ ${RES} -ne ${STATE_OK} ] ; then get_remote_oraclehome
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}'"
@ -1597,6 +1724,65 @@ ORAENV="ORACLE_HOME=${ORACLE_HOME};PATH=$PATH:$ORACLE_HOME/bin;LD_LIBRARY_PATH=$
echo -e "${SSH}"
echo -e "${SQLPLUS}"
echo -e "${ORAENV}"
echo -e "${COMMAND}"
exit 0
## getops ### # CLEANING THE COMMAND
## getops ### COMMAND="${1:2}"
## getops ### ORACLE_SID="$2"
## getops ### [[ ! "${COMMAND}" || ! "${ORACLE_SID}" ]] && print_usage && exit ${STATE_UNKNOWN}
## getops ### if [ $# -eq 3 ] ; then
## getops ### #ospassword check
## getops ### # the values are REVERSE as it use reverse_return_values
## getops ### CRITICAL=$2
## getops ### WARNING=$3
## getops ###
## getops ### if [[ "${WARNING}" && ${CRITICAL} ]] ; then
## getops ### if [[ ${CRITICAL} -gt ${WARNING} ]] ; then
## getops ### echo "UNKNOWN - ${COMMAND} CRITICAL level is bigger than WARNING (reverse check)"
## getops ### exit $STATE_UNKNOWN
## getops ### fi
## getops ### fi
## getops ### else
## getops ### if [ $# -eq 4 ] ; then
## getops ### CRITICAL=$3
## getops ### WARNING=$4
## getops ### elif [ $# -eq 5 ] ; then
## getops ### TSDG=$3
## getops ### CRITICAL=$4
## getops ### WARNING=$5
## getops ### fi
## getops ### if [[ "${WARNING}" && ${CRITICAL} ]] ; then
## getops ### if [[ ${WARNING} -gt ${CRITICAL} ]] ; then
## getops ### echo "UNKNOWN - ${COMMAND} Warning level is less than Critical"
## getops ### exit $STATE_UNKNOWN
## getops ### fi
## getops ### fi
## getops ###
## getops ### fi
## getops ### # if the check is not for asmfs, then a ORACLE_HOME is necessary
## getops ### if ! [[ "${COMMAND}" = "asmfs" || "${COMMAND}" = "ospassword" ]] ; then
## getops ### get_remote_oraclehome
## getops ### RES=$?
## getops ### if [ ${RES} -ne ${STATE_OK} ] ; then
## getops ### echo "CRITICAL - No ORACLE_HOME found"
## getops ### exit $STATE_UNKNOWN
## getops ### fi
## getops ### #
## getops ### fi
## getops ### # SQLPLUS FOR CONNECTIONS
## getops ### SQLPLUS="sqlplus -s '${ORACLEUSER}/${ORACLEUSERPASSWORD}@${ORACLE_SID}'"
## getops ### 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;"
case "${COMMAND}" in case "${COMMAND}" in
"tns") "tns")
check_tns check_tns