Refactored check_linux_fs_usage() + check_hpux_fs_usage() plugin to support exceptions in the config file while still checking everything else
This commit is contained in:
parent
c9c02c0d0f
commit
70b9ae3d4a
@ -27,12 +27,18 @@ max_inodes_usage=90
|
|||||||
# [default: 90]
|
# [default: 90]
|
||||||
max_space_usage=90
|
max_space_usage=90
|
||||||
|
|
||||||
# specify mount points and their maximum usage (in %). Leave undefined to
|
# specify mount points and their maximum usage (in %). When not defining a threshold
|
||||||
# perform check on all active filesystems. When not defining individual thresholds
|
# for a given filesystem, the general threshold will be used (see above). When
|
||||||
# for a given filesystem, the general threshold will be used (see above)
|
# defining a threshold of 0 (zero), then the check will for this give filesystem
|
||||||
|
# will be skipped (this allows for exclusion of filesystems)
|
||||||
# [fs:<mount_point>:<max_inode_usage_%>:<max_space_usage_%]
|
# [fs:<mount_point>:<max_inode_usage_%>:<max_space_usage_%]
|
||||||
|
# Examples:
|
||||||
|
# check myfs1 with a custom inodes + space usage threshold
|
||||||
#fs:myfs1:70:95
|
#fs:myfs1:70:95
|
||||||
#fs:myfs2:75:90
|
# check myfs2 with the general inodes usage threshold & a custom space usage threshold
|
||||||
|
#fs:myfs2::80
|
||||||
|
# check myfs3 with a custom inodes usage threshold & do not check the space usage
|
||||||
|
#fs:myfs3:99:0
|
||||||
|
|
||||||
|
|
||||||
#******************************************************************************
|
#******************************************************************************
|
||||||
|
@ -27,12 +27,18 @@ max_inodes_usage=90
|
|||||||
# [default: 90]
|
# [default: 90]
|
||||||
max_space_usage=90
|
max_space_usage=90
|
||||||
|
|
||||||
# specify mount points and their maximum usage (in %). Leave undefined to
|
# specify mount points and their maximum usage (in %). When not defining a threshold
|
||||||
# perform check on all active filesystems. When not defining individual thresholds
|
# for a given filesystem, the general threshold will be used (see above). When
|
||||||
# for a given filesystem, the general threshold will be used (see above)
|
# defining a threshold of 0 (zero), then the check will for this give filesystem
|
||||||
|
# will be skipped (this allows for exclusion of filesystems)
|
||||||
# [fs:<mount_point>:<max_inode_usage_%>:<max_space_usage_%]
|
# [fs:<mount_point>:<max_inode_usage_%>:<max_space_usage_%]
|
||||||
|
# Examples:
|
||||||
|
# check myfs1 with a custom inodes + space usage threshold
|
||||||
#fs:myfs1:70:95
|
#fs:myfs1:70:95
|
||||||
#fs:myfs2:75:90
|
# check myfs2 with the general inodes usage threshold & a custom space usage threshold
|
||||||
|
#fs:myfs2::80
|
||||||
|
# check myfs3 with a custom inodes usage threshold & do not check the space usage
|
||||||
|
#fs:myfs3:99:0
|
||||||
|
|
||||||
|
|
||||||
#******************************************************************************
|
#******************************************************************************
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
# @(#) HISTORY:
|
# @(#) HISTORY:
|
||||||
# @(#) 2019-01-24: initial version [Patrick Van der Veken]
|
# @(#) 2019-01-24: initial version [Patrick Van der Veken]
|
||||||
# @(#) 2019-01-27: regex fix [Patrick Van der Veken]
|
# @(#) 2019-01-27: regex fix [Patrick Van der Veken]
|
||||||
|
# @(#) 2019-01-30: refactored to support custom defintions with all
|
||||||
|
# filesystems check [Patrick Van der Veken]
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
|
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
|
||||||
#******************************************************************************
|
#******************************************************************************
|
||||||
@ -33,7 +35,7 @@ function check_hpux_fs_usage
|
|||||||
{
|
{
|
||||||
# ------------------------- CONFIGURATION starts here -------------------------
|
# ------------------------- CONFIGURATION starts here -------------------------
|
||||||
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
|
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
|
||||||
typeset _VERSION="2019-01-27" # YYYY-MM-DD
|
typeset _VERSION="2019-01-30" # YYYY-MM-DD
|
||||||
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
|
typeset _SUPPORTED_PLATFORMS="HP-UX" # uname -s match
|
||||||
# ------------------------- CONFIGURATION ends here ---------------------------
|
# ------------------------- CONFIGURATION ends here ---------------------------
|
||||||
|
|
||||||
@ -50,7 +52,6 @@ typeset _CFG_CHECK_INODES_USAGE=""
|
|||||||
typeset _CFG_CHECK_SPACE_USAGE=""
|
typeset _CFG_CHECK_SPACE_USAGE=""
|
||||||
typeset _CFG_MAX_INODES_USAGE=""
|
typeset _CFG_MAX_INODES_USAGE=""
|
||||||
typeset _CFG_MAX_SPACE_USAGE=""
|
typeset _CFG_MAX_SPACE_USAGE=""
|
||||||
typeset _CFG_FS=""
|
|
||||||
typeset _CFG_INODES_THRESHOLD=""
|
typeset _CFG_INODES_THRESHOLD=""
|
||||||
typeset _CFG_SPACE_THRESHOLD=""
|
typeset _CFG_SPACE_THRESHOLD=""
|
||||||
typeset _FS=""
|
typeset _FS=""
|
||||||
@ -58,7 +59,6 @@ typeset _DO_INODES=0
|
|||||||
typeset _DO_SPACE=0
|
typeset _DO_SPACE=0
|
||||||
typeset _INODES_USAGE=1
|
typeset _INODES_USAGE=1
|
||||||
typeset _SPACE_USAGE=1
|
typeset _SPACE_USAGE=1
|
||||||
typeset _LINE_COUNT=1
|
|
||||||
|
|
||||||
# handle arguments (originally comma-separated)
|
# handle arguments (originally comma-separated)
|
||||||
for _ARG in ${_ARGS}
|
for _ARG in ${_ARGS}
|
||||||
@ -159,154 +159,124 @@ then
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check for each configured filesystem or for all
|
# 1) validate inodes (df -Pil)
|
||||||
if (( $(grep -c -i '^fs:' ${_CONFIG_FILE} 2>/dev/null) > 0 ))
|
if (( _DO_INODES > 0 ))
|
||||||
then
|
then
|
||||||
# 1) --- configured FS ---
|
(( ARG_DEBUG > 0 )) && debug "checking inodes..."
|
||||||
# a) --- inodes ---
|
|
||||||
if (( _DO_INODES > 0 ))
|
|
||||||
then
|
|
||||||
_LINE_COUNT=1
|
|
||||||
grep -i '^fs:' ${_CONFIG_FILE} 2>/dev/null |\
|
|
||||||
while IFS=':' read _ _CFG_FS _CFG_INODES_THRESHOLD _
|
|
||||||
do
|
|
||||||
# report on missing FS name of threshold
|
|
||||||
if [[ -z "${_CFG_FS}" ]] && [[ -z "${_CFG_INODES_THRESHOLD}" ]]
|
|
||||||
then
|
|
||||||
warn "missing filesystem name and/or threshold in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
data_is_numeric "${_CFG_INODES_THRESHOLD}"
|
|
||||||
if (( $? > 0 ))
|
|
||||||
then
|
|
||||||
warn "parameter is not numeric in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
if (( _CFG_INODES_THRESHOLD == 0 || _CFG_INODES_THRESHOLD >= 100 ))
|
|
||||||
then
|
|
||||||
(( ARG_DEBUG > 0 )) && debug "found out-of-bounds inodes threshold for ${_CFG_FS}, using general threshold"
|
|
||||||
_CFG_INODES_THRESHOLD=${_CFG_MAX_INODES_USAGE}
|
|
||||||
fi
|
|
||||||
# add space to grep must be non-greedy!
|
|
||||||
_INODES_USAGE=$(grep -E -e "^${_CFG_FS} " ${HC_STDOUT_LOG} 2>/dev/null | awk '{print $2}' 2>/dev/null)
|
|
||||||
data_is_numeric "${_INODES_USAGE}"
|
|
||||||
if (( $? > 0 ))
|
|
||||||
then
|
|
||||||
warn "discovered value for inode usage is incorrect [${_CFG_FS}:${_INODES_USAGE}]"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
# check against the threshold
|
|
||||||
if (( _INODES_USAGE > _CFG_INODES_THRESHOLD ))
|
|
||||||
then
|
|
||||||
_MSG="${_CFG_FS} exceedes its inode threshold (${_INODES_USAGE}%>${_CFG_INODES_THRESHOLD}%)"
|
|
||||||
_STC=1
|
|
||||||
else
|
|
||||||
_MSG="${_CFG_FS} does not exceede its inode threshold (${_INODES_USAGE}%<=${_CFG_INODES_THRESHOLD}%)"
|
|
||||||
_STC=0
|
|
||||||
fi
|
|
||||||
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
|
|
||||||
then
|
|
||||||
log_hc "$0" ${_STC} "${_MSG}" ${_INODES_USAGE} ${_CFG_INODES_THRESHOLD}
|
|
||||||
fi
|
|
||||||
_LINE_COUNT=$(( _LINE_COUNT + 1 ))
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
# a) --- space ---
|
|
||||||
if (( _DO_SPACE > 0 ))
|
|
||||||
then
|
|
||||||
_LINE_COUNT=1
|
|
||||||
grep -i '^fs:' ${_CONFIG_FILE} 2>/dev/null |\
|
|
||||||
while IFS=':' read _ _CFG_FS _ _CFG_SPACE_THRESHOLD _
|
|
||||||
do
|
|
||||||
# report on missing FS name of threshold
|
|
||||||
if [[ -z "${_CFG_FS}" ]] && [[ -z "${_CFG_SPACE_THRESHOLD}" ]]
|
|
||||||
then
|
|
||||||
warn "missing filesystem name and/or threshold in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
data_is_numeric "${_CFG_SPACE_THRESHOLD}"
|
|
||||||
if (( $? > 0 ))
|
|
||||||
then
|
|
||||||
warn "parameter is not numeric in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
if (( _CFG_SPACE_THRESHOLD == 0 || _CFG_SPACE_THRESHOLD >= 100 ))
|
|
||||||
then
|
|
||||||
(( ARG_DEBUG > 0 )) && debug "found out-of-bounds space threshold for ${_CFG_FS}, using general threshold"
|
|
||||||
_CFG_SPACE_THRESHOLD=${_CFG_MAX_SPACE_USAGE}
|
|
||||||
fi
|
|
||||||
# add space to grep must be non-greedy!
|
|
||||||
_SPACE_USAGE=$(grep -E -e "^${_CFG_FS} " ${HC_STDOUT_LOG} 2>/dev/null | awk '{print $3}' 2>/dev/null)
|
|
||||||
data_is_numeric "${_SPACE_USAGE}"
|
|
||||||
if (( $? > 0 ))
|
|
||||||
then
|
|
||||||
warn "discovered value for space usage is incorrect [${_CFG_FS}:${_SPACE_USAGE}]"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
# check against the threshold
|
|
||||||
if (( _SPACE_USAGE > _CFG_SPACE_THRESHOLD ))
|
|
||||||
then
|
|
||||||
_MSG="${_CFG_FS} exceedes its space threshold (${_SPACE_USAGE}%>${_CFG_SPACE_THRESHOLD}%)"
|
|
||||||
_STC=1
|
|
||||||
else
|
|
||||||
_MSG="${_CFG_FS} does not exceede its space threshold (${_SPACE_USAGE}%<=${_CFG_SPACE_THRESHOLD}%)"
|
|
||||||
_STC=0
|
|
||||||
fi
|
|
||||||
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
|
|
||||||
then
|
|
||||||
log_hc "$0" ${_STC} "${_MSG}" ${_SPACE_USAGE} ${_CFG_SPACE_THRESHOLD}
|
|
||||||
fi
|
|
||||||
_LINE_COUNT=$(( _LINE_COUNT + 1 ))
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
# 2) --- ALL FS ---
|
|
||||||
grep '^\/' ${HC_STDOUT_LOG} 2>/dev/null | awk '{print $1}' 2>/dev/null |\
|
grep '^\/' ${HC_STDOUT_LOG} 2>/dev/null | awk '{print $1}' 2>/dev/null |\
|
||||||
while read _FS
|
while read _FS
|
||||||
do
|
do
|
||||||
# a) --- inodes ---
|
(( ARG_DEBUG > 0 )) && debug "parsing inodes data for filesystem: ${_FS}"
|
||||||
# add space to grep must be non-greedy!
|
# add space to grep; must be non-greedy!
|
||||||
_INODES_USAGE=$(grep "^${_FS} " ${HC_STDOUT_LOG} 2>/dev/null | awk '{print $2}' 2>/dev/null)
|
_INODES_USAGE=$(grep "^${_FS} " ${HC_STDOUT_LOG} 2>/dev/null | awk '{print $2}' 2>/dev/null)
|
||||||
data_is_numeric "${_INODES_USAGE}"
|
data_is_numeric "${_INODES_USAGE}"
|
||||||
if (( $? > 0 ))
|
if (( $? > 0 ))
|
||||||
then
|
then
|
||||||
warn "discovered value for inode usage is incorrect [${_FS}:${_INODES_USAGE}]"
|
warn "discovered value for inodes usage is incorrect [${_FS}:${_INODES_USAGE}]"
|
||||||
|
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
# check against the threshold
|
# which threshold to use (general or custom?)
|
||||||
if (( _INODES_USAGE > _CFG_MAX_INODES_USAGE ))
|
_CFG_FS_LINE=$(grep -E -e "^fs:${_FS}:" ${_CONFIG_FILE} 2>/dev/null)
|
||||||
|
if [[ -n "${_CFG_FS_LINE}" ]]
|
||||||
then
|
then
|
||||||
_MSG="${_FS} exceedes its inode threshold (${_INODES_USAGE}%>${_CFG_MAX_INODES_USAGE}%)"
|
(( ARG_DEBUG > 0 )) && debug "found custom definition for ${_FS} in configuration file ${_CONFIG_FILE}"
|
||||||
|
_CFG_INODES_THRESHOLD=$(print "${_CFG_FS_LINE}" | cut -f3 -d':' 2>/dev/null)
|
||||||
|
# null value means general threshold
|
||||||
|
if [[ -z "${_CFG_INODES_THRESHOLD}" ]]
|
||||||
|
then
|
||||||
|
(( ARG_DEBUG > 0 )) && debug "found empty inodes threshold for ${_FS}, using general threshold"
|
||||||
|
_CFG_INODES_THRESHOLD=${_CFG_MAX_INODES_USAGE}
|
||||||
|
fi
|
||||||
|
data_is_numeric "${_CFG_INODES_THRESHOLD}"
|
||||||
|
if (( $? > 0 ))
|
||||||
|
then
|
||||||
|
warn "inodes parameter is not numeric for ${_FS} in configuration file ${_CONFIG_FILE}"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
# zero value means disabled check
|
||||||
|
if (( _CFG_INODES_THRESHOLD == 0 ))
|
||||||
|
then
|
||||||
|
(( ARG_DEBUG > 0 )) && debug "found zero inodes threshold for ${_FS}, disabling check"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
(( ARG_DEBUG > 0 )) && debug "no custom inodes threshold for ${_FS}, using general threshold"
|
||||||
|
_CFG_INODES_THRESHOLD=${_CFG_MAX_INODES_USAGE}
|
||||||
|
fi
|
||||||
|
# check against the tresholdd
|
||||||
|
if (( _INODES_USAGE > _CFG_INODES_THRESHOLD ))
|
||||||
|
then
|
||||||
|
_MSG="${_FS} exceedes its inode threshold (${_INODES_USAGE}%>${_CFG_INODES_THRESHOLD}%)"
|
||||||
_STC=1
|
_STC=1
|
||||||
else
|
else
|
||||||
_MSG="${_FS} does not exceede its inode threshold (${_INODES_USAGE}%<=${_CFG_MAX_INODES_USAGE}%)"
|
_MSG="${_FS} does not exceede its inode threshold (${_INODES_USAGE}%<=${_CFG_INODES_THRESHOLD}%)"
|
||||||
_STC=0
|
_STC=0
|
||||||
fi
|
fi
|
||||||
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
|
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
|
||||||
then
|
then
|
||||||
log_hc "$0" ${_STC} "${_MSG}" ${_INODES_USAGE} ${_CFG_MAX_INODES_USAGE}
|
log_hc "$0" ${_STC} "${_MSG}" ${_INODES_USAGE} ${_CFG_INODES_THRESHOLD}
|
||||||
fi
|
fi
|
||||||
# b) --- space ---
|
done
|
||||||
# add space to grep must be non-greedy!
|
fi
|
||||||
_SPACE_USAGE=$(grep "^${_FS} " ${HC_STDOUT_LOG} 2>/dev/null | awk '{print $3}' 2>/dev/null)
|
|
||||||
|
# 2) validate space (df -Pl)
|
||||||
|
if (( _DO_SPACE > 0 ))
|
||||||
|
then
|
||||||
|
(( ARG_DEBUG > 0 )) && debug "checking space..."
|
||||||
|
grep '^\/' ${HC_STDOUT_LOG} 2>/dev/null | awk '{print $1}' 2>/dev/null |\
|
||||||
|
while read _FS
|
||||||
|
do
|
||||||
|
(( ARG_DEBUG > 0 )) && debug "parsing space data for filesystem: ${_FS}"
|
||||||
|
# add space to grep; must be non-greedy!
|
||||||
|
_SPACE_USAGE=$(grep -E -e "^${_FS} " ${HC_STDOUT_LOG} 2>/dev/null | awk '{print $3}' 2>/dev/null)
|
||||||
data_is_numeric "${_SPACE_USAGE}"
|
data_is_numeric "${_SPACE_USAGE}"
|
||||||
if (( $? > 0 ))
|
if (( $? > 0 ))
|
||||||
then
|
then
|
||||||
warn "discovered value for space usage is incorrect [${_FS}:${_SPACE_USAGE}]"
|
warn "discovered value for space usage is incorrect [${_FS}:${_SPACE_USAGE}]"
|
||||||
|
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
# check against the threshold
|
# which threshold to use (general or custom?)
|
||||||
if (( _SPACE_USAGE > _CFG_MAX_SPACE_USAGE ))
|
_CFG_FS_LINE=$(grep -E -e "^fs:${_FS}:" ${_CONFIG_FILE} 2>/dev/null)
|
||||||
|
if [[ -n "${_CFG_FS_LINE}" ]]
|
||||||
then
|
then
|
||||||
_MSG="${_FS} exceedes its space threshold (${_SPACE_USAGE}%>${_CFG_MAX_SPACE_USAGE}%)"
|
(( ARG_DEBUG > 0 )) && debug "found custom definition for ${_FS} in configuration file ${_CONFIG_FILE}"
|
||||||
|
_CFG_SPACE_THRESHOLD=$(print "${_CFG_FS_LINE}" | cut -f4 -d':' 2>/dev/null)
|
||||||
|
# null value means general threshold
|
||||||
|
if [[ -z "${_CFG_SPACE_THRESHOLD}" ]]
|
||||||
|
then
|
||||||
|
(( ARG_DEBUG > 0 )) && debug "found empty space threshold for ${_FS}, using general threshold"
|
||||||
|
_CFG_SPACE_THRESHOLD=${_CFG_MAX_SPACE_USAGE}
|
||||||
|
fi
|
||||||
|
data_is_numeric "${_CFG_SPACE_THRESHOLD}"
|
||||||
|
if (( $? > 0 ))
|
||||||
|
then
|
||||||
|
warn "space parameter is not numeric for ${_FS} in configuration file ${_CONFIG_FILE}"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
# zero value means disabled check
|
||||||
|
if (( _CFG_SPACE_THRESHOLD == 0 ))
|
||||||
|
then
|
||||||
|
(( ARG_DEBUG > 0 )) && debug "found zero space threshold for ${_FS}, disabling check"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
(( ARG_DEBUG > 0 )) && debug "no custom space threshold for ${_FS}, using general threshold"
|
||||||
|
_CFG_SPACE_THRESHOLD=${_CFG_MAX_SPACE_USAGE}
|
||||||
|
fi
|
||||||
|
# check against the treshold
|
||||||
|
if (( _SPACE_USAGE > _CFG_SPACE_THRESHOLD ))
|
||||||
|
then
|
||||||
|
_MSG="${_FS} exceedes its space threshold (${_SPACE_USAGE}%>${_CFG_SPACE_THRESHOLD}%)"
|
||||||
_STC=1
|
_STC=1
|
||||||
else
|
else
|
||||||
_MSG="${_FS} does not exceede its space threshold (${_SPACE_USAGE}%<=${_CFG_MAX_SPACE_USAGE}%)"
|
_MSG="${_FS} does not exceede its space threshold (${_SPACE_USAGE}%<=${_CFG_SPACE_THRESHOLD}%)"
|
||||||
_STC=0
|
_STC=0
|
||||||
fi
|
fi
|
||||||
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
|
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
|
||||||
then
|
then
|
||||||
log_hc "$0" ${_STC} "${_MSG}" ${_SPACE_USAGE} ${_CFG_MAX_SPACE_USAGE}
|
log_hc "$0" ${_STC} "${_MSG}" ${_SPACE_USAGE} ${_CFG_SPACE_THRESHOLD}
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
# @(#) HISTORY:
|
# @(#) HISTORY:
|
||||||
# @(#) 2019-01-24: initial version [Patrick Van der Veken]
|
# @(#) 2019-01-24: initial version [Patrick Van der Veken]
|
||||||
# @(#) 2019-01-27: regex fix [Patrick Van der Veken]
|
# @(#) 2019-01-27: regex fix [Patrick Van der Veken]
|
||||||
|
# @(#) 2019-01-30: refactored to support custom defintions with all
|
||||||
|
# filesystems check [Patrick Van der Veken]
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
|
# DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!
|
||||||
#******************************************************************************
|
#******************************************************************************
|
||||||
@ -33,7 +35,7 @@ function check_linux_fs_usage
|
|||||||
{
|
{
|
||||||
# ------------------------- CONFIGURATION starts here -------------------------
|
# ------------------------- CONFIGURATION starts here -------------------------
|
||||||
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
|
typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf"
|
||||||
typeset _VERSION="2019-01-27" # YYYY-MM-DD
|
typeset _VERSION="2019-01-30" # YYYY-MM-DD
|
||||||
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
|
typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match
|
||||||
# ------------------------- CONFIGURATION ends here ---------------------------
|
# ------------------------- CONFIGURATION ends here ---------------------------
|
||||||
|
|
||||||
@ -50,7 +52,6 @@ typeset _CFG_CHECK_INODES_USAGE=""
|
|||||||
typeset _CFG_CHECK_SPACE_USAGE=""
|
typeset _CFG_CHECK_SPACE_USAGE=""
|
||||||
typeset _CFG_MAX_INODES_USAGE=""
|
typeset _CFG_MAX_INODES_USAGE=""
|
||||||
typeset _CFG_MAX_SPACE_USAGE=""
|
typeset _CFG_MAX_SPACE_USAGE=""
|
||||||
typeset _CFG_FS=""
|
|
||||||
typeset _CFG_INODES_THRESHOLD=""
|
typeset _CFG_INODES_THRESHOLD=""
|
||||||
typeset _CFG_SPACE_THRESHOLD=""
|
typeset _CFG_SPACE_THRESHOLD=""
|
||||||
typeset _FS=""
|
typeset _FS=""
|
||||||
@ -58,7 +59,6 @@ typeset _DO_INODES=0
|
|||||||
typeset _DO_SPACE=0
|
typeset _DO_SPACE=0
|
||||||
typeset _INODES_USAGE=1
|
typeset _INODES_USAGE=1
|
||||||
typeset _SPACE_USAGE=1
|
typeset _SPACE_USAGE=1
|
||||||
typeset _LINE_COUNT=1
|
|
||||||
typeset _INODES_FILE="${TMP_DIR}/.$0.inodes.$$"
|
typeset _INODES_FILE="${TMP_DIR}/.$0.inodes.$$"
|
||||||
typeset _SPACE_FILE="${TMP_DIR}/.$0.space.$$"
|
typeset _SPACE_FILE="${TMP_DIR}/.$0.space.$$"
|
||||||
|
|
||||||
@ -174,178 +174,132 @@ then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# do inodes/space checks
|
# 1) validate inodes (df -Pil)
|
||||||
if (( $(grep -c -i '^fs:' ${_CONFIG_FILE} 2>/dev/null) > 0 ))
|
if (( _DO_INODES > 0 ))
|
||||||
then
|
then
|
||||||
# 1) --- configured FS ---
|
(( ARG_DEBUG > 0 )) && debug "checking inodes..."
|
||||||
# a) --- inodes (df -Pil) ---
|
grep '^\/' ${_INODES_FILE} 2>/dev/null | awk '{print $6}' 2>/dev/null |\
|
||||||
if (( _DO_INODES > 0 ))
|
while read _FS
|
||||||
then
|
do
|
||||||
_LINE_COUNT=1
|
(( ARG_DEBUG > 0 )) && debug "parsing inodes data for filesystem: ${_FS}"
|
||||||
grep -i '^fs:' ${_CONFIG_FILE} 2>/dev/null |\
|
# add space to grep; must be non-greedy!
|
||||||
while IFS=':' read _ _CFG_FS _CFG_INODES_THRESHOLD _
|
_INODES_USAGE=$(grep -E -e " ${_FS}$" ${_INODES_FILE} 2>/dev/null | awk '{gsub(/%/,"",$5);print $5}' 2>/dev/null)
|
||||||
do
|
data_is_numeric "${_INODES_USAGE}"
|
||||||
# report on missing FS name or threshold
|
if (( $? > 0 ))
|
||||||
if [[ -z "${_CFG_FS}" ]] && [[ -z "${_CFG_INODES_THRESHOLD}" ]]
|
then
|
||||||
|
warn "discovered value for inodes usage is incorrect [${_FS}:${_INODES_USAGE}]"
|
||||||
|
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
# which threshold to use (general or custom?)
|
||||||
|
_CFG_FS_LINE=$(grep -E -e "^fs:${_FS}:" ${_CONFIG_FILE} 2>/dev/null)
|
||||||
|
if [[ -n "${_CFG_FS_LINE}" ]]
|
||||||
|
then
|
||||||
|
(( ARG_DEBUG > 0 )) && debug "found custom definition for ${_FS} in configuration file ${_CONFIG_FILE}"
|
||||||
|
_CFG_INODES_THRESHOLD=$(print "${_CFG_FS_LINE}" | cut -f3 -d':' 2>/dev/null)
|
||||||
|
# null value means general threshold
|
||||||
|
if [[ -z "${_CFG_INODES_THRESHOLD}" ]]
|
||||||
then
|
then
|
||||||
warn "missing filesystem name and/or threshold in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
|
(( ARG_DEBUG > 0 )) && debug "found empty inodes threshold for ${_FS}, using general threshold"
|
||||||
continue
|
_CFG_INODES_THRESHOLD=${_CFG_MAX_INODES_USAGE}
|
||||||
fi
|
fi
|
||||||
data_is_numeric "${_CFG_INODES_THRESHOLD}"
|
data_is_numeric "${_CFG_INODES_THRESHOLD}"
|
||||||
if (( $? > 0 ))
|
if (( $? > 0 ))
|
||||||
then
|
then
|
||||||
warn "parameter is not numeric in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
|
warn "inodes parameter is not numeric for ${_FS} in configuration file ${_CONFIG_FILE}"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
if (( _CFG_INODES_THRESHOLD == 0 || _CFG_INODES_THRESHOLD >= 100 ))
|
# zero value means disabled check
|
||||||
|
if (( _CFG_INODES_THRESHOLD == 0 ))
|
||||||
then
|
then
|
||||||
(( ARG_DEBUG > 0 )) && debug "found out-of-bounds inodes threshold for ${_CFG_FS}, using general threshold"
|
(( ARG_DEBUG > 0 )) && debug "found zero inodes threshold for ${_FS}, disabling check"
|
||||||
_CFG_INODES_THRESHOLD=${_CFG_MAX_INODES_USAGE}
|
|
||||||
fi
|
|
||||||
# add space to grep must be non-greedy!
|
|
||||||
_INODES_USAGE=$(grep -E -e " ${_CFG_FS}$" ${_INODES_FILE} 2>/dev/null | awk '{gsub(/%/,"",$5);print $5}' 2>/dev/null)
|
|
||||||
data_is_numeric "${_INODES_USAGE}"
|
|
||||||
if (( $? > 0 ))
|
|
||||||
then
|
|
||||||
warn "discovered value for inodes usage is incorrect [${_CFG_FS}:${_INODES_USAGE}]"
|
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
# check against the threshold
|
else
|
||||||
if (( _INODES_USAGE > _CFG_INODES_THRESHOLD ))
|
(( ARG_DEBUG > 0 )) && debug "no custom inodes threshold for ${_FS}, using general threshold"
|
||||||
|
_CFG_INODES_THRESHOLD=${_CFG_MAX_INODES_USAGE}
|
||||||
|
fi
|
||||||
|
# check against the treshold
|
||||||
|
if (( _INODES_USAGE > _CFG_INODES_THRESHOLD ))
|
||||||
|
then
|
||||||
|
_MSG="${_FS} exceedes its inode threshold (${_INODES_USAGE}%>${_CFG_INODES_THRESHOLD}%)"
|
||||||
|
_STC=1
|
||||||
|
else
|
||||||
|
_MSG="${_FS} does not exceede its inode threshold (${_INODES_USAGE}%<=${_CFG_INODES_THRESHOLD}%)"
|
||||||
|
_STC=0
|
||||||
|
fi
|
||||||
|
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
|
||||||
|
then
|
||||||
|
log_hc "$0" ${_STC} "${_MSG}" ${_INODES_USAGE} ${_CFG_MAX_INODES_USAGE}
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
# add df output to stdout log_hc
|
||||||
|
print "==== df -Pil ====" >>${HC_STDOUT_LOG}
|
||||||
|
cat ${_INODES_FILE} >>${HC_STDOUT_LOG}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 2) validate space (df -Pl)
|
||||||
|
if (( _DO_SPACE > 0 ))
|
||||||
|
then
|
||||||
|
(( ARG_DEBUG > 0 )) && debug "checking space..."
|
||||||
|
grep '^\/' ${_SPACE_FILE} 2>/dev/null | awk '{print $6}' 2>/dev/null |\
|
||||||
|
while read _FS
|
||||||
|
do
|
||||||
|
(( ARG_DEBUG > 0 )) && debug "parsing space data for filesystem: ${_FS}"
|
||||||
|
# add space to grep; must be non-greedy!
|
||||||
|
_SPACE_USAGE=$(grep -E -e " ${_FS}$" ${_SPACE_FILE} 2>/dev/null | awk '{gsub(/%/,"",$5);print $5}' 2>/dev/null)
|
||||||
|
data_is_numeric "${_SPACE_USAGE}"
|
||||||
|
if (( $? > 0 ))
|
||||||
|
then
|
||||||
|
warn "discovered value for space usage is incorrect [${_FS}:${_SPACE_USAGE}]"
|
||||||
|
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
# which threshold to use (general or custom?)
|
||||||
|
_CFG_FS_LINE=$(grep -E -e "^fs:${_FS}:" ${_CONFIG_FILE} 2>/dev/null)
|
||||||
|
if [[ -n "${_CFG_FS_LINE}" ]]
|
||||||
|
then
|
||||||
|
(( ARG_DEBUG > 0 )) && debug "found custom definition for ${_FS} in configuration file ${_CONFIG_FILE}"
|
||||||
|
_CFG_SPACE_THRESHOLD=$(print "${_CFG_FS_LINE}" | cut -f4 -d':' 2>/dev/null)
|
||||||
|
# null value means general threshold
|
||||||
|
if [[ -z "${_CFG_SPACE_THRESHOLD}" ]]
|
||||||
then
|
then
|
||||||
_MSG="${_CFG_FS} exceedes its inode threshold (${_INODES_USAGE}%>${_CFG_INODES_THRESHOLD}%)"
|
(( ARG_DEBUG > 0 )) && debug "found empty space threshold for ${_FS}, using general threshold"
|
||||||
_STC=1
|
_CFG_SPACE_THRESHOLD=${_CFG_MAX_SPACE_USAGE}
|
||||||
else
|
|
||||||
_MSG="${_CFG_FS} does not exceede its inode threshold (${_INODES_USAGE}%<=${_CFG_INODES_THRESHOLD}%)"
|
|
||||||
_STC=0
|
|
||||||
fi
|
|
||||||
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
|
|
||||||
then
|
|
||||||
log_hc "$0" ${_STC} "${_MSG}" ${_INODES_USAGE} ${_CFG_INODES_THRESHOLD}
|
|
||||||
fi
|
|
||||||
_LINE_COUNT=$(( _LINE_COUNT + 1 ))
|
|
||||||
done
|
|
||||||
# add df output to stdout log_hc
|
|
||||||
print "==== df -Pil ====" >>${HC_STDOUT_LOG}
|
|
||||||
cat ${_INODES_FILE} >>${HC_STDOUT_LOG}
|
|
||||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
|
|
||||||
fi
|
|
||||||
# b) --- space (df -Pl) ---
|
|
||||||
if (( _DO_SPACE > 0 ))
|
|
||||||
then
|
|
||||||
_LINE_COUNT=1
|
|
||||||
grep -i '^fs:' ${_CONFIG_FILE} 2>/dev/null |\
|
|
||||||
while IFS=':' read _ _CFG_FS _ _CFG_SPACE_THRESHOLD
|
|
||||||
do
|
|
||||||
# report on missing FS name or threshold
|
|
||||||
if [[ -z "${_CFG_FS}" ]] && [[ -z "${_CFG_SPACE_THRESHOLD}" ]]
|
|
||||||
then
|
|
||||||
warn "missing filesystem name and/or threshold in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
|
|
||||||
continue
|
|
||||||
fi
|
fi
|
||||||
data_is_numeric "${_CFG_SPACE_THRESHOLD}"
|
data_is_numeric "${_CFG_SPACE_THRESHOLD}"
|
||||||
if (( $? > 0 ))
|
if (( $? > 0 ))
|
||||||
then
|
then
|
||||||
warn "parameter is not numeric in configuration file ${_CONFIG_FILE} at data line ${_LINE_COUNT}"
|
warn "space parameter is not numeric for ${_FS} in configuration file ${_CONFIG_FILE}"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
if (( _CFG_SPACE_THRESHOLD == 0 || _CFG_SPACE_THRESHOLD >= 100 ))
|
# zero value means disabled check
|
||||||
|
if (( _CFG_SPACE_THRESHOLD == 0 ))
|
||||||
then
|
then
|
||||||
(( ARG_DEBUG > 0 )) && debug "found out-of-bounds space threshold for ${_CFG_FS}, using general threshold"
|
(( ARG_DEBUG > 0 )) && debug "found zero space threshold for ${_FS}, disabling check"
|
||||||
_CFG_SPACE_THRESHOLD=${_CFG_MAX_SPACE_USAGE}
|
|
||||||
fi
|
|
||||||
# add space to grep must be non-greedy!
|
|
||||||
_SPACE_USAGE=$(grep -E -e " ${_CFG_FS}$" ${_SPACE_FILE} 2>/dev/null | awk '{gsub(/%/,"",$5);print $5}' 2>/dev/null)
|
|
||||||
data_is_numeric "${_SPACE_USAGE}"
|
|
||||||
if (( $? > 0 ))
|
|
||||||
then
|
|
||||||
warn "discovered value for space usage is incorrect [${_CFG_FS}:${_SPACE_USAGE}]"
|
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
# check against the threshold
|
else
|
||||||
if (( _SPACE_USAGE > _CFG_SPACE_THRESHOLD ))
|
(( ARG_DEBUG > 0 )) && debug "no custom space threshold for ${_FS}, using general threshold"
|
||||||
then
|
_CFG_SPACE_THRESHOLD=${_CFG_MAX_SPACE_USAGE}
|
||||||
_MSG="${_CFG_FS} exceedes its space threshold (${_SPACE_USAGE}%>${_CFG_SPACE_THRESHOLD}%)"
|
|
||||||
_STC=1
|
|
||||||
else
|
|
||||||
_MSG="${_CFG_FS} does not exceede its space threshold (${_SPACE_USAGE}%<=${_CFG_SPACE_THRESHOLD}%)"
|
|
||||||
_STC=0
|
|
||||||
fi
|
|
||||||
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
|
|
||||||
then
|
|
||||||
log_hc "$0" ${_STC} "${_MSG}" ${_SPACE_USAGE} ${_CFG_SPACE_THRESHOLD}
|
|
||||||
fi
|
|
||||||
_LINE_COUNT=$(( _LINE_COUNT + 1 ))
|
|
||||||
done
|
|
||||||
# add df output to stdout log_hc
|
|
||||||
print "==== df -Pl ====" >>${HC_STDOUT_LOG}
|
|
||||||
cat ${_SPACE_FILE} >>${HC_STDOUT_LOG}
|
|
||||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
# 2) --- ALL FS ---
|
|
||||||
df -Pl 2>/dev/null | grep '^\/' 2>/dev/null | awk '{print $6}' 2>/dev/null |\
|
|
||||||
while read _FS
|
|
||||||
do
|
|
||||||
# a) --- inodes (df -Pil) ---
|
|
||||||
if (( _DO_INODES > 0 ))
|
|
||||||
then
|
|
||||||
# add space to grep must be non-greedy!
|
|
||||||
_INODES_USAGE=$(grep -E -e " ${_FS}$" ${_INODES_FILE} 2>/dev/null | awk '{gsub(/%/,"",$5);print $5}' 2>/dev/null)
|
|
||||||
data_is_numeric "${_INODES_USAGE}"
|
|
||||||
if (( $? > 0 ))
|
|
||||||
then
|
|
||||||
warn "discovered value for inodes usage is incorrect [${_FS}:${_INODES_USAGE}]"
|
|
||||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
# check against the threshold
|
|
||||||
if (( _INODES_USAGE > _CFG_MAX_INODES_USAGE ))
|
|
||||||
then
|
|
||||||
_MSG="${_FS} exceedes its inode threshold (${_INODES_USAGE}%>${_CFG_MAX_INODES_USAGE}%)"
|
|
||||||
_STC=1
|
|
||||||
else
|
|
||||||
_MSG="${_FS} does not exceede its inode threshold (${_INODES_USAGE}%<=${_CFG_MAX_INODES_USAGE}%)"
|
|
||||||
_STC=0
|
|
||||||
fi
|
|
||||||
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
|
|
||||||
then
|
|
||||||
log_hc "$0" ${_STC} "${_MSG}" ${_INODES_USAGE} ${_CFG_MAX_INODES_USAGE}
|
|
||||||
fi
|
|
||||||
# add df output to stdout log_hc
|
|
||||||
print "==== df -Pil ====" >>${HC_STDOUT_LOG}
|
|
||||||
cat ${_INODES_FILE} >>${HC_STDOUT_LOG}
|
|
||||||
fi
|
fi
|
||||||
# b) --- space (df -Pl) ---
|
# check against the treshold
|
||||||
if (( _DO_SPACE > 0 ))
|
if (( _SPACE_USAGE > _CFG_SPACE_THRESHOLD ))
|
||||||
then
|
then
|
||||||
# add space to grep must be non-greedy!
|
_MSG="${_FS} exceedes its space threshold (${_SPACE_USAGE}%>${_CFG_SPACE_THRESHOLD}%)"
|
||||||
_SPACE_USAGE=$(grep -E -e " ${_FS}$" ${_SPACE_FILE} 2>/dev/null | awk '{gsub(/%/,"",$5);print $5}' 2>/dev/null)
|
_STC=1
|
||||||
data_is_numeric "${_SPACE_USAGE}"
|
else
|
||||||
if (( $? > 0 ))
|
_MSG="${_FS} does not exceede its space threshold (${_SPACE_USAGE}%<=${_CFG_SPACE_THRESHOLD}%)"
|
||||||
then
|
_STC=0
|
||||||
warn "discovered value for space usage is incorrect [${_FS}:${_SPACE_USAGE}]"
|
fi
|
||||||
(( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && dump_logs
|
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
|
||||||
continue
|
then
|
||||||
fi
|
log_hc "$0" ${_STC} "${_MSG}" ${_SPACE_USAGE} ${_CFG_SPACE_THRESHOLD}
|
||||||
# check against the threshold
|
|
||||||
if (( _SPACE_USAGE > _CFG_MAX_SPACE_USAGE ))
|
|
||||||
then
|
|
||||||
_MSG="${_FS} exceedes its space threshold (${_SPACE_USAGE}%>${_CFG_MAX_SPACE_USAGE}%)"
|
|
||||||
_STC=1
|
|
||||||
else
|
|
||||||
_MSG="${_FS} does not exceede its space threshold (${_SPACE_USAGE}%<=${_CFG_MAX_SPACE_USAGE}%)"
|
|
||||||
_STC=0
|
|
||||||
fi
|
|
||||||
if (( _LOG_HEALTHY > 0 || _STC > 0 ))
|
|
||||||
then
|
|
||||||
log_hc "$0" ${_STC} "${_MSG}" ${_SPACE_USAGE} ${_CFG_MAX_SPACE_USAGE}
|
|
||||||
fi
|
|
||||||
# add df output to stdout log_hc
|
|
||||||
print "==== df -Pl ====" >>${HC_STDOUT_LOG}
|
|
||||||
cat ${_SPACE_FILE} >>${HC_STDOUT_LOG}
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
# add df output to stdout log_hc
|
||||||
|
print "==== df -Pl ====" >>${HC_STDOUT_LOG}
|
||||||
|
cat ${_SPACE_FILE} >>${HC_STDOUT_LOG}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# do cleanup
|
# do cleanup
|
||||||
|
Loading…
x
Reference in New Issue
Block a user