From 06818d240fa7d24c7acfd1d19f16575499c5ad25 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 22 Oct 2014 14:06:26 +1300 Subject: First commit --- README.markdown | 13 +++++++ README.md | 4 --- nac | 97 +++++++++++++++++++++++++++++++++++++++++++++++++ nac.1 | 47 ++++++++++++++++++++++++ nagios-acknowledge | 97 +++++++++++++++++++++++++++++++++++++++++++++++++ nagios-acknowledge.1 | 47 ++++++++++++++++++++++++ nagios-downtime | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++ nagios-downtime.1 | 53 +++++++++++++++++++++++++++ nagios-force-check | 77 +++++++++++++++++++++++++++++++++++++++ nagios-force-check.1 | 36 +++++++++++++++++++ ndt | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++ ndt.1 | 53 +++++++++++++++++++++++++++ nfc | 77 +++++++++++++++++++++++++++++++++++++++ nfc.1 | 36 +++++++++++++++++++ 14 files changed, 833 insertions(+), 4 deletions(-) create mode 100644 README.markdown delete mode 100644 README.md create mode 100755 nac create mode 100644 nac.1 create mode 100755 nagios-acknowledge create mode 100644 nagios-acknowledge.1 create mode 100755 nagios-downtime create mode 100644 nagios-downtime.1 create mode 100755 nagios-force-check create mode 100644 nagios-force-check.1 create mode 100755 ndt create mode 100644 ndt.1 create mode 100755 nfc create mode 100644 nfc.1 diff --git a/README.markdown b/README.markdown new file mode 100644 index 0000000..bdd7328 --- /dev/null +++ b/README.markdown @@ -0,0 +1,13 @@ +Nagscripts +========== + +Some Nagios shell scripts to simplify commands. `man(1)` pages included. + +License +------- + +Copyright (c) [Tom Ryder][1]. Distributed under [MIT License][2]. + +[1]: https://sanctum.geek.nz/ +[2]: http://opensource.org/licenses/MIT + diff --git a/README.md b/README.md deleted file mode 100644 index d16a4ae..0000000 --- a/README.md +++ /dev/null @@ -1,4 +0,0 @@ -nagscripts -========== - -Some Nagios shell scripts to simplify commands diff --git a/nac b/nac new file mode 100755 index 0000000..5878e40 --- /dev/null +++ b/nac @@ -0,0 +1,97 @@ +#!/usr/bin/env bash + +# +# nagios-acknowledge(1) -- Shortcut to acknowledge problems in Nagios, because +# it's annoying to do with the web interface for large sets of hosts or +# services. +# +# $ nac [/] [optional comment] +# +# Good for for/while loops: +# +# for hostname in hosta hostb hostc; do nac "$hostname" ... ; done +# while read -r hostname; do nac "$hostname" ... ; done < downtime-hostnames +# +# By default, does not send ACKNOWLEDGEMENT notifications. Use -n if you do +# want that. +# +# Author: Tom Ryder +# Copyright: 2014 Sanctum +# + +# Name self +self=nagios-acknowledge + +# Usage printing function +usage() { + printf 'USAGE: %s [-n] [comment]\n' "$self" +} + +# Default to not notifying +notify=0 + +# Figure out whether we should notify +OPTIND=1 +while getopts 'hn' opt ; do + case "$opt" in + n) + notify=1 + ;; + h) + usage + exit 0 + ;; + '?') + usage >&2 + exit 1 + ;; + esac +done +shift "$((OPTIND-1))" + +# Bail if no arguments left; we need at least the host/service name +if ! (($#)) ; then + usage >&2 + exit 1 +fi + +# Define relatively fixed/guaranteed fields for Nagios command; note that the +# comment has a default of 'no comment given' +now=$(date +%s) +spec=$1 +sticky=1 +notify=$notify +persistent=1 +author=${SUDO_USER:-$USER} +comment=${2:-'no comment given'} +cmdfile=${NAGCMD_FILE:-/usr/local/nagios/var/rw/nagios.cmd} + +# If a service name is specified after a slash, figure that out +if [[ $spec == */* ]] ; then + host=${spec%/*} + service=${spec##*/} +else + host=$spec + service= +fi + +# Quietly replace semicolons in comment with commas +comment=${comment//;/,} + +# Write command and print message if it fails; succeed silently +if [[ $service ]] ; then + cmd=$(printf '[%lu] ACKNOWLEDGE_SVC_PROBLEM;%s;%s;%u;%u;%u;%s;%s' \ + "$now" "$host" "$service" \ + "$sticky" "$notify" "$persistent" "$author" "$comment") +else + cmd=$(printf '[%lu] ACKNOWLEDGE_HOST_PROBLEM;%s;%u;%u;%u;%s;%s' \ + "$now" "$host" \ + "$sticky" "$notify" "$persistent" "$author" "$comment") +fi + +# Attempt to write command to file +if ! printf '%s\n' "$cmd" > "$cmdfile" ; then + printf '%s: Failed to write command to file\n' "$self" >&2 + exit 1 +fi + diff --git a/nac.1 b/nac.1 new file mode 100644 index 0000000..48f31f7 --- /dev/null +++ b/nac.1 @@ -0,0 +1,47 @@ +.TH NAGIOS-ACKNOWLEDGE 1 "Nagios Acknowledge" "Nagscripts" +.SH NAME +.B nac, nagios-acknowledge +\- Pleasant way to acknowledge problems with a Nagios host or service +.SH USAGE +.B nagios-acknowledge +-h +.br +.B nagios-acknowledge +[-n] +.I HOSTNAME[/SERVICE] +.I [COMMENT] +.SH SYNOPSIS +.B nac +webhost 'DDoS I think, fixing' +.PP +.B nac +-n webhost/HTTP 'Apache HTTPD crashed, fixing' +.PP +for hostname in ns{1..3} ; do +.br +.B + nac +"$hostname" 'DNS is completely rooted, addressing now' +.br +done +.SH DESCRIPTION +.B nagios-acknowledge +will format and attempt to write a Nagios command to the Nagios commands file +which it expects to find at /usr/local/nagios/var/rw/nagios.cmd to acknowledge +a problem for a particular host or service. +.PP +The user's current login name will be used as the author field for the +acknowledgement, taking into account any use of +.I sudo(8) +changes. Note that the +.I COMMENT +parameter is optional. +.P +By default, the script won't send an ACKNOWLEDGEMENT notification. Add a -n +option if you actually want to do this. +.SH SEE ALSO +nagios-downtime(1), nagios-force-check(1) +.SH AUTHOR +Tom Ryder +.PP + diff --git a/nagios-acknowledge b/nagios-acknowledge new file mode 100755 index 0000000..5878e40 --- /dev/null +++ b/nagios-acknowledge @@ -0,0 +1,97 @@ +#!/usr/bin/env bash + +# +# nagios-acknowledge(1) -- Shortcut to acknowledge problems in Nagios, because +# it's annoying to do with the web interface for large sets of hosts or +# services. +# +# $ nac [/] [optional comment] +# +# Good for for/while loops: +# +# for hostname in hosta hostb hostc; do nac "$hostname" ... ; done +# while read -r hostname; do nac "$hostname" ... ; done < downtime-hostnames +# +# By default, does not send ACKNOWLEDGEMENT notifications. Use -n if you do +# want that. +# +# Author: Tom Ryder +# Copyright: 2014 Sanctum +# + +# Name self +self=nagios-acknowledge + +# Usage printing function +usage() { + printf 'USAGE: %s [-n] [comment]\n' "$self" +} + +# Default to not notifying +notify=0 + +# Figure out whether we should notify +OPTIND=1 +while getopts 'hn' opt ; do + case "$opt" in + n) + notify=1 + ;; + h) + usage + exit 0 + ;; + '?') + usage >&2 + exit 1 + ;; + esac +done +shift "$((OPTIND-1))" + +# Bail if no arguments left; we need at least the host/service name +if ! (($#)) ; then + usage >&2 + exit 1 +fi + +# Define relatively fixed/guaranteed fields for Nagios command; note that the +# comment has a default of 'no comment given' +now=$(date +%s) +spec=$1 +sticky=1 +notify=$notify +persistent=1 +author=${SUDO_USER:-$USER} +comment=${2:-'no comment given'} +cmdfile=${NAGCMD_FILE:-/usr/local/nagios/var/rw/nagios.cmd} + +# If a service name is specified after a slash, figure that out +if [[ $spec == */* ]] ; then + host=${spec%/*} + service=${spec##*/} +else + host=$spec + service= +fi + +# Quietly replace semicolons in comment with commas +comment=${comment//;/,} + +# Write command and print message if it fails; succeed silently +if [[ $service ]] ; then + cmd=$(printf '[%lu] ACKNOWLEDGE_SVC_PROBLEM;%s;%s;%u;%u;%u;%s;%s' \ + "$now" "$host" "$service" \ + "$sticky" "$notify" "$persistent" "$author" "$comment") +else + cmd=$(printf '[%lu] ACKNOWLEDGE_HOST_PROBLEM;%s;%u;%u;%u;%s;%s' \ + "$now" "$host" \ + "$sticky" "$notify" "$persistent" "$author" "$comment") +fi + +# Attempt to write command to file +if ! printf '%s\n' "$cmd" > "$cmdfile" ; then + printf '%s: Failed to write command to file\n' "$self" >&2 + exit 1 +fi + diff --git a/nagios-acknowledge.1 b/nagios-acknowledge.1 new file mode 100644 index 0000000..48f31f7 --- /dev/null +++ b/nagios-acknowledge.1 @@ -0,0 +1,47 @@ +.TH NAGIOS-ACKNOWLEDGE 1 "Nagios Acknowledge" "Nagscripts" +.SH NAME +.B nac, nagios-acknowledge +\- Pleasant way to acknowledge problems with a Nagios host or service +.SH USAGE +.B nagios-acknowledge +-h +.br +.B nagios-acknowledge +[-n] +.I HOSTNAME[/SERVICE] +.I [COMMENT] +.SH SYNOPSIS +.B nac +webhost 'DDoS I think, fixing' +.PP +.B nac +-n webhost/HTTP 'Apache HTTPD crashed, fixing' +.PP +for hostname in ns{1..3} ; do +.br +.B + nac +"$hostname" 'DNS is completely rooted, addressing now' +.br +done +.SH DESCRIPTION +.B nagios-acknowledge +will format and attempt to write a Nagios command to the Nagios commands file +which it expects to find at /usr/local/nagios/var/rw/nagios.cmd to acknowledge +a problem for a particular host or service. +.PP +The user's current login name will be used as the author field for the +acknowledgement, taking into account any use of +.I sudo(8) +changes. Note that the +.I COMMENT +parameter is optional. +.P +By default, the script won't send an ACKNOWLEDGEMENT notification. Add a -n +option if you actually want to do this. +.SH SEE ALSO +nagios-downtime(1), nagios-force-check(1) +.SH AUTHOR +Tom Ryder +.PP + diff --git a/nagios-downtime b/nagios-downtime new file mode 100755 index 0000000..9a886e0 --- /dev/null +++ b/nagios-downtime @@ -0,0 +1,100 @@ +#!/usr/bin/env bash + +# +# nagios-downtime(1) -- Shortcut to scheduling fixed downtime in Nagios, +# because it's annoying to do with the web interface for large sets of hosts +# or services. +# +# $ ndt [/] [optional comment] +# +# Good for for/while loops: +# +# for hostname in hosta hostb hostc; do ndt "$hostname" ... ; done +# while read -r hostname; do ndt "$hostname" ... ; done < downtime-hosts +# +# Assumes date(1) with +%s format and --date option (probably only GNU date). +# +# Author: Tom Ryder +# Copyright: 2014 Sanctum +# + +# Name self +self=nagios-downtime + +# Usage printing function +usage() { + printf 'USAGE: %s [comment]\n' "$self" +} + +# Process options (just help at the moment) +OPTIND=1 +while getopts 'h' opt ; do + case "$opt" in + h) + usage + exit 0 + ;; + '?') + usage >&2 + exit 1 + ;; + esac +done +shift "$((OPTIND-1))" + +# Bail if too few arguments left; we need at least the hostname, the start date, and the end date +if (($# < 3)) ; then + usage >&2 + exit 1 +fi + +# Define relatively fixed/guaranteed fields for Nagios command; note that the +# comment has a default of 'no comment given' +now=$(date +%s) +spec=$1 +fixed=1 +trigger=0 +duration=0 +author=${SUDO_USER:-$USER} +comment=${4:-'no comment given'} +cmdfile=${NAGCMD_FILE:-/usr/local/nagios/var/rw/nagios.cmd} + +# If a service name is specified after a slash, figure that out +if [[ $spec == */* ]] ; then + host=${spec%/*} + service=${spec##*/} +else + host=$spec + service= +fi + +# Quietly replace semicolons in comment with commas +comment=${comment//;/,} + +# Attempt to parse start and end dates; fail usefully if the call doesn't work +if ! dtstart=$(date +%s --date "$2") ; then + printf '%s: Could not parse start date %s' "$self" "$2" >&2 + exit 1 +fi +if ! dtend=$(date +%s --date "$3") ; then + printf '%s: Could not parse end date %s' "$self" "$3" >&2 + exit 1 +fi + +# Write command and print message if it fails; succeed silently +if [[ $service ]] ; then + cmd=$(printf '[%lu] SCHEDULE_SVC_DOWNTIME;%s;%s;%s;%s;%u;%u;%u;%s;%s' \ + "$now" "$host" "$service" "$dtstart" "$dtend" \ + "$fixed" "$trigger" "$duration" "$author" "$comment") +else + cmd=$(printf '[%lu] SCHEDULE_HOST_DOWNTIME;%s;%s;%s;%u;%u;%u;%s;%s' \ + "$now" "$host" "$dtstart" "$dtend" \ + "$fixed" "$trigger" "$duration" "$author" "$comment") +fi + +# Attempt to write command to file +if ! printf '%s\n' "$cmd" > "$cmdfile" ; then + printf '%s: Failed to write command to file\n' "$self" >&2 + exit 1 +fi + diff --git a/nagios-downtime.1 b/nagios-downtime.1 new file mode 100644 index 0000000..c4ef614 --- /dev/null +++ b/nagios-downtime.1 @@ -0,0 +1,53 @@ +.TH NAGIOS-DOWNTIME 1 "Nagios Downtime" "Nagscripts" +.SH NAME +.B ndt, nagios-downtime +\- Pleasant way to script fixed downtime for a Nagios host or service +.SH USAGE +.B nagios-downtime +-h +.br +.B nagios-downtime +.I HOSTNAME[/SERVICE] +.I START +.I END +.I [COMMENT] +.SH SYNOPSIS +.B ndt +webhost now 10pm 'Upgrading to latest OS release' +.PP +.B ndt +webhost/HTTP now 10pm 'Upgrading Apache HTTPD' +.PP +for hostname in ns{1..3} ; do +.br +.B + ndt +"$hostname" 'sunday 3:00am' 'sunday 4:00am' 'Outage for entire DNS system for upgrades' +.br +done +.SH DESCRIPTION +.B nagios-downtime +will format and attempt to write a Nagios command to the Nagios commands file +which it expects to find at /usr/local/nagios/var/rw/nagios.cmd to schedule +downtime for a particular host or service. The two date fields +.I START +and +.I END +may be given in any form understood by +.I date(1) +with the +.I --date +option. +.PP +The user's current login name will be used as the author field for the +downtime, taking into account any use of +.I sudo(8) +changes. Note that the +.I COMMENT +parameter is optional. +.SH SEE ALSO +nagios-acknowledge(1), nagios-force-check(1) +.SH AUTHOR +Tom Ryder +.PP + diff --git a/nagios-force-check b/nagios-force-check new file mode 100755 index 0000000..99d9534 --- /dev/null +++ b/nagios-force-check @@ -0,0 +1,77 @@ +#!/usr/bin/env bash + +# +# nagios-force-check(1) -- Force an immediate check of a nominated host or +# service. +# +# $ nac [/] +# +# Author: Tom Ryder +# Copyright: 2014 Sanctum +# + +# Name self +self=nagios-force-check + +# Usage printing function +usage() { + printf 'USAGE: %s [-n] \n' "$self" +} + +# Handle options, just -h help at the moment +OPTIND=1 +while getopts 'h' opt ; do + case "$opt" in + h) + usage + exit 0 + ;; + '?') + usage >&2 + exit 1 + ;; + esac +done +shift "$((OPTIND-1))" + +# Bail if no arguments left; we need at least the host/service name +if ! (($#)) ; then + usage >&2 + exit 1 +fi + +# Define relatively fixed/guaranteed fields for Nagios command; note that the +# comment has a default of 'no comment given' +now=$(date +%s) +spec=$1 +cmdfile=${NAGCMD_FILE:-/usr/local/nagios/var/rw/nagios.cmd} + +# If a service name is specified after a slash, figure that out +if [[ $spec == */* ]] ; then + host=${spec%/*} + service=${spec##*/} +else + host=$spec + service= +fi + +# Write command and print message if it fails; succeed silently +declare -a cmds +if [[ $service ]] ; then + cmds=("${cmds[@]}" "$(printf '[%lu] SCHEDULE_FORCED_SVC_CHECK;%s;%s;%lu' \ + "$now" "$host" "$service" "$now")") +else + cmds=("${cmds[@]}" "$(printf '[%lu] SCHEDULE_FORCED_HOST_CHECK;%s;%lu' \ + "$now" "$host" "$now")") + cmds=("${cmds[@]}" "$(printf '[%lu] SCHEDULE_HOST_SVC_CHECKS;%s;%lu' \ + "$now" "$host" "$now")") +fi + +# Attempt to write command to file +for cmd in "${cmds[@]}" ; do + if ! printf '%s\n' "$cmd" >> "$cmdfile" ; then + printf '%s: Failed to write command to file\n' "$self" >&2 + exit 1 + fi +done + diff --git a/nagios-force-check.1 b/nagios-force-check.1 new file mode 100644 index 0000000..27d7114 --- /dev/null +++ b/nagios-force-check.1 @@ -0,0 +1,36 @@ +.TH NAGIOS-FORCE-CHECK 1 "Nagios Force Check" "Nagscripts" +.SH NAME +.B nfc, nagios-force-check +\- Pleasant way to force a check for a Nagios host or service +.SH USAGE +.B nagios-force-check +-h +.br +.B nagios-force-check +.I HOSTNAME[/SERVICE] +.SH SYNOPSIS +.B nfc +webhost +.br +.B nfc +webhost/HTTP +.B +.br +.B nul +| while read -r object ; do +.br + nfc "$object" +.br +done +.SH DESCRIPTION +.B nagios-force-check +will format and attempt to write a Nagios command to the Nagios commands file +which it expects to find at /usr/local/nagios/var/rw/nagios.cmd to force a +check of a particular host (and all its services) or just one particular +service. +.SH SEE ALSO +nagios-acknowledge(1), nagios-downtime(1) +.SH AUTHOR +Tom Ryder +.PP + diff --git a/ndt b/ndt new file mode 100755 index 0000000..9a886e0 --- /dev/null +++ b/ndt @@ -0,0 +1,100 @@ +#!/usr/bin/env bash + +# +# nagios-downtime(1) -- Shortcut to scheduling fixed downtime in Nagios, +# because it's annoying to do with the web interface for large sets of hosts +# or services. +# +# $ ndt [/] [optional comment] +# +# Good for for/while loops: +# +# for hostname in hosta hostb hostc; do ndt "$hostname" ... ; done +# while read -r hostname; do ndt "$hostname" ... ; done < downtime-hosts +# +# Assumes date(1) with +%s format and --date option (probably only GNU date). +# +# Author: Tom Ryder +# Copyright: 2014 Sanctum +# + +# Name self +self=nagios-downtime + +# Usage printing function +usage() { + printf 'USAGE: %s [comment]\n' "$self" +} + +# Process options (just help at the moment) +OPTIND=1 +while getopts 'h' opt ; do + case "$opt" in + h) + usage + exit 0 + ;; + '?') + usage >&2 + exit 1 + ;; + esac +done +shift "$((OPTIND-1))" + +# Bail if too few arguments left; we need at least the hostname, the start date, and the end date +if (($# < 3)) ; then + usage >&2 + exit 1 +fi + +# Define relatively fixed/guaranteed fields for Nagios command; note that the +# comment has a default of 'no comment given' +now=$(date +%s) +spec=$1 +fixed=1 +trigger=0 +duration=0 +author=${SUDO_USER:-$USER} +comment=${4:-'no comment given'} +cmdfile=${NAGCMD_FILE:-/usr/local/nagios/var/rw/nagios.cmd} + +# If a service name is specified after a slash, figure that out +if [[ $spec == */* ]] ; then + host=${spec%/*} + service=${spec##*/} +else + host=$spec + service= +fi + +# Quietly replace semicolons in comment with commas +comment=${comment//;/,} + +# Attempt to parse start and end dates; fail usefully if the call doesn't work +if ! dtstart=$(date +%s --date "$2") ; then + printf '%s: Could not parse start date %s' "$self" "$2" >&2 + exit 1 +fi +if ! dtend=$(date +%s --date "$3") ; then + printf '%s: Could not parse end date %s' "$self" "$3" >&2 + exit 1 +fi + +# Write command and print message if it fails; succeed silently +if [[ $service ]] ; then + cmd=$(printf '[%lu] SCHEDULE_SVC_DOWNTIME;%s;%s;%s;%s;%u;%u;%u;%s;%s' \ + "$now" "$host" "$service" "$dtstart" "$dtend" \ + "$fixed" "$trigger" "$duration" "$author" "$comment") +else + cmd=$(printf '[%lu] SCHEDULE_HOST_DOWNTIME;%s;%s;%s;%u;%u;%u;%s;%s' \ + "$now" "$host" "$dtstart" "$dtend" \ + "$fixed" "$trigger" "$duration" "$author" "$comment") +fi + +# Attempt to write command to file +if ! printf '%s\n' "$cmd" > "$cmdfile" ; then + printf '%s: Failed to write command to file\n' "$self" >&2 + exit 1 +fi + diff --git a/ndt.1 b/ndt.1 new file mode 100644 index 0000000..c4ef614 --- /dev/null +++ b/ndt.1 @@ -0,0 +1,53 @@ +.TH NAGIOS-DOWNTIME 1 "Nagios Downtime" "Nagscripts" +.SH NAME +.B ndt, nagios-downtime +\- Pleasant way to script fixed downtime for a Nagios host or service +.SH USAGE +.B nagios-downtime +-h +.br +.B nagios-downtime +.I HOSTNAME[/SERVICE] +.I START +.I END +.I [COMMENT] +.SH SYNOPSIS +.B ndt +webhost now 10pm 'Upgrading to latest OS release' +.PP +.B ndt +webhost/HTTP now 10pm 'Upgrading Apache HTTPD' +.PP +for hostname in ns{1..3} ; do +.br +.B + ndt +"$hostname" 'sunday 3:00am' 'sunday 4:00am' 'Outage for entire DNS system for upgrades' +.br +done +.SH DESCRIPTION +.B nagios-downtime +will format and attempt to write a Nagios command to the Nagios commands file +which it expects to find at /usr/local/nagios/var/rw/nagios.cmd to schedule +downtime for a particular host or service. The two date fields +.I START +and +.I END +may be given in any form understood by +.I date(1) +with the +.I --date +option. +.PP +The user's current login name will be used as the author field for the +downtime, taking into account any use of +.I sudo(8) +changes. Note that the +.I COMMENT +parameter is optional. +.SH SEE ALSO +nagios-acknowledge(1), nagios-force-check(1) +.SH AUTHOR +Tom Ryder +.PP + diff --git a/nfc b/nfc new file mode 100755 index 0000000..99d9534 --- /dev/null +++ b/nfc @@ -0,0 +1,77 @@ +#!/usr/bin/env bash + +# +# nagios-force-check(1) -- Force an immediate check of a nominated host or +# service. +# +# $ nac [/] +# +# Author: Tom Ryder +# Copyright: 2014 Sanctum +# + +# Name self +self=nagios-force-check + +# Usage printing function +usage() { + printf 'USAGE: %s [-n] \n' "$self" +} + +# Handle options, just -h help at the moment +OPTIND=1 +while getopts 'h' opt ; do + case "$opt" in + h) + usage + exit 0 + ;; + '?') + usage >&2 + exit 1 + ;; + esac +done +shift "$((OPTIND-1))" + +# Bail if no arguments left; we need at least the host/service name +if ! (($#)) ; then + usage >&2 + exit 1 +fi + +# Define relatively fixed/guaranteed fields for Nagios command; note that the +# comment has a default of 'no comment given' +now=$(date +%s) +spec=$1 +cmdfile=${NAGCMD_FILE:-/usr/local/nagios/var/rw/nagios.cmd} + +# If a service name is specified after a slash, figure that out +if [[ $spec == */* ]] ; then + host=${spec%/*} + service=${spec##*/} +else + host=$spec + service= +fi + +# Write command and print message if it fails; succeed silently +declare -a cmds +if [[ $service ]] ; then + cmds=("${cmds[@]}" "$(printf '[%lu] SCHEDULE_FORCED_SVC_CHECK;%s;%s;%lu' \ + "$now" "$host" "$service" "$now")") +else + cmds=("${cmds[@]}" "$(printf '[%lu] SCHEDULE_FORCED_HOST_CHECK;%s;%lu' \ + "$now" "$host" "$now")") + cmds=("${cmds[@]}" "$(printf '[%lu] SCHEDULE_HOST_SVC_CHECKS;%s;%lu' \ + "$now" "$host" "$now")") +fi + +# Attempt to write command to file +for cmd in "${cmds[@]}" ; do + if ! printf '%s\n' "$cmd" >> "$cmdfile" ; then + printf '%s: Failed to write command to file\n' "$self" >&2 + exit 1 + fi +done + diff --git a/nfc.1 b/nfc.1 new file mode 100644 index 0000000..27d7114 --- /dev/null +++ b/nfc.1 @@ -0,0 +1,36 @@ +.TH NAGIOS-FORCE-CHECK 1 "Nagios Force Check" "Nagscripts" +.SH NAME +.B nfc, nagios-force-check +\- Pleasant way to force a check for a Nagios host or service +.SH USAGE +.B nagios-force-check +-h +.br +.B nagios-force-check +.I HOSTNAME[/SERVICE] +.SH SYNOPSIS +.B nfc +webhost +.br +.B nfc +webhost/HTTP +.B +.br +.B nul +| while read -r object ; do +.br + nfc "$object" +.br +done +.SH DESCRIPTION +.B nagios-force-check +will format and attempt to write a Nagios command to the Nagios commands file +which it expects to find at /usr/local/nagios/var/rw/nagios.cmd to force a +check of a particular host (and all its services) or just one particular +service. +.SH SEE ALSO +nagios-acknowledge(1), nagios-downtime(1) +.SH AUTHOR +Tom Ryder +.PP + -- cgit v1.2.3