Debian Codegraph @

contrib/downtime

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/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 diescip-shell shell shell-project 0.0.0 die().()
24 {
25 echoscip-shell system . . echo. >&2 "$@"
26 exit 1
27 }
28
29 usagescip-shell shell shell-project 0.0.0 usage().()
30 {
31 diescip-shell shell shell-project 0.0.0 die(). "Usage: $0 [-C <comment>] [-c <config-file>] [-H <host>] [-S <service>]"
32 }
33
34 datescip-shell system . . date. -d 'now' '+%s' 2>&1 | grepscip-shell system . . grep. '^[[:digit:]]*$' >/dev/nullscip-shell filesystem . . `/dev/null`. \
35 || diescip-shell shell shell-project 0.0.0 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 usagescip-shell shell shell-project 0.0.0 usage().
60 ;;
61 esac
62 done
63
64 shift `exprscip-shell system . . expr. $OPTIND - 1`
65 testscip-shell system . . test. $# -eq 0 || usagescip-shell shell shell-project 0.0.0 usage().
66
67 host=${host:-`hostnamescip-shell system . . hostname. -s`}
68 service=${service:+$service}
69 start=`datescip-shell system . . date. -d ${start:-'now'} '+%s'`
70 end=`datescip-shell system . . date. -d ${end:-'+2 hours'} '+%s'`
71 author=`getentscip-shell system . . getent. passwd "$USER" | cutscip-shell system . . cut. -d: -f5`
72 comment=${comment:-"Submitted by send_nsca@`hostnamescip-shell system . . hostname. -s`"}
73
74 if [scip-shell system . . `[`. -z "$service" ]
75 then # Host check.
76 printfscip-shell system . . 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 printfscip-shell system . . 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: