From 3b92f482402977b8c49ad9f0dae59d39eb245d2c Mon Sep 17 00:00:00 2001 From: tfheen Date: Tue, 4 Oct 2011 11:15:13 +0000 Subject: [PATCH] Add samhain functions git-svn-id: file:///svn/tfheen/trunk/dotfiles@1485 8da78d58-1cd3-0310-bee5-d77bd1b3e8bf --- zshfunc/_reinit-samhain-one | 30 ++++++++++++++++++++++++++++++ zshfunc/reinit-samhain-one | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 zshfunc/_reinit-samhain-one create mode 100644 zshfunc/reinit-samhain-one diff --git a/zshfunc/_reinit-samhain-one b/zshfunc/_reinit-samhain-one new file mode 100644 index 0000000..667a698 --- /dev/null +++ b/zshfunc/_reinit-samhain-one @@ -0,0 +1,30 @@ +#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 "$@" diff --git a/zshfunc/reinit-samhain-one b/zshfunc/reinit-samhain-one new file mode 100644 index 0000000..2ba39b1 --- /dev/null +++ b/zshfunc/reinit-samhain-one @@ -0,0 +1,37 @@ +# -*- 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 +'; -- 2.39.5