Add initial Linux operations Bash toolkit with network diagnostics
This commit is contained in:
Executable
+29
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env bash
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o 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"
|
||||
Reference in New Issue
Block a user