Page 1 of 1

Macro for server name?

Posted: Fri Aug 01, 2014 10:12 am
by thewinelake
Is there a macro that I can use to give me the hostname of the nagios server itself?

I want this as we may have several nagios servers, and when they send an SMS, I'd like to know which one is sending it.

Of course I could manually put it into the command, but would be nice if it were simpler.

Re: Macro for server name?

Posted: Fri Aug 01, 2014 10:40 am
by eloyd
Nope. No such thing in the docs or the source.

I would think if you're sending an SMS, then you would want to make each character count, so I don't know why you want the hostname in there, but you can always add it in the printf command within commands.cfg. Here's one idea. Note the `/bin/hostname` in the middle of the printf:

Code: Select all

define command{
        command_name    notify-service-by-sms
        command_line    /usr/bin/printf "%b" "$NOTIFICATIONTYPE$ - `/bin/hostname`: $SERVICEDESC$ ($HOSTNAME$) $SERVICESTATE$ - $SERVICEOUTPUT$\n" | $USER1$/send_sms 2>/dev/null
}

Re: Macro for server name?

Posted: Fri Aug 01, 2014 10:54 am
by thewinelake
Thanks - an interesting idea! However, in the end I just decided to rewrite the sender.

BTW, the hostname doesn't actually take any valuable SMS real-estate, as I'm putting it as the sender ID