#! /bin/sh # # Skript zum Kontrollieren der NagVis Mappen ob diese Objekte im Monitoring noch existieren: # - Hosts # - Hostgruppen # - NagVis Mappen # - Services # # Version: 1.0.0 # # Author: 2025/09/30 Juergen Vigna # # Changed: # export TERM=xterm TMPFILE=$(mktemp) OUTFILE=$(mktemp) MTMPFILE=$(mktemp) HTMPFILE=$(mktemp) HGTMPFILE=$(mktemp) STMPFILE=$(mktemp) CLICMD="/usr/bin/icingacli" MAPDIR="/neteye/shared/nagvis/conf/maps" trap 'rm -f $TMPFILE $OUTFILE $MTMPFILE $HTMPFILE $HGTMPFILE $STMPFILE; exit 1' 1 2 15 trap 'rm -f $TMPFILE $OUTFILE $MTMPFILE $HTMPFILE $HGTMPFILE $STMPFILE' 0 ls -1 $MAPDIR/*.cfg >$MTMPFILE ${CLICMD} monitoring list hosts | awk '{print $2}' | sed -e 's/:$//g' >$HTMPFILE ${CLICMD} director hostgroups list >$HGTMPFILE ${CLICMD} monitoring list services --format json | jq -r '.[] | .host_name + ";" + .service_description' >$STMPFILE i=0 while read mapfile do MAP=$(basename $mapfile) if echo "$MAP" | grep '^Vorlage' >/dev/null then continue fi OUNKNOWN="" # # First check host objects # for o in $(grep -e "^host_name" $mapfile | cut -d= -f2 | cut -d# -f1 | tr -d '\r' | tr ' ' '#' ) do o=${o//#/ } if ! egrep "^$o\$" $HTMPFILE >/dev/null then OUNKNOWN="$OUNKNOWN,HOST:$o" fi done # # Second check hostgroup objects # for o in $(grep -e "^hostgroup_name" $mapfile | cut -d= -f2 | cut -d# -f1 | tr -d '\r' | tr ' ' '#' ) do o=${o//#/ } if ! egrep "^$o\$" $HGTMPFILE >/dev/null then OUNKNOWN="$OUNKNOWN,HOSTGROUP:$o" fi done # # Third check map objects # for o in $(grep -e "^map_name" $mapfile | cut -d= -f2 | cut -d# -f1 | tr -d '\r' | tr ' ' '#' ) do o=${o//#/ } if ! egrep "/${o}.cfg" $MTMPFILE >/dev/null then OUNKNOWN="$OUNKNOWN,MAP:${o}.cfg" fi done # # Fourth check service objects # grep -B 1 "^service_description" $mapfile | grep -v '^--' | sed 'N;/\nservice_description/s/\n/;/;P;D' | sed -e 's/host_name=//g' -e 's/service_description=//g' >$TMPFILE while read o do if ! egrep "${o}" $STMPFILE >/dev/null then OUNKNOWN="$OUNKNOWN,SERVICE:${o}" fi done < $TMPFILE if [ -n "$OUNKNOWN" ] then OUNKNOWN=$(echo "$OUNKNOWN" | cut -c 2-) echo "ERROR - $MAP - Missing Objects: $OUNKNOWN" >> $OUTFILE fi done < $MTMPFILE if [ -s $OUTFILE ] then echo "CRITICAL - Missing objects in NagVis Mapfiles" cat $OUTFILE exit 2 fi echo "OK - No missing objects in NagVis Mapfiles" exit 0