#!/bin/sh
# yambar `zfs` segment feed: ZFS pool health summary from sysop.
#
# Emits one yambar record on each poll:
#   state|string|ok           (all pools ONLINE)
#   state|string|degraded     (any pool non-ONLINE)
#
# Routes operator into `sysop storage` when state != ok.

set -eu

while :; do
    summary="$(sysop storage --summary 2>/dev/null || echo 'degraded')"
    case "$summary" in
        ok) printf 'state|string|ok\n\n' ;;
        *)  printf 'state|string|degraded\n\n' ;;
    esac
    sleep 10
done
