| 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 -u |
| 14 | |
| 15 | send_nsca_args=${SEND_NSCA_ARGS:+$SEND_NSCA_ARGS} |
| 16 | |
| 17 | PATH="$PATH:/usr/local/nagios/libexec:/usr/lib/nagios/plugins" |
| 18 | export PATH |
| 19 | |
| 20 | die() |
| 21 | { |
| 22 | echo >&2 "$@" |
| 23 | exit 1 |
| 24 | } |
| 25 | |
| 26 | usage() |
| 27 | { |
| 28 | die "Usage: $0 [-c <config-file>] [-H <host>] [-S <service>]" \ |
| 29 | "<plugin> [<argument> ...]" |
| 30 | } |
| 31 | |
| 32 | while getopts c:H:hS: option |
| 33 | do |
| 34 | case $option in |
| 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 $# -ge 1 || usage |
| 52 | |
| 53 | host=${host:-`hostname | sed 's+\..*++' | tr '[:upper:]' '[:lower:]'`} |
| 54 | service=${service:-`echo "$1" | sed 's+.*[_/]++' | tr '[:lower:]' '[:upper:]'`} |
| 55 | output=`"$@"` |
| 56 | state=$? |
| 57 | |
| 58 | test $state -le 3 || die "$0: '$@' yields invalid plugin return code $state" |
| 59 | |
| 60 | printf '%b' "$host\t$service\t$state\t$output\n" | send_nsca $send_nsca_args |
| 61 | |
| 62 | # vim:set joinspaces noexpandtab textwidth=80: |