aboutsummaryrefslogtreecommitdiff
path: root/nagios-notification-switch
blob: a6c250702e63d70b373ee036f8d8e0fa0f161a45 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env bash

#
# nagios-notification-switch(1) -- Turn notifications off or on globally.
#
#    $ nns on
#    $ nns off
#
# Author: Tom Ryder <tom@sanctum.geek.nz>
# Copyright: 2016
#

# Name self
self=nagios-notification-switch

# Usage printing function
usage() {
    printf 'USAGE: %s [on|off]\n' "$self"
}

# If no args, exit with usage help
if ! (($#)) ; then
    usage >&2
    exit 1
fi

# Figure out what to do based on first argument
case $1 in

    # Give help in the form of usage information if requested
    -h|--help)
        usage
        ;;

    # Set notifications on
    on)
        printf '[%lu] ENABLE_NOTIFICATIONS\n' "$(date +%s)" \
            > "${NAGCMD_FILE:-/usr/local/nagios/var/rw/nagios.cmd}"
        ;;

    # Set notifications off
    off)
        printf '[%lu] DISABLE_NOTIFICATIONS\n' "$(date +%s)" \
            > "${NAGCMD_FILE:-/usr/local/nagios/var/rw/nagios.cmd}"
        ;;

    # Didn't understand the argument; say so and dump usage to stderr
    *)
        printf 'Unknown argument :%s\n' "$1"
        usage >&2
        exit 1
        ;;
esac