Update embedded libev code to version 4.22
[nsca-ng.git] / contrib / downtime
blobfa173b2bc1706badca70e137f443b96a1658babb
1 #!/bin/sh
3 # Copyright (c) 2013 Holger Weiss <holger@weiss.in-berlin.de>
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.
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.
13 # Note that this script uses non-standard date(1) extensions which aren't
14 # available on all systems. GNU date(1) provides them:
16 # http://www.gnu.org/software/coreutils/
18 set -e
19 set -u
21 send_nsca_args=${SEND_NSCA_ARGS:+$SEND_NSCA_ARGS}
23 die()
25 echo >&2 "$@"
26 exit 1
29 usage()
31 die "Usage: $0 [-C <comment>] [-c <config-file>] [-H <host>] [-S <service>]"
34 date -d 'now' '+%s' 2>&1 | grep '^[[:digit:]]*$' >/dev/null \
35 || die "$0: GNU date(1) or BSD date(1) is required"
37 while getopts C:c:e:H:hS:s: option
39 case $option in
41 comment=$OPTARG
44 send_nsca_args="${send_nsca_args:+$send_nsca_args }-c $OPTARG"
47 end=$OPTARG
50 host=$OPTARG
53 service=$OPTARG
56 start=$OPTARG
58 h|\?)
59 usage
61 esac
62 done
64 shift `expr $OPTIND - 1`
65 test $# -eq 0 || usage
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`"}
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
83 # vim:set joinspaces noexpandtab textwidth=80: