host object declarations

Marki jm+nagios-users at roth.lu
Tue Oct 2 17:20:59 CEST 2012


> The only thing I'm saying in that bugreport is
> that Nagios does not and will not complain when the "address" fields of
> hosts are unique.

In fact you also said:

> that suggests that either your namestandard (used for the host_name field)
> sucks, or that you or your co-workers are simply confused when it comes
> to configuring Nagios.

So let's talk best practices.

In practice it did occur that when someone copy/pasted a bunch of service
definitions (yeah I know you should use templates, call that confusion if
you like) just forgot to update the address field and the newly created checks
(or so they believed) did nothing more than check the old stuff once more.

According to what you suggest, it is wisest to indeed use DNS names where you
can in the host_name field. (and only use the address field in special
circumstances) (in Nagios4)

If you define your nomenclature like that, possible confusion may be
eliminated ;-)

BTW I have all sorts things in place that
- check for duplicate addresses
- check for syntax errors all over the place
- check if the plugin specified in command_line actually exists thus preventing
stupid error 127 or alike
If anyone finds that interesting, see below.

bye,
Marki

PS. As a sidenote: I once created a more or less functional version of a script
allowing to change service names. It's not trivial but can be done.
Does anyone know of something existing and working that allows to change
service and also hostnames?





for f in $(grep command_line $NAGIOS/etc/checkcommands.cfg | awk '{print $2}' |\
grep USER1 | sed 's/\$USER1\$\///'); do
    if [ ! -f $NAGIOS/libexec/$f ]; then
        echo "[KO] $f does not exist"
        ERR=$(($ERR + 1))
    fi
done
[ "$ERR" -eq 0 ] && echo "[OK] all commands seem to exist"

# make sure to always update both statements!
if [ "$(grep -r address $NAGIOS/etc/hosts* | grep -v '~' | grep -v svn |\
grep -v '.bak' | cut -d: -f2 | tr -d ' \t' | awk -F'address' '{print $2}' |\
sort | uniq -c | sort -n | grep -v ' 1 ' | wc -l)" -ne 0 ]; then
    echo "[INFO] IP address defined more than once:"
    grep -r address $NAGIOS/etc/hosts* | grep -v '~' | grep -v svn |\
    grep -v '.bak' | cut -d: -f2 | tr -d ' \t' |\
    awk -F'address' '{print $2}' | sort | uniq -c | sort -n | grep -v ' 1 '
else
    echo "[OK] Dup IP check ok"
fi

# syntax check - bash scripts
OK=1
echo Please wait...
for i in $(find $NAGIOS/libexec -type f | grep -v '~'); do
    echo $i | grep -q '/.svn/' && continue
    if [[ "$i" =~ '\.sh' ]] || [ "$(head -1 $i)" = '#!/bin/bash' ]; then
        if ! sh -n $i; then
            OK=0
            echo "[KO] bash syntax error - $i"
        fi
    fi
    if [[ "$i" =~ '\.pl' ]] || [ "$(head -1 $i)" = '#!/usr/bin/perl' ]; then
        if ! perl -wc $i; then
            OK=0
            echo "[KO] perl syntax error - $i"
        fi
    fi
    if [[ "$i" =~ '\.php' ]]; then
        if ! php -l $i &>/dev/null; then
            OK=0
            echo "[KO] PHP syntax error - $i"
        fi
    fi
done
[ "$OK" -eq "1" ] && echo "[OK] shell scripts - syntax checks ok"

# check command syntax
TMP=/tmp/$(basename $0).$$
grep command_line $NAGIOS/etc/misccommands.cfg $NAGIOS/etc/checkcommands.cfg |\
sed 's/command_line//' > $TMP
sh -n $TMP
RET=$?
if [ "$RET" -eq 0 ]; then
        echo "[OK] command scripts - syntax checks ok"
else
        echo "[KO] command scripts - error $RET"
fi
rm $TMP






------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list