3 # NagCollect -- Nagios Data Collector for Passive Checks
4 # Copyright (c)2009-2010 Alexander Barton, alex@barton.de
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 # Please read the file COPYING, README and AUTHORS for more information.
12 # nagios-submit-host -- Submit passive host check result
19 echo "$NAME [-c] <host> <code> [<text>]"; echo
20 echo " -c create new host, if necessary"
21 echo " <host> Nagios host ID"
22 echo " <code> Status code: 0=OK, 1=Warning, 2=Error, 3=Unknown"
23 echo " <text> Optional status message"
32 [ -r "/etc/nagios3/system.cfg" ] || Error "Can't read /etc/nagios3/system.cfg!"
33 . /etc/nagios3/system.cfg
35 # Validate command line arguments
36 if [ "$1" = "-c" ]; then
39 [ $# -ge 2 -a $# -le 3 ] || Usage
40 [ "$2" = 0 -o "$2" = "1" -o "$2" = "2" -o "$2" = "3" ] || Usage
42 # Validate configuration
43 [ -w "$CMDFILE" ] || Error "Can't write to \"$CMDFILE\"!"
50 grep -E "^[[:space:]]+host_name[[:space:]]+${host}\$" "$CFGDIR"/*.cfg >/dev/null 2>&1
52 # Host not configured!
53 [ -n "$CREATE" ] || Error "Host \"$host\" not configured!?"
54 echo "Creating new Nagios host configuration for \"$host\" ..."
55 cfg="$CFGDIR/_host_$host.cfg"
58 use ${HOST_TEMPLATE_PASSIVE}
62 chmod "$CFG_MODE" "$cfg" || Error "chmod(1) failed!"
63 echo "Reloading Nagios configuration ..."
64 "$RCFILE" reload || Error "Failed to reload Nagios configuration!"
68 cmd="[$time_t] PROCESS_HOST_CHECK_RESULT;$host;$code;$text"
69 echo "$cmd" >>"$CMDFILE"