Compare commits

..

No commits in common. "shellcheck" and "master" have entirely different histories.

View File

@ -100,6 +100,15 @@ 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
support() {
printf "%sSend email to nagios-users@lists.sourceforge.net if you have questions\nregarding use of this software. To submit patches or suggest improvements,\nsend email to nagiosplug-devel@lists.sourceforge.net.\nPlease include version information with all correspondence (when possible,\nuse output from the --version option of the plugin itself).\n" | sed -e 's/\n/ /g'
}
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
@ -165,6 +174,114 @@ 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="$*"
@ -177,7 +294,7 @@ oraerror_check()
return_values() return_values()
{ {
local VALUE=$1 local let VALUE=$1
if [[ ${VALUE} -gt ${CRITICAL} ]] ; then if [[ ${VALUE} -gt ${CRITICAL} ]] ; then
MSG="CRITICAL" MSG="CRITICAL"
RETURNCODE=${STATE_CRITICAL} RETURNCODE=${STATE_CRITICAL}
@ -197,7 +314,7 @@ return_values()
reverse_return_values() reverse_return_values()
{ {
local VALUE=$1 local let VALUE=$1
if [[ ${VALUE} -lt ${CRITICAL} ]] ; then if [[ ${VALUE} -lt ${CRITICAL} ]] ; then
MSG="CRITICAL" MSG="CRITICAL"
RETURNCODE=${STATE_CRITICAL} RETURNCODE=${STATE_CRITICAL}
@ -224,11 +341,11 @@ get_remote_oraclehome()
{ {
#set -x #set -x
# Hunt down a reasonable ORACLE_HOME # Hunt down a reasonable ORACLE_HOME
ORATABLIST="$(${SSH} "locate oratab" | grep -E "/oratab$" | tr '\n' ' ')" ORATABLIST="$(${SSH} "locate oratab" | egrep "/oratab$" | tr '\n' ' ')"
for ORATAB in ${ORATABLIST} ; do for ORATAB in ${ORATABLIST} ; do
ORACLE_HOME=$(${SSH} "cat ${ORATAB}" | grep -E "^(${ORACLE_SID}|\*):" | awk -F: '{print $2}') 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 if [[ "${ORACLE_HOME}" ]] && [ $($SSH "ls -d ${ORACLE_HOME}" |wc -l) -eq 1 ] ; then
return 0 return 0
fi fi
done done
@ -238,8 +355,7 @@ get_remote_oraclehome()
check_tns() check_tns()
{ {
local AUX="${ORAENV} tnsping ${ORACLE_SID}" local AUX="${ORAENV} tnsping ${ORACLE_SID}"
local TNSCHECK local TNSCHECK="$(${SSH} ${AUX})"
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}
@ -250,9 +366,8 @@ check_tns()
check_db() check_db()
{ {
local PMONCHECK local PMONCHECK="$(${SSH} "ps -ef" | egrep -v grep | grep -c "ora_pmon_${ORACLE_SID}")"
PMONCHECK="$(${SSH} "ps -ef" | grep -Ev grep | grep -c "ora_pmon_${ORACLE_SID}")" if [ ${PMONCHECK} -ge 1 ] ; then
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
@ -276,8 +391,8 @@ check_login()
check_total_sessions() check_total_sessions()
{ {
local RETURNCODE=${STATE_UNKNOWN} local let RETURNCODE=${STATE_UNKNOWN}
local TOTALSESSIONS=0 local let TOTALSESSIONS=0
local QUERY="${NOHEAD} local QUERY="${NOHEAD}
set numf 99999 set numf 99999
@ -306,11 +421,11 @@ and not username in ('SYS', 'PUBLIC', 'NAGIOS' )
check_asessions_v3() check_asessions_v3()
{ {
local RETURNCODE=${STATE_UNKNOWN} local let RETURNCODE=${STATE_UNKNOWN}
local MAXINDEX=0 local let MAXINDEX=0
local i=0 local let i=0
local x=0 local let x=0
local TOTALSESSIONS=0 local let TOTALSESSIONS=0
declare -a RESSULTARRAY declare -a RESSULTARRAY
declare -a RESSULTUSERS declare -a RESSULTUSERS
@ -358,10 +473,10 @@ order by 1
check_sharedpool() check_sharedpool()
{ {
local RETURNCODE=${STATE_UNKNOWN} local let RETURNCODE=${STATE_UNKNOWN}
local SHAREDFREE=0 local let SHAREDFREE=0
local SHAREDTOTAL=0 local let SHAREDTOTAL=0
local SHAREDPERCENT=100 local let 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;
@ -420,7 +535,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 RETURNCODE=${STATE_UNKNOWN} local let RETURNCODE=${STATE_UNKNOWN}
local QUERY="${NOHEAD} local QUERY="${NOHEAD}
set numf 99 set numf 99
select count(SES.SID) select count(SES.SID)
@ -450,8 +565,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 RETURNCODE=${STATE_UNKNOWN} local let RETURNCODE=${STATE_UNKNOWN}
local TOTALSESSIONS=0 local let TOTALSESSIONS=0
local PERFDATA="" local PERFDATA=""
local QUERY="${NOHEAD} local QUERY="${NOHEAD}
set numf 999 set numf 999