53 lines
2.3 KiB
Text
53 lines
2.3 KiB
Text
|
|
# Five conditions, all of which have to hold. Ported from the check that
|
||
|
|
# infra/nodito/32_zfs_pool_setup_playbook.yml deployed, which was correct -
|
||
|
|
# only its reporting was tied to Uptime Kuma.
|
||
|
|
local pool="{{ healthcheck_zfs_pool }}"
|
||
|
|
local json issues=""
|
||
|
|
|
||
|
|
json=$(zpool status -j "$pool" 2>&1) || { MESSAGE="zpool status failed: ${json}"; return 1; }
|
||
|
|
|
||
|
|
# 1. pool state
|
||
|
|
local state
|
||
|
|
state=$(echo "$json" | jq -r --arg p "$pool" '.pools[$p].state')
|
||
|
|
[ "$state" = "ONLINE" ] || issues="${issues}${issues:+; }pool ${state}"
|
||
|
|
|
||
|
|
# 2. every vdev and device ONLINE
|
||
|
|
local bad
|
||
|
|
bad=$(echo "$json" | jq -r --arg p "$pool" '
|
||
|
|
.pools[$p].vdevs[] | .. | objects
|
||
|
|
| select(.state? and .state != "ONLINE")
|
||
|
|
| "\(.name // "unknown"):\(.state)"' 2>/dev/null | paste -sd, -)
|
||
|
|
[ -z "$bad" ] || issues="${issues}${issues:+; }devices ${bad}"
|
||
|
|
|
||
|
|
# 3. resilver in progress
|
||
|
|
local fn st
|
||
|
|
fn=$(echo "$json" | jq -r --arg p "$pool" '.pools[$p].scan_stats.function // "NONE"')
|
||
|
|
st=$(echo "$json" | jq -r --arg p "$pool" '.pools[$p].scan_stats.state // "NONE"')
|
||
|
|
if [ "$fn" = "RESILVER" ] && [ "$st" = "SCANNING" ]; then
|
||
|
|
issues="${issues}${issues:+; }resilvering"
|
||
|
|
fi
|
||
|
|
|
||
|
|
# 4. read/write/checksum errors. ZFS reports these as strings.
|
||
|
|
local errs
|
||
|
|
errs=$(echo "$json" | jq -r --arg p "$pool" '
|
||
|
|
.pools[$p].vdevs[] | .. | objects
|
||
|
|
| select(.name? and ((.read_errors // "0" | tonumber) > 0
|
||
|
|
or (.write_errors // "0" | tonumber) > 0
|
||
|
|
or (.checksum_errors // "0" | tonumber) > 0))
|
||
|
|
| "\(.name) r=\(.read_errors) w=\(.write_errors) c=\(.checksum_errors)"' 2>/dev/null | paste -sd, -)
|
||
|
|
[ -z "$errs" ] || issues="${issues}${issues:+; }errors ${errs}"
|
||
|
|
|
||
|
|
# 5. errors from the last scrub
|
||
|
|
local scan_err
|
||
|
|
scan_err=$(echo "$json" | jq -r --arg p "$pool" '.pools[$p].scan_stats.errors // "0"')
|
||
|
|
if [ -n "$scan_err" ] && [ "$scan_err" != "0" ] && [ "$scan_err" != "null" ]; then
|
||
|
|
issues="${issues}${issues:+; }scan errors ${scan_err}"
|
||
|
|
fi
|
||
|
|
|
||
|
|
if [ -n "$issues" ]; then MESSAGE="$issues"; return 1; fi
|
||
|
|
|
||
|
|
local scrub
|
||
|
|
scrub=$(echo "$json" | jq -r --arg p "$pool" '.pools[$p].scan_stats.start_time // "never"')
|
||
|
|
MESSAGE="${pool} ONLINE, last scrub ${scrub}"
|
||
|
|
return 0
|