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-service -- Submit passive service check result
19 echo "$NAME [-c] <host> <service> <code> [<text>]"; echo
20 echo " -c create new service, if necessary"
21 echo " <host> Nagios host ID"
22 echo " <service> Nagios service ID"
23 echo " <code> Status code: 0=OK, 1=Warning, 2=Error, 3=Unknown"
24 echo " <text> Optional status message"
33 [ -r "/etc/nagios3/system.cfg" ] || Error "Can't read /etc/nagios3/system.cfg!"
34 . /etc/nagios3/system.cfg
36 # Validate command line arguments
37 if [ "$1" = "-c" ]; then
40 [ $# -ge 3 -a $# -le 4 ] || Usage
41 [ "$3" = 0 -o "$3" = "1" -o "$3" = "2" -o "$3" = "3" ] || Usage
43 # Validate configuration
44 [ -w "$CMDFILE" ] || Error "Can't write to \"$CMDFILE\"!"
52 cfg=`grep -lE "^[[:space:]]+host_name[[:space:]]+${host}\$" "$CFGDIR"/*.cfg`
53 [ -n "$cfg" ] || Error "Host \"$host\" not configured!?"
57 # Passive service check; does it exist already?
58 grep -E "^[[:space:]]+service_description[[:space:]]+${service}\$" \
59 "$cfg" >/dev/null 2>&1
62 Error "Service \"$service\" not configured on \"$host\"!?"
63 echo "Creating new Nagios host configuration for \"$host\" ..."
67 use ${SERVICE_TEMPLATE_PASSIVE}
68 service_description $service
69 check_command ${SERVICE_PASSIVE_CMD}
73 chmod "$CFG_MODE" "$cfg" || Error "chmod(1) failed!"
74 echo "Reloading Nagios configuration ..."
75 "$RCFILE" reload || Error "Failed to reload Nagios configuration!"
81 cmd="[$time_t] PROCESS_SERVICE_CHECK_RESULT;$host;$service;$code;$text"
82 echo "$cmd" >>"$CMDFILE"