--- /dev/null
+#compdef reinit-samhain-one
+
+_reinit-samhain-one () {
+ local curcontext="$curcontext" state line ret=1 expl
+ typeset -A opt_args
+
+ _arguments -C -s \
+ '*:hosts:->hosts' && ret=0
+
+ if [[ -n "$state" ]]; then
+ if compset -P '*@'; then
+ _wanted hosts expl host _samhain_all_hosts -S: && ret=0
+ else
+ _alternative \
+ 'hosts:: _samhain_all_hosts -S:' \
+ 'users:: _samhain_users -qS@' && ret=0
+ fi
+ fi
+ return ret
+}
+
+_samhain_users () {
+ _tags users && _combination -s '[@]' my-accounts users-hosts users "$@"
+}
+
+_samhain_all_hosts () {
+ _tags hosts && _combination -s '[@]' my-accounts users-hosts hosts "$@"
+}
+
+_reinit-samhain-one "$@"
--- /dev/null
+# -*- sh -*-
+## vim:ft=zsh:foldmethod=marker
+
+local host
+
+host=$1
+#if [ "$host" = "${host%%.debian.org}" ]; then
+# host="$host.debian.org"
+#fi
+echo $host
+ssh $host -t '
+ check() {
+ sudo /usr/sbin/samhain -t check -i -p err -s none -l none -m none
+ };
+ if [ -x /usr/sbin/samhain ]; then
+ t="`tempfile`";
+ trap "rm -f $t" 0 1 2 5 15;
+ check > "$t" 2>&1;
+ if [ "`grep "^CRIT" "$t" | wc -l`" != 0 ]; then
+ echo "samhain db errors found:";
+ sed -e "s/.*path=<\([^>]*\)>, .*/\1/" "$t";
+ echo;
+ echo "Enter 'y' to continue upgrade and update samhaindb for `hostname`";
+ read ans;
+ [ "$ans" = "y" ] || exit;
+
+ echo Updating samhain db...
+ sudo samhain --foreground -t update
+
+ if [ -f /var/cache/dsa/nagios/samhain ]; then
+ grep -q OK /var/cache/dsa/nagios/samhain || sudo dsa-update-samhain-status
+ fi
+ [ -x /usr/local/lib/nagios/nsca_samhain ] && /usr/local/lib/nagios/nsca_samhain
+ echo done.
+ fi;
+ fi
+';