2 # nagios-submit-host -- Submit passive host check result
3 # 2009-12-11, alex@barton.de
9 echo "$NAME [-c] <host> <code> [<text>]"; echo
10 echo " -c create new host, if necessary"
11 echo " <host> Nagios host ID"
12 echo " <code> Status code: 0=OK, 1=Warning, 2=Error, 3=Unknown"
13 echo " <text> Optional status message"
22 [ -r "/etc/nagios3/system.cfg" ] || Error "Can't read /etc/nagios3/system.cfg!"
23 . /etc/nagios3/system.cfg
25 # Validate command line arguments
26 if [ "$1" = "-c" ]; then
29 [ $# -ge 2 -a $# -le 3 ] || Usage
30 [ "$2" = 0 -o "$2" = "1" -o "$2" = "2" -o "$2" = "3" ] || Usage
32 # Validate configuration
33 [ -w "$CMDFILE" ] || Error "Can't write to \"$CMDFILE\"!"
40 grep -E "^[[:space:]]+host_name[[:space:]]+${host}\$" "$CFGDIR"/*.cfg >/dev/null 2>&1
42 # Host not configured!
43 [ -n "$CREATE" ] || Error "Host \"$host\" not configured!?"
44 echo "Creating new Nagios host configuration for \"$host\" ..."
45 cfg="$CFGDIR/_host_$host.cfg"
48 use ${HOST_TEMPLATE_PASSIVE}
52 chmod "$CFG_MODE" "$cfg" || Error "chmod(1) failed!"
53 echo "Reloading Nagios configuration ..."
54 "$RCFILE" reload || Error "Failed to reload Nagios configuration!"
58 cmd="[$time_t] PROCESS_HOST_CHECK_RESULT;$host;$code;$text"
59 echo "$cmd" >>"$CMDFILE"