diff --git a/opt/hc/lib/core/include_data.sh b/opt/hc/lib/core/include_data.sh index dfa05f9..12c7fda 100755 --- a/opt/hc/lib/core/include_data.sh +++ b/opt/hc/lib/core/include_data.sh @@ -30,7 +30,7 @@ # RETURNS: 0 function version_include_data { -typeset _VERSION="2020-03-04" # YYYY-MM-DD +typeset _VERSION="2020-03-06" # YYYY-MM-DD print "INFO: $0: ${_VERSION#version_*}" @@ -237,7 +237,7 @@ return 0 # ----------------------------------------------------------------------------- # @(#) FUNCTION: data_magic_unquote() # DOES: magically unquotes a needle in a string (default needle is: %) -# EXPECTS: to be magically unquoted [string]; $2=needle [string] +# EXPECTS: $1=to be magically unquoted [string]; $2=needle [string] # OUTPUTS: magically unquoted [string] # RETURNS: n/a # REQUIRES: n/a @@ -616,7 +616,8 @@ return 0 # ----------------------------------------------------------------------------- # @(#) FUNCTION: data_expand_numerical_range() # DOES: expand numerical range (X-Y) to comma-separated list of numbers -# EXPECTS: [string] +# EXPECTS: $1=numerical range [string] +# $2=flag for leading zeroes <10 [0=do not add (default),1=add] # OUTPUTS: [string] # RETURNS: 0=no error occurred; <>0=some error occurred # REQUIRES: n/a @@ -624,6 +625,7 @@ function data_expand_numerical_range { (( ARG_DEBUG > 0 && ARG_DEBUG_LEVEL > 0 )) && set "${DEBUG_OPTS}" typeset _NUM_LIST="" +typeset _HAS_LEAD_ZERO=${2:0} case "${1}" in *-*) @@ -641,19 +643,21 @@ case "${1}" in return 1 fi # expand list - _NUM_LIST=$(print "${1}"| awk -F '-' ' + _NUM_LIST=$(print "${1}"| awk -F '-' -v has_lead_zero=${_HAS_LEAD_ZERO} ' BEGIN { count = 0; } { - while ($1 + count < $2) { + while ($1 + count <= $2) { + # add leading zero to sprintf when < 10 + if (has_lead_zero > 0 && $1 + count < 10) { lead_zero = "0" } else { lead_zero = "" } if (length (NUM_LIST) == 0) { - NUM_LIST = sprintf ("%s", $1 + count); + NUM_LIST = sprintf ("%" lead_zero "2d", $1 + count); } else { - NUM_LIST = sprintf ("%s,%s", NUM_LIST, $1 + count); - } + NUM_LIST = sprintf ("%s,%" lead_zero "2d", NUM_LIST, $1 + count); } count++; } } - END { print NUM_LIST; }') + # remove space from end result and print + END { gsub(/[[:space:]]/, "", NUM_LIST); print NUM_LIST; }') if [[ -z "${_NUM_LIST}" ]] then (( ARG_DEBUG > 0 )) && debug "range conversion returned empty list" diff --git a/opt/hc/lib/platform/exadata/check_exadata_zfs_share_replication.sh b/opt/hc/lib/platform/exadata/check_exadata_zfs_share_replication.sh index 321fe20..7875c7e 100755 --- a/opt/hc/lib/platform/exadata/check_exadata_zfs_share_replication.sh +++ b/opt/hc/lib/platform/exadata/check_exadata_zfs_share_replication.sh @@ -31,7 +31,8 @@ # @(#) 2019-05-14: small fixes [Patrick Van der Veken] # @(#) 2020-01-27: addition of day check option + # @(#) newline config value check [Patrick Van der Veken] -# @(#) 2020-03-05: addition of hour check option +# @(#) 2020-03-05: addition of hour check option + fix +# @(#) 2020-03-06: fix for expanding numerical range # ----------------------------------------------------------------------------- # DO NOT CHANGE THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING! #****************************************************************************** @@ -41,7 +42,7 @@ function check_exadata_zfs_share_replication { # ------------------------- CONFIGURATION starts here ------------------------- typeset _CONFIG_FILE="${CONFIG_DIR}/$0.conf" -typeset _VERSION="2020-03-04" # YYYY-MM-DD +typeset _VERSION="2020-03-06" # YYYY-MM-DD typeset _SUPPORTED_PLATFORMS="Linux" # uname -s match # replication query script -- DO NOT CHANGE -- # prj1/share1:true:idle:success:111 @@ -88,7 +89,7 @@ typeset _SSH_BIN="" typeset _SSH_OUTPUT="" typeset _ZFS_DATA="" typeset _WEEKDAY=$(data_lc "$(date '+%a' 2>/dev/null)") # Sun -typeset _HOUR=$(data_strip_space "$(date '+%k' 2>/dev/null)") # 7,23 etc +typeset _HOUR=$(data_strip_space "$(date '+%H' 2>/dev/null)") # 7,23 etc # handle arguments (originally comma-separated) for _ARG in ${_ARGS} @@ -289,7 +290,8 @@ do then _REPLICATION_HOURS="${_HOUR}" else - _REPLICATION_HOURS=$(data_expand_numerical_range "${_CFG_REPLICATION_HOURS}") + # expand range with leading zeroes + _REPLICATION_HOURS=$(data_expand_numerical_range "${_CFG_REPLICATION_HOURS}" 1) fi # perform checks @@ -351,7 +353,7 @@ do log_hc "$0" ${_STC} "${_MSG}" "${_REPLICATION_LAG}" "${_CFG_REPLICATION_LAG}" fi else - warn "check of ${_ZFS_HOST}:${_REPLICATION_NAME} is not configured for this hour/these hours: ${_REPLICATION_HOURS}" + warn "check of ${_ZFS_HOST}:${_REPLICATION_NAME} is only configured for this/these hour(s): ${_REPLICATION_HOURS}" fi else warn "check of ${_ZFS_HOST}:${_REPLICATION_NAME} is not configured for today"