1
0
Fork 0

nagios/btrfs-quota: add extra infos to perfdata

This commit is contained in:
Chl 2023-10-01 03:07:10 +02:00
parent d2ee68217e
commit b9184ba489

View file

@ -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:
# - "free" space value
# - value
# - quota (aka. maximum space possible)
# - threshold (in percent with a '%' suffix, or plain unit)
#
check_freespace_is_above_threshold() {
check_above_threshold() {
local VALUE="$1"
local MAXVALUE="$2"
local THRESHOLD="$3"
if get_percent "$THRESHOLD" >/dev/null; then
VALUE="$(( $VALUE * 100 / $MAXVALUE ))"
THRESHOLD="$( get_percent "$THRESHOLD" )"
fi
if [ "$VALUE" -le "$THRESHOLD" ]; then
if [ "$VALUE" -gt "$( get_absolute_threshold "$MAXVALUE" "$THRESHOLD" )" ]; then
return 1
fi
return 0
@ -178,22 +192,24 @@ while getopts hw:c:V: f; do
# our precious vars even with prosix-strict dash)
while read QGROUPID RFER EXCL MAXRFER MAXEXCL SUBVOLUMEPATH; do
LOOP_OUTPUT_STATUS=$STATE_OK
PERFDATA_RFER="$RFER""B"
PERFDATA_EXCL="$EXCL""B"
if [ "$MAXRFER" != "none" ]; then
FREERFER="$(( $MAXRFER - $RFER ))"
if ! check_freespace_is_above_threshold "$FREERFER" "$MAXRFER" "$RANGE_CRITICAL"; then
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_above_threshold "$RFER" "$MAXRFER" "$RANGE_CRITICAL"; then
OUTPUT_EXIT_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
LOOP_OUTPUT_STATUS=$STATE_WARNING
fi
fi
if [ "$MAXEXCL" != "none" ]; then
FREEEXCL="$(( $MAXEXCL - $EXCL ))"
if ! check_freespace_is_above_threshold "$FREEEXCL" "$MAXEXCL" "$RANGE_CRITICAL"; then
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_above_threshold "$EXCL" "$MAXEXCL" "$RANGE_CRITICAL"; then
OUTPUT_EXIT_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
[ "$LOOP_OUTPUT_STATUS" = "$STATE_OK" ] && LOOP_OUTPUT_STATUS=$STATE_WARNING
fi
@ -212,7 +228,9 @@ while getopts hw:c:V: f; do
OUTPUT_DETAIL_CRITICAL="$OUTPUT_DETAIL_CRITICAL $TMP" ;;
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
$( btrfs qgroup show -re --raw "$VOLUME" | tail -n +3 )
EOF