nagios/btrfs-quota: add extra infos to perfdata
This commit is contained in:
parent
d2ee68217e
commit
b9184ba489
1 changed files with 34 additions and 16 deletions
|
@ -76,24 +76,38 @@ get_percent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Returns 0 if freespace is above threshold, 1 if not
|
# Uniformize thresholds:
|
||||||
|
# if "20%" then calculate
|
||||||
|
# else leave as is
|
||||||
|
# args:
|
||||||
|
# 1: MAXVALUE
|
||||||
|
# 2: THRESHOLD
|
||||||
|
#
|
||||||
|
get_absolute_threshold() {
|
||||||
|
local MAXVALUE="$1"
|
||||||
|
local THRESHOLD="$2"
|
||||||
|
|
||||||
|
if get_percent "$THRESHOLD" >/dev/null; then
|
||||||
|
echo "$(( $MAXVALUE * ( 100 - $( get_percent "$THRESHOLD" ) ) / 100 ))"
|
||||||
|
else
|
||||||
|
echo "$(( $MAXVALUE - $THRESHOLD ))"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Returns 1 if value is above threshold, 0 if not
|
||||||
#
|
#
|
||||||
# args:
|
# args:
|
||||||
# - "free" space value
|
# - value
|
||||||
# - quota (aka. maximum space possible)
|
# - quota (aka. maximum space possible)
|
||||||
# - threshold (in percent with a '%' suffix, or plain unit)
|
# - threshold (in percent with a '%' suffix, or plain unit)
|
||||||
#
|
#
|
||||||
check_freespace_is_above_threshold() {
|
check_above_threshold() {
|
||||||
local VALUE="$1"
|
local VALUE="$1"
|
||||||
local MAXVALUE="$2"
|
local MAXVALUE="$2"
|
||||||
local THRESHOLD="$3"
|
local THRESHOLD="$3"
|
||||||
|
|
||||||
if get_percent "$THRESHOLD" >/dev/null; then
|
if [ "$VALUE" -gt "$( get_absolute_threshold "$MAXVALUE" "$THRESHOLD" )" ]; then
|
||||||
VALUE="$(( $VALUE * 100 / $MAXVALUE ))"
|
|
||||||
THRESHOLD="$( get_percent "$THRESHOLD" )"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$VALUE" -le "$THRESHOLD" ]; then
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
|
@ -178,22 +192,24 @@ while getopts hw:c:V: f; do
|
||||||
# our precious vars even with prosix-strict dash)
|
# our precious vars even with prosix-strict dash)
|
||||||
while read QGROUPID RFER EXCL MAXRFER MAXEXCL SUBVOLUMEPATH; do
|
while read QGROUPID RFER EXCL MAXRFER MAXEXCL SUBVOLUMEPATH; do
|
||||||
LOOP_OUTPUT_STATUS=$STATE_OK
|
LOOP_OUTPUT_STATUS=$STATE_OK
|
||||||
|
PERFDATA_RFER="$RFER""B"
|
||||||
|
PERFDATA_EXCL="$EXCL""B"
|
||||||
if [ "$MAXRFER" != "none" ]; then
|
if [ "$MAXRFER" != "none" ]; then
|
||||||
FREERFER="$(( $MAXRFER - $RFER ))"
|
PERFDATA_RFER="$( printf "%s;%d;%d;0;%d" "$PERFDATA_RFER" "$( get_absolute_threshold "$MAXRFER" "$RANGE_WARNING" )" "$( get_absolute_threshold "$MAXRFER" "$RANGE_CRITICAL" )" "$MAXRFER" )"
|
||||||
if ! check_freespace_is_above_threshold "$FREERFER" "$MAXRFER" "$RANGE_CRITICAL"; then
|
if ! check_above_threshold "$RFER" "$MAXRFER" "$RANGE_CRITICAL"; then
|
||||||
OUTPUT_EXIT_STATUS=$STATE_CRITICAL
|
OUTPUT_EXIT_STATUS=$STATE_CRITICAL
|
||||||
LOOP_OUTPUT_STATUS=$STATE_CRITICAL
|
LOOP_OUTPUT_STATUS=$STATE_CRITICAL
|
||||||
elif ! check_freespace_is_above_threshold "$FREERFER" "$MAXRFER" "$RANGE_WARNING"; then
|
elif ! check_above_threshold "$RFER" "$MAXRFER" "$RANGE_WARNING"; then
|
||||||
[ "$OUTPUT_EXIT_STATUS" = "$STATE_OK" ] && OUTPUT_EXIT_STATUS=$STATE_WARNING
|
[ "$OUTPUT_EXIT_STATUS" = "$STATE_OK" ] && OUTPUT_EXIT_STATUS=$STATE_WARNING
|
||||||
LOOP_OUTPUT_STATUS=$STATE_WARNING
|
LOOP_OUTPUT_STATUS=$STATE_WARNING
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ "$MAXEXCL" != "none" ]; then
|
if [ "$MAXEXCL" != "none" ]; then
|
||||||
FREEEXCL="$(( $MAXEXCL - $EXCL ))"
|
PERFDATA_RFER="$( printf "%s;%d;%d;0;%d" "$PERFDATA_EXCL" "$( get_absolute_threshold "$MAXEXCL" "$RANGE_WARNING" )" "$( get_absolute_threshold "$MAXEXCL" "$RANGE_CRITICAL" )" "$MAXEXCL" )"
|
||||||
if ! check_freespace_is_above_threshold "$FREEEXCL" "$MAXEXCL" "$RANGE_CRITICAL"; then
|
if ! check_above_threshold "$EXCL" "$MAXEXCL" "$RANGE_CRITICAL"; then
|
||||||
OUTPUT_EXIT_STATUS=$STATE_CRITICAL
|
OUTPUT_EXIT_STATUS=$STATE_CRITICAL
|
||||||
LOOP_OUTPUT_STATUS=$STATE_CRITICAL
|
LOOP_OUTPUT_STATUS=$STATE_CRITICAL
|
||||||
elif ! check_freespace_is_above_threshold "$FREEEXCL" "$MAXEXCL" "$RANGE_WARNING"; then
|
elif ! check_above_threshold "$EXCL" "$MAXEXCL" "$RANGE_WARNING"; then
|
||||||
[ "$OUTPUT_EXIT_STATUS" = "$STATE_OK" ] && OUTPUT_EXIT_STATUS=$STATE_WARNING
|
[ "$OUTPUT_EXIT_STATUS" = "$STATE_OK" ] && OUTPUT_EXIT_STATUS=$STATE_WARNING
|
||||||
[ "$LOOP_OUTPUT_STATUS" = "$STATE_OK" ] && LOOP_OUTPUT_STATUS=$STATE_WARNING
|
[ "$LOOP_OUTPUT_STATUS" = "$STATE_OK" ] && LOOP_OUTPUT_STATUS=$STATE_WARNING
|
||||||
fi
|
fi
|
||||||
|
@ -212,7 +228,9 @@ while getopts hw:c:V: f; do
|
||||||
OUTPUT_DETAIL_CRITICAL="$OUTPUT_DETAIL_CRITICAL $TMP" ;;
|
OUTPUT_DETAIL_CRITICAL="$OUTPUT_DETAIL_CRITICAL $TMP" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
OUTPUT_PERFDATA="$( printf "%s\n%s\n%s" "$OUTPUT_PERFDATA" "$VOLUME:$QGROUPID:$SUBVOLUMEPATH:rfer=$RFER" "$VOLUME:$QGROUPID:$SUBVOLUMEPATH:excl=$EXCL" )"
|
# We had some errors with pnp4nagios with labels containing '<>' like '<toplevel>' so
|
||||||
|
# we slaped a tr '<>' '_' at the end...
|
||||||
|
OUTPUT_PERFDATA="$( printf "%s\n%s\n%s" "$OUTPUT_PERFDATA" "$VOLUME:$QGROUPID:$SUBVOLUMEPATH:rfer=$PERFDATA_RFER" "$VOLUME:$QGROUPID:$SUBVOLUMEPATH:excl=$PERFDATA_EXCL" | tr '<>' '_')"
|
||||||
done <<EOF
|
done <<EOF
|
||||||
$( btrfs qgroup show -re --raw "$VOLUME" | tail -n +3 )
|
$( btrfs qgroup show -re --raw "$VOLUME" | tail -n +3 )
|
||||||
EOF
|
EOF
|
||||||
|
|
Loading…
Reference in a new issue