From cdc34fa78b326bd241aae7399190c739e25bf025 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 20 Jun 2016 13:08:15 +1200 Subject: Update to latest version with MKLivestatus No longer using NDOUtils at work, these are much nicer and more likely to work with any given Nagios installation now anyway. Added nagios-data-search, nagios-downtstream-list, nagios-exists, nagios-problem-list, and nagios-unhandled-list. --- LICENSE | 3 +- README.markdown | 1 - nagios-acknowledge | 86 +++++++++++++++++++++++++++------------- nagios-acknowledge.1 | 25 ++++++------ nagios-data-search | 72 ++++++++++++++++++++++++++++++++++ nagios-data-search.1 | 19 +++++++++ nagios-downstream-list | 62 +++++++++++++++++++++++++++++ nagios-downstream-list.1 | 17 ++++++++ nagios-downtime | 100 +++++++++++++++++++++++++++++------------------ nagios-downtime.1 | 29 +++++++------- nagios-exists | 79 +++++++++++++++++++++++++++++++++++++ nagios-exists.1 | 29 ++++++++++++++ nagios-force-check | 89 +++++++++++++++++++++++++++-------------- nagios-force-check.1 | 28 ++++++++++--- nagios-problem-list | 61 +++++++++++++++++++++++++++++ nagios-problem-list.1 | 30 ++++++++++++++ nagios-unhandled-list | 65 ++++++++++++++++++++++++++++++ nagios-unhandled-list.1 | 30 ++++++++++++++ 18 files changed, 693 insertions(+), 132 deletions(-) create mode 100755 nagios-data-search create mode 100644 nagios-data-search.1 create mode 100755 nagios-downstream-list create mode 100644 nagios-downstream-list.1 create mode 100755 nagios-exists create mode 100644 nagios-exists.1 create mode 100755 nagios-problem-list create mode 100644 nagios-problem-list.1 create mode 100755 nagios-unhandled-list create mode 100644 nagios-unhandled-list.1 diff --git a/LICENSE b/LICENSE index d77e562..77ba6a1 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014 Tom Ryder +Copyright (c) 2016 Tom Ryder Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - diff --git a/README.markdown b/README.markdown index b922a2c..e38e3fe 100644 --- a/README.markdown +++ b/README.markdown @@ -17,4 +17,3 @@ Copyright (c) [Tom Ryder][2]. Distributed under [MIT License][3]. [1]: https://www.inspire.net.nz/ [2]: https://sanctum.geek.nz/ [3]: http://opensource.org/licenses/MIT - diff --git a/nagios-acknowledge b/nagios-acknowledge index 51fdce8..f9b1081 100755 --- a/nagios-acknowledge +++ b/nagios-acknowledge @@ -5,18 +5,21 @@ # it's annoying to do with the web interface for large sets of hosts or # services. # -# $ nac [/] [optional comment] +# $ nac (|-) [optional comment] # -# Good for for/while loops: +# You can specify multiple objects by separating them with commas: # -# for hostname in hosta hostb hostc; do nac "$hostname" ... ; done -# while read -r hostname; do nac "$hostname" ... ; done < downtime-hostnames +# $ nac abc-example-ap-1,abc-example-ap-2/VOLTAGE 'Power problems at abc-example' +# +# Even easier is to pipe them into stdin by specifying - as the object: +# +# $ nul | grep abc-example | nac - 'Power problems at abc-example' # # By default, does not send ACKNOWLEDGEMENT notifications. Use -n if you do # want that. # # Author: Tom Ryder -# Copyright: 2014 Sanctum +# Copyright: 2016 # # Name self @@ -24,16 +27,16 @@ self=nagios-acknowledge # Usage printing function usage() { - printf 'USAGE: %s [-n] [comment]\n' "$self" + printf 'USAGE: %s [-n] (|-) [comment]\n' "$self" } # Default to not notifying notify=0 -# Process options +# Figure out whether we should notify OPTIND=1 while getopts 'hn' opt ; do - case "$opt" in + case $opt in n) notify=1 ;; @@ -60,37 +63,66 @@ fi 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 +# How to get the objects depends on the spec (the first argument) +declare -a objects +case $spec in + + # If the spec is just "-", we just read unique objects from stdin + -) + while read -r object ; do + [[ $object ]] || continue + objects[${#objects[@]}]=$object + done < <(sort -u) + ;; + + # If the spec is anything else, we break it up with commas and read the + # objects that way + *) + IFS=, read -a objects -r < <(printf '%s\n' "$spec") + ;; +esac + +# All the hosts or services must exist, just to be strict; they don't +# necessarily have to be in a PROBLEM state though +for object in "${objects[@]}" ; do + nagios-exists "$object" && continue + printf '%s: Host/service %s does not seem to exist\n' \ + "$self" "$object" >&2 + exit 1 +done # 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 +# Write commands to schedule downtime for each of the objects, bail if a single +# one of them fails +for object in "${objects[@]}" ; do + case $object in + */*) + host=${object%/*} + service=${object##*/} + cmd=$(printf '[%lu] ACKNOWLEDGE_SVC_PROBLEM;%s;%s;%u;%u;%u;%s;%s' \ + "$now" "$host" "$service" \ + "$sticky" "$notify" "$persistent" "$author" "$comment") + ;; + *) + host=$object + cmd=$(printf '[%lu] ACKNOWLEDGE_HOST_PROBLEM;%s;%u;%u;%u;%s;%s' \ + "$now" "$host" \ + "$sticky" "$notify" "$persistent" "$author" "$comment") + ;; + esac + printf '%s\n' "$cmd" > "$cmdfile" || exit +done # 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 index 48f31f7..2641acf 100644 --- a/nagios-acknowledge.1 +++ b/nagios-acknowledge.1 @@ -8,28 +8,25 @@ .br .B nagios-acknowledge [-n] -.I HOSTNAME[/SERVICE] +.I (HOSTNAME[/SERVICE][,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 +nac webhost 'DDoS I think, fixing' .br -.B - nac -"$hostname" 'DNS is completely rooted, addressing now' +nac -n webhost/HTTP 'Apache HTTPD crashed, fixing' .br -done +nac authns1,authns2,recdns1,recdns2 'DNS is all buggered' +.br +npl | grep abc-example | nac - 'Power problems at abc-example' .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 +Multiple hosts or services can be separated by commas, and the special value - +allows hosts or services to be read from stdin. +.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) @@ -40,8 +37,8 @@ parameter is optional. 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) +nagios-data-search(1), nagios-descendent-list(1), nagios-downtime(1), +nagios-force-check(1), nagios-problem-list(1), nagios-unhandled-list(1) .SH AUTHOR Tom Ryder .PP - diff --git a/nagios-data-search b/nagios-data-search new file mode 100755 index 0000000..5be21ca --- /dev/null +++ b/nagios-data-search @@ -0,0 +1,72 @@ +#!/usr/bin/env bash + +# +# nagios-data-search(1) -- List all the hosts (or services) matching any of a +# set of strings. +# +# $ nds abc-example- +# $ nds abc- def- ghi- +# $ nds -s WORDPRESS +# +# Author: Tom Ryder +# Copyright: 2016 +# + +# Name self +self=nagios-data-search + +# Usage printing function +usage() { + printf 'USAGE: %s [-hs] STRING\n' "$self" +} + +# By default we search hosts, not services +services=0 + +# Handle options, just -h help at the moment +OPTIND=1 +while getopts 'hs' opt ; do + case "$opt" in + h) + usage + exit 0 + ;; + s) + services=1 + ;; + '?') + usage >&2 + exit 1 + ;; + esac +done +shift "$((OPTIND-1))" + +# We need exactly one argument after that +if ! (($#)) ; then + usage >&2 + exit 1 +fi + +# Define the path to the Livestatus socket +socket=${MK_LIVESTATUS_SOCKET:-/usr/local/nagios/var/rw/live} + +# Iterate through the search terms +for search ; do + if ((services)) ; then + unixcat "$socket" < diff --git a/nagios-downstream-list b/nagios-downstream-list new file mode 100755 index 0000000..6485e89 --- /dev/null +++ b/nagios-downstream-list @@ -0,0 +1,62 @@ +#!/usr/bin/env bash + +# +# nagios-downstream-list(1) -- List all the descendents of at least one given +# host, unique and sorted. +# +# $ ndl abc-example-mc-1 +# +# Author: Tom Ryder +# Copyright: 2016 +# + +# Name self +self=nagios-downstream-list + +# Usage printing function +usage() { + printf 'USAGE: %s HOST1 [HOST2 ... ]\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))" + +# We need at least one argument remaining +if ! (($#)) ; then + usage >&2 + exit 1 +fi + +# Define the path to the Livestatus socket +socket=${MK_LIVESTATUS_SOCKET:-/usr/local/nagios/var/rw/live} + +# Recursive function to print all the descendents of the arguments +descendents() { + for ancestor ; do + while read -r child ; do + printf '%s\n' "$child" + descendents "$child" + done < <(unixcat "$socket" <= $ancestor +EOF + ) + done | sort -uV +} + +# Run the recursive function on all the arguments given to this script +descendents "$@" diff --git a/nagios-downstream-list.1 b/nagios-downstream-list.1 new file mode 100644 index 0000000..9633d97 --- /dev/null +++ b/nagios-downstream-list.1 @@ -0,0 +1,17 @@ +.TH NAGIOS-DOWNSTREAM-LIST 1 "Nagios Downstream List" "Nagscripts" +.SH NAME +.B ndl, nagios-downstream-list +\- List hosts dependent on a given host +.SH USAGE +.B nagios-downstream-list +.I HOSTNAME1 [HOSTNAME2 ...] +.SH DESCRIPTION +.B nagios-downstream-list +will write to standard output the descendent hosts of the host(s) given as the +sole argument as read from a MK LiveStatus socket. +.SH SEE ALSO +nagios-acknowledge(1), nagios-data-search(1), nagios-downtime(1), +nagios-force-check(1), nagios-notification-switch(1), nagios-problem-list(1), +nagios-unhandled-list(1) +.SH AUTHOR +Tom Ryder diff --git a/nagios-downtime b/nagios-downtime index 9a886e0..fdf9988 100755 --- a/nagios-downtime +++ b/nagios-downtime @@ -5,17 +5,20 @@ # because it's annoying to do with the web interface for large sets of hosts # or services. # -# $ ndt [/] [optional comment] +# $ ndt (|-) [comment]\n' "$self" # -# Good for for/while loops: +# You can specify multiple objects by separating them with commas: # -# for hostname in hosta hostb hostc; do ndt "$hostname" ... ; done -# while read -r hostname; do ndt "$hostname" ... ; done < downtime-hosts +# $ ndt abc-example-ap-1,abc-example-ap-2/VOLTAGE 9am 10am 'Power problems at abc-example' +# +# Even easier is to pipe them into stdin by specifying - as the object: +# +# $ nds abc-example | ndt - 9am 10am 'Power problems at abc-example' # # Assumes date(1) with +%s format and --date option (probably only GNU date). # # Author: Tom Ryder -# Copyright: 2014 Sanctum +# Copyright: 2016 # # Name self @@ -23,7 +26,7 @@ self=nagios-downtime # Usage printing function usage() { - printf 'USAGE: %s [comment]\n' "$self" + printf 'USAGE: %s [|-] [comment]\n' "$self" } # Process options (just help at the moment) @@ -59,42 +62,65 @@ 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 +# How to get the objects depends on the spec (the first argument) +declare -a objects +case $spec in -# Quietly replace semicolons in comment with commas -comment=${comment//;/,} + # If the spec is just "-", we just read unique objects from stdin + -) + while read -r object ; do + [[ $object ]] || continue + objects[${#objects[@]}]=$object + done < <(sort -u) + ;; -# 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 + # If the spec is anything else, we break it up with commas and read the + # objects that way + *) + IFS=, read -a objects -r < <(printf '%s\n' "$spec") + ;; +esac + +# All the hosts or services must exist, just to be strict +for object in "${objects[@]}" ; do + nagios-exists "$object" && continue + printf '%s: Host/service %s does not seem to exist\n' \ + "$self" "$object" >&2 exit 1 -fi +done -# 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 parse start and end dates; fail if the call doesn't work +dta=$(date +%s --date "$2") || exit +dtb=$(date +%s --date "$3") || exit -# Attempt to write command to file -if ! printf '%s\n' "$cmd" > "$cmdfile" ; then - printf '%s: Failed to write command to file\n' "$self" >&2 +# If the end time is less than right now, this is probably a mistake +dtn=$(date +%s) +if ((dtn > dtb)) ; then + printf '%s: Refusing to schedule downtime ending in the past (%s)\n' \ + "$self" "$(date -d @"$dtb" +%c)" exit 1 fi +# Quietly replace semicolons in comment with commas +comment=${comment//;/,} + +# Write commands to schedule downtime for each of the objects, bail if a single +# one of them fails +for object in "${objects[@]}" ; do + case $object in + */*) + host=${object%/*} + service=${object##*/} + cmd=$(printf '[%lu] SCHEDULE_SVC_DOWNTIME;%s;%s;%s;%s;%u;%u;%u;%s;%s' \ + "$now" "$host" "$service" "$dta" "$dtb" \ + "$fixed" "$trigger" "$duration" "$author" "$comment") + ;; + *) + host=$object + cmd=$(printf '[%lu] SCHEDULE_HOST_DOWNTIME;%s;%s;%s;%u;%u;%u;%s;%s' \ + "$now" "$host" "$dta" "$dtb" \ + "$fixed" "$trigger" "$duration" "$author" "$comment") + ;; + esac + printf '%s\n' "$cmd" > "$cmdfile" || exit +done diff --git a/nagios-downtime.1 b/nagios-downtime.1 index c4ef614..3581651 100644 --- a/nagios-downtime.1 +++ b/nagios-downtime.1 @@ -7,29 +7,28 @@ -h .br .B nagios-downtime -.I HOSTNAME[/SERVICE] +.I (HOSTNAME[/SERVICE][,HOSTNAME[,SERVICE],...]|-) .I START .I END .I [COMMENT] .SH SYNOPSIS -.B ndt -webhost now 10pm 'Upgrading to latest OS release' +ndt webhost now 10pm 'Upgrading to latest Ubuntu release' .PP -.B ndt -webhost/HTTP now 10pm 'Upgrading Apache HTTPD' -.PP -for hostname in ns{1..3} ; do +ndt webhost/HTTP now 10pm 'Upgrading Apache HTTPD' .br -.B - ndt -"$hostname" 'sunday 3:00am' 'sunday 4:00am' 'Outage for entire DNS system for upgrades' +ndt authns1,authns2,recdns1,recdns2 'sunday 3:00am' 'sunday 4:00am' 'Outage for entire DNS system for upgrades' .br -done +nds abc-example | ndt - 9am 10am 'Power problems at abc-example' .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 +downtime for given hosts or services. +.PP +Multiple hosts or services can be separated by commas, and the special value - +allows hosts or services to be read from stdin. +.PP +The two date fields .I START and .I END @@ -46,8 +45,8 @@ changes. Note that the .I COMMENT parameter is optional. .SH SEE ALSO -nagios-acknowledge(1), nagios-force-check(1) +nagios-acknowledge(1), nagios-data-search(1), nagios-descendent-list(1), +nagios-force-check(1), nagios-notification-switch(1), nagios-problem-list(1), +nagios-unhandled-list(1) .SH AUTHOR Tom Ryder -.PP - diff --git a/nagios-exists b/nagios-exists new file mode 100755 index 0000000..c9e6114 --- /dev/null +++ b/nagios-exists @@ -0,0 +1,79 @@ +#!/usr/bin/env bash + +# +# nagios-exists(1) -- Return an exit status corresponding to whether HOST or +# HOST/SERVICE exists in Nagios. Mostly for use in scripts. +# +# $ nex abc-example-mc-1 +# $ nex webhost/HTTP +# +# Author: Tom Ryder +# Copyright: 2016 +# + +# Name self +self=nagios-exists + +# Usage printing function +usage() { + printf 'USAGE: %s HOST[/SERVICE]\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))" + +# We need exactly one argument remaining +if (($# != 1)) ; then + usage >&2 + exit 1 +fi + +# Define the path to the Livestatus socket +socket=${MK_LIVESTATUS_SOCKET:-/usr/local/nagios/var/rw/live} + +# Which query to run depends on what the argument looks like. +case $1 in + + # If there's a slash in the argument, it's a host/service tuplet. + */*) + host_name=${1%/*} + service_description=${1#*/} + while read -r _ ; do + exit + done < <(unixcat "$socket" < +.PP diff --git a/nagios-force-check b/nagios-force-check index 8c19620..ef12e35 100755 --- a/nagios-force-check +++ b/nagios-force-check @@ -4,10 +4,11 @@ # nagios-force-check(1) -- Force an immediate check of a nominated host or # service. # -# $ nfc [/] +# $ nac [/] +# # # Author: Tom Ryder -# Copyright: 2014 Sanctum +# Copyright: 2016 # # Name self @@ -15,13 +16,17 @@ self=nagios-force-check # Usage printing function usage() { - printf 'USAGE: %s [-n] \n' "$self" + printf 'USAGE: %s (-a | [&2 + exit 1 + +# Bail if -a wasn't selected and there are no arguments +elif ! ((check_all_problems)) && ! (($#)) ; then usage >&2 exit 1 fi @@ -43,35 +53,54 @@ 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##*/} +# Specs are either arguments or all unhandled problems +declare -a specs +if ((check_all_problems)) ; then + while read -r object ; do + specs=("${specs[@]}" "$object") + done < <(nagios-problem-list) else - host=$spec - service= + specs=("$@") 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 +# Iterate through the specs given and run the force recheck command +for spec in "${specs[@]}" ; do -# 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 + # Check the host or service exists + if ! nagios-exists "$spec" ; then + printf '%s: Host/service %s does not seem to exist\n' \ + "$self" "$spec" >&2 + fi + + # If a service name is specified after a slash, figure that out + if [[ $spec == */* ]] ; then + host=${spec%/*} + service=${spec##*/} + else + host=$spec + service= fi -done + # Write command and print message if it fails; succeed silently + declare -a cmds + cmds=() + if [[ $service ]] ; then + cmds=("${cmds[@]}" "$(printf '[%lu] SCHEDULE_SVC_CHECK;%s;%s;%lu' \ + "$now" "$host" "$service" "$now")") + else + cmds=("${cmds[@]}" "$(printf '[%lu] SCHEDULE_HOST_CHECK;%s;%lu' \ + "$now" "$host" "$now")") + cmds=("${cmds[@]}" "$(printf '[%lu] SCHEDULE_HOST_SVC_CHECKS;%s;%lu' \ + "$now" "$host" "$now")") + fi + + # Attempt to write commands 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 +done diff --git a/nagios-force-check.1 b/nagios-force-check.1 index 27d7114..9836247 100644 --- a/nagios-force-check.1 +++ b/nagios-force-check.1 @@ -7,7 +7,10 @@ -h .br .B nagios-force-check -.I HOSTNAME[/SERVICE] +-a +.br +.B nagios-force-check +.I HOSTNAME[/SERVICE] [HOSTNAME[/SERVICE]...] .SH SYNOPSIS .B nfc webhost @@ -26,11 +29,24 @@ done .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. +check of at least one particular host (and all its services) or at least one +particular service. +.P +You can use the +.B -a +switch on its own (with no targets specified) to force checks on all problem +services returned by +.B nagios-problem-list(1) +-- this is equivalent to running something like: +.P +npl | while read -r object ; do +.br + nfc "$object" +.br +done .SH SEE ALSO -nagios-acknowledge(1), nagios-downtime(1) +nagios-acknowledge(1), nagios-data-search(1), nagios-descendent-list(1), +nagios-downtime(1), nagios-notification-switch(1), nagios-problem-list(1), +nagios-unhandled-list(1) .SH AUTHOR Tom Ryder -.PP - diff --git a/nagios-problem-list b/nagios-problem-list new file mode 100755 index 0000000..3927feb --- /dev/null +++ b/nagios-problem-list @@ -0,0 +1,61 @@ +#!/usr/bin/env bash + +# +# nagios-problem-list(1) -- List all the hosts and services in a problem state, +# handled or not +# +# $ npl +# +# Author: Tom Ryder +# Copyright: 2016 +# + +# Name self +self=nagios-problem-list + +# Usage printing function +usage() { + printf 'USAGE: %s [-h]\n' "$self" +} + +# By default we search hosts, not services +services=0 + +# 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))" + +# Any arguments after that are abuse +if (($#)) ; then + usage >&2 + exit 1 +fi + +# Define the path to the Livestatus socket +socket=${MK_LIVESTATUS_SOCKET:-/usr/local/nagios/var/rw/live} + +unixcat "$socket" < diff --git a/nagios-unhandled-list b/nagios-unhandled-list new file mode 100755 index 0000000..d5d97fd --- /dev/null +++ b/nagios-unhandled-list @@ -0,0 +1,65 @@ +#!/usr/bin/env bash + +# +# nagios-unhandled-list(1) -- List all unhandled hosts and services in a +# problem state. +# +# $ npl +# +# Author: Tom Ryder +# Copyright: 2016 +# + +# Name self +self=nagios-unhandled-list + +# Usage printing function +usage() { + printf 'USAGE: %s [-h]\n' "$self" +} + +# By default we search hosts, not services +services=0 + +# 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))" + +# Any arguments after that are abuse +if (($#)) ; then + usage >&2 + exit 1 +fi + +# Define the path to the Livestatus socket +socket=${MK_LIVESTATUS_SOCKET:-/usr/local/nagios/var/rw/live} + +unixcat "$socket" < -- cgit v1.2.3