aboutsummaryrefslogtreecommitdiff
path: root/nagios-notification-switch
diff options
context:
space:
mode:
Diffstat (limited to 'nagios-notification-switch')
-rwxr-xr-xnagios-notification-switch53
1 files changed, 53 insertions, 0 deletions
diff --git a/nagios-notification-switch b/nagios-notification-switch
new file mode 100755
index 0000000..a6c2507
--- /dev/null
+++ b/nagios-notification-switch
@@ -0,0 +1,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