diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-06-20 13:08:15 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-06-20 13:08:15 +1200 |
commit | cdc34fa78b326bd241aae7399190c739e25bf025 (patch) | |
tree | 2d12fdf161b74dcde13baf33bb46f0137f443952 /nagios-downstream-list | |
parent | Remove silly symlinks (diff) | |
download | nagscripts-3023a404a59a8ec51e9ebe0b5fea3a4f9f8ddf0c.tar.gz nagscripts-3023a404a59a8ec51e9ebe0b5fea3a4f9f8ddf0c.zip |
Update to latest version with MKLivestatusmk-livestatus
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.
Diffstat (limited to 'nagios-downstream-list')
-rwxr-xr-x | nagios-downstream-list | 62 |
1 files changed, 62 insertions, 0 deletions
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 <tom@sanctum.geek.nz> +# 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" <<EOF +GET hosts +Columns: host_name +Filter: parents >= $ancestor +EOF + ) + done | sort -uV +} + +# Run the recursive function on all the arguments given to this script +descendents "$@" |