#!/bin/sh # nagios-submit-host -- Submit passive host check result # 2009-12-11, alex@barton.de NAME=`basename "$0"` CREATE= Usage() { echo "$NAME [-c] []"; echo echo " -c create new host, if necessary" echo " Nagios host ID" echo " Status code: 0=OK, 1=Warning, 2=Error, 3=Unknown" echo " Optional status message" echo; exit 1 } Error() { echo "$NAME: $*" exit 1 } [ -r "/etc/nagios3/system.cfg" ] || Error "Can't read /etc/nagios3/system.cfg!" . /etc/nagios3/system.cfg # Validate command line arguments if [ "$1" = "-c" ]; then CREATE=1; shift fi [ $# -ge 2 -a $# -le 3 ] || Usage [ "$2" = 0 -o "$2" = "1" -o "$2" = "2" -o "$2" = "3" ] || Usage # Validate configuration [ -w "$CMDFILE" ] || Error "Can't write to \"$CMDFILE\"!" time_t=`date +%s` host="$1" code="$2" text="${3:-}" grep -E "^[[:space:]]+host_name[[:space:]]+${host}\$" "$CFGDIR"/*.cfg >/dev/null 2>&1 if [ $? -ne 0 ]; then # Host not configured! [ -n "$CREATE" ] || Error "Host \"$host\" not configured!?" echo "Creating new Nagios host configuration for \"$host\" ..." cfg="$CFGDIR/_host_$host.cfg" cat >"$cfg" <>"$CMDFILE"