#!/bin/bash # Ustaw wartości graniczne WARNING_THRESHOLD=80 CRITICAL_THRESHOLD=90 # Zmienna do przechowywania komunikatu końcowego final_message="" highest_status_code=0 # Pobierz dane dla wszystkich systemów plików zfs readarray -t filesystem_data < <(zfs list -t filesystem -o name,avail,used,usedsnap,usedds -Hp) # Sprawdzanie użycia snapshotów dla każdego systemu plików for fs in "${filesystem_data[@]}"; do # Czytanie wartości z linii danych systemu plików read -r name avail used usedsnap usedds <<<"$fs" # Konwersja do procentów, jeśli usedsnap jest większe niż 0 if [[ $usedsnap != "0B" ]]; then # Usuń ostatni znak 'B' i konwertuj na bajty usedsnap_bytes=$(echo $usedsnap | sed 's/B//') used_bytes=$(echo $used | sed 's/B//') # Oblicz procent używanych snapshotów w stosunku do całkowitego użycia usedsnap_percent=$(echo "scale=2; $usedsnap_bytes / $used_bytes * 100" | bc) # Sprawdzenie wartości progowych if (( $(echo "$usedsnap_percent > $CRITICAL_THRESHOLD" | bc -l) )); then final_message+="CRITICAL: $name is at $usedsnap_percent% used of snapshot space. " current_status_code=2 elif (( $(echo "$usedsnap_percent > $WARNING_THRESHOLD" | bc -l) )); then final_message+="WARNING: $name is at $usedsnap_percent% used of snapshot space. " current_status_code=1 else final_message+="OK: $name is at $usedsnap_percent% used of snapshot space. " current_status_code=0 fi # Update highest status code if [[ $current_status_code -gt $highest_status_code ]]; then highest_status_code=$current_status_code fi else final_message+="OK: $name has no snapshots using space. " fi done # Wyświetl komunikat końcowy echo "$final_message" exit $highest_status_code