#!/bin/bash STALE_DIR="${HOME}/var/stale/" get_names() { /usr/sbin/bcfg2-reports "$@" --fields=name | sed 's/ *$//' } get_stale() { get_names --stale | sed 's/ *$//' } get_all() { get_names -a | sed 's/ *$//' } get_bad() { get_names -d | sed 's/ *$//' } get_clean() { get_names -c | sed 's/ *$//' } get_count() { count=$(/usr/sbin/bcfg2-reports "$@" | wc -l) if [ "$count" = "0" ]; then echo 0 else echo $((count - 1)) fi } get_nagios() { if [ -z "$1" ]; then clean=$(get_clean | wc -l) bad=$(get_bad | wc -l) stale=$(get_stale | wc -l) status="OK" exit=0 if [ "$bad" != "0" -o "$stale" != "0" ]; then status="CRITICAL" exit=2 fi echo "$status | clean=$clean; bad=$bad; stale=$stale;" exit $exit else if ! get_names -a | grep -q "^$1$"; then echo "CRITICAL $1 not known to bcfg2" exit 2 fi if get_names --stale | grep -q "^$1$"; then echo "CRITICAL $1 is stale" exit 2 fi bad=$(get_count -b "$1") if [ "$bad" != "0" ]; then echo "CRITICAL $bad bad entries" exit 2 fi extra=$(get_count -e "$1") total=$(bcfg2-reports -t "$1" | sed "s/good: [0-9]*)/extra: $extra)/") echo "OK $total" fi } get_stale_once() { get_stale | while read host; do STALE_FILE="${STALE_DIR}/${host}" test -f "${STALE_FILE}" || ( touch "${STALE_FILE}" echo $host ) done comm -13 <(get_stale | sort) <(get_all | sort) | while read host; do STALE_FILE="${STALE_DIR}/${host}" test -f "${STALE_FILE}" && rm -f "${STALE_FILE}" done } cron() { stale=$(get_stale_once) if [ -n "$stale" ]; then sendmail -t <