| 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 | # Note that this script uses non-standard date(1) extensions which aren't |
| 14 | # available on all systems. GNU date(1) provides them: |
| 15 | # |
| 16 | # http://www.gnu.org/software/coreutils/ |
| 17 | |
| 18 | set -e |
| 19 | set -u |
| 20 | |
| 21 | send_nsca_args=${SEND_NSCA_ARGS:+$SEND_NSCA_ARGS} |
| 22 | |
| 23 | die() |
| 24 | { |
| 25 | echo >&2 "$@" |
| 26 | exit 1 |
| 27 | } |
| 28 | |
| 29 | usage() |
| 30 | { |
| 31 | die "Usage: $0 [-C <comment>] [-c <config-file>] [-H <host>] [-S <service>]" |
| 32 | } |
| 33 | |
| 34 | date -d 'now' '+%s' 2>&1 | grep '^[[:digit:]]*$' >/dev/null \ |
| 35 | || die "$0: GNU date(1) or BSD date(1) is required" |
| 36 | |
| 37 | while getopts C:c:e:H:hS:s: option |
| 38 | do |
| 39 | case $option in |
| 40 | C) |
| 41 | comment=$OPTARG |
| 42 | ;; |
| 43 | c) |
| 44 | send_nsca_args="${send_nsca_args:+$send_nsca_args }-c $OPTARG" |
| 45 | ;; |
| 46 | e) |
| 47 | end=$OPTARG |
| 48 | ;; |
| 49 | H) |
| 50 | host=$OPTARG |
| 51 | ;; |
| 52 | S) |
| 53 | service=$OPTARG |
| 54 | ;; |
| 55 | s) |
| 56 | start=$OPTARG |
| 57 | ;; |
| 58 | h|\?) |
| 59 | usage |
| 60 | ;; |
| 61 | esac |
| 62 | done |
| 63 | |
| 64 | shift `expr $OPTIND - 1` |
| 65 | test $# -eq 0 || usage |
| 66 | |
| 67 | host=${host:-`hostname -s`} |
| 68 | service=${service:+$service} |
| 69 | start=`date -d ${start:-'now'} '+%s'` |
| 70 | end=`date -d ${end:-'+2 hours'} '+%s'` |
| 71 | author=`getent passwd "$USER" | cut -d: -f5` |
| 72 | comment=${comment:-"Submitted by send_nsca@`hostname -s`"} |
| 73 | |
| 74 | if [ -z "$service" ] |
| 75 | then # Host check. |
| 76 | printf '%b' "SCHEDULE_HOST_DOWNTIME;$host;$start;$end;1;0;0;$author;$comment\n" \ |
| 77 | | send_nsca -C $send_nsca_args |
| 78 | else # Service check. |
| 79 | printf '%b' "SCHEDULE_SVC_DOWNTIME;$host;$service;$start;$end;1;0;0;$author;$comment\n" \ |
| 80 | | send_nsca -C $send_nsca_args |
| 81 | fi |
| 82 | |
| 83 | # vim:set joinspaces noexpandtab textwidth=80: |