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. --- nagios-exists | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100755 nagios-exists (limited to 'nagios-exists') 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" <