| 1 |
#!/bin/sh |
| 2 |
# |
| 3 |
# Copyright (c) 2013 Holger Weiss <[email protected]> |
| 4 |
# |
| 5 |
# This file is free software; Holger Weiss gives unlimited permission to copy |
| 6 |
# and/or distribute it, with or without modifications, as long as this notice is |
| 7 |
# preserved. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 |
# ANY WARRANTY, to the extent permitted by law; without even the implied |
| 11 |
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 |
|
| 13 |
set -e |
| 14 |
set -u |
| 15 |
|
| 16 |
send_nsca_args=${SEND_NSCA_ARGS:+$SEND_NSCA_ARGS} |
| 17 |
|
| 18 |
die() |
| 19 |
{ |
| 20 |
echo >&2 "$@" |
| 21 |
exit 1 |
| 22 |
} |
| 23 |
|
| 24 |
usage() |
| 25 |
{ |
| 26 |
die "Usage: $0 [-C <comment>] [-c <config-file>] [-H <host>] [-S <service>]" |
| 27 |
} |
| 28 |
|
| 29 |
while getopts C:c:H:hS: option |
| 30 |
do |
| 31 |
case $option in |
| 32 |
C) |
| 33 |
comment=$OPTARG |
| 34 |
;; |
| 35 |
c) |
| 36 |
send_nsca_args="${send_nsca_args:+$send_nsca_args }-c $OPTARG" |
| 37 |
;; |
| 38 |
H) |
| 39 |
host=$OPTARG |
| 40 |
;; |
| 41 |
S) |
| 42 |
service=$OPTARG |
| 43 |
;; |
| 44 |
h|\?) |
| 45 |
usage |
| 46 |
;; |
| 47 |
esac |
| 48 |
done |
| 49 |
|
| 50 |
shift `expr $OPTIND - 1` |
| 51 |
test $# -eq 0 || usage |
| 52 |
|
| 53 |
host=${host:-`hostname -s`} |
| 54 |
service=${service:+$service} |
| 55 |
author=`getent passwd "$USER" | cut -d: -f5` |
| 56 |
comment=${comment:-"Submitted by send_nsca@`hostname -s`"} |
| 57 |
|
| 58 |
if [ -z "$service" ] |
| 59 |
then # Host acknowledgement. |
| 60 |
printf '%b' "ACKNOWLEDGE_HOST_PROBLEM;$host;1;0;1;$author;$comment\n" \ |
| 61 |
| send_nsca -C $send_nsca_args |
| 62 |
else # Service acknowledgement. |
| 63 |
printf '%b' "ACKNOWLEDGE_SVC_PROBLEM;$host;$service;1;0;1;$author;$comment\n" \ |
| 64 |
| send_nsca -C $send_nsca_args |
| 65 |
fi |
| 66 |
|
| 67 |
# vim:set joinspaces noexpandtab textwidth=80: |