Files
Mateusz Suski ca5a876d03
lint / shell-yaml-ansible (push) Failing after 21s
Improve infra-run portfolio credibility
2026-05-08 21:18:22 +00:00

28 lines
1001 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
threshold="${1:-80}"
if [[ ! "$threshold" =~ ^[0-9]+$ ]] || (( threshold < 1 || threshold > 100 )); then
printf 'CRITICAL: invalid threshold "%s"; provide an integer from 1 to 100\n' "$threshold" >&2
exit 2
fi
status=0
warning_threshold=$(( threshold > 5 ? threshold - 5 : threshold ))
while read -r filesystem _size _used avail use_percent mountpoint; do
usage="${use_percent%\%}"
if (( usage >= threshold )); then
printf 'CRITICAL: %s mounted on %s is %s used; threshold is %s%% (%s free)\n' "$filesystem" "$mountpoint" "$use_percent" "$threshold" "$avail"
status=1
elif (( usage >= warning_threshold )); then
printf 'WARNING: %s mounted on %s is %s used; threshold is %s%%\n' "$filesystem" "$mountpoint" "$use_percent" "$threshold"
else
printf 'OK: %s mounted on %s is %s used\n' "$filesystem" "$mountpoint" "$use_percent"
fi
done < <(df -P -x tmpfs -x devtmpfs | awk 'NR > 1 {print $1, $2, $3, $4, $5, $6}')
exit "$status"