summaryrefslogtreecommitdiff
path: root/zshfunc/reinit-debian-samhain-one
blob: f0f28c0a15dfd7e62e2baf1ad2aec6ed16ff3ccd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
## vim:ft=zsh:foldmethod=marker

local host

host=$1
if [ "$host" = "${host%%.debian.org}" ]; then
	host="$host.debian.org"
fi
echo $host
preexec $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
			grep -q OK /var/cache/dsa/nagios/samhain || sudo dsa-update-samhain-status
			echo done.
		fi;
	fi
';