Page 1 of 1

Modifying HOSTADDRESS IP addresses in notifications

Posted: Fri Sep 26, 2014 9:35 am
by bgodfrey
At our customer's site there is a requirement to show only partial IP addresses for their hosts in all unencrypted email messages, including Nagios notifications.

To comply with that, we modified the definitions of "notify-host-by-email" and "notify-service-by-email" in commands.cfg, inserting a "sed" command in front of the "/bin/mail" command. The particular "sed" command we used will change the first 2 octets to "xxx.xxx".

So in place of this part of the definition:

/bin/mail

we have

sed -e 's/ 192\.168\./ xxx.xxx./' | /bin/mail

although I only use 192.168 here to illustrate the example. Our octets are different.

A more generic way to replace any values in the first 2 octets with x would be like this:

sed -e 's/ [0-9]*\.[0-9]*\.\([0-9]*\.[0-9]* \)/x.x.\1/' | /bin/mail

This can be tested as follows:

echo " 127.0.0.1 " | sed -e 's/ [0-9]*\.[0-9]*\.\([0-9]*\.[0-9]* \)/ x.x.\1/'

x.x.0.1

If someone has accomplished this another way, I would be interested to know how.

We could have eliminated the IP address entirely with a simpler change, by removing $HOSTADDRESS, but the partial IP address is useful to have.

-Bill

Re: Modifying HOSTADDRESS IP addresses in notifications

Posted: Fri Sep 26, 2014 9:49 am
by tmcdonald
I've always liked the idea of doing a replacement on the IP address so it stays consistent for troubleshooting but is not revealing anything. So "192.168.1.5" might become "AIB.AFH.A.E", of course not using a simple substitution like that. I don't yet have any code for this but I've been working over it in my head for a few weeks.

Re: Modifying HOSTADDRESS IP addresses in notifications

Posted: Fri Sep 26, 2014 12:58 pm
by Box293
An alternative method is to store the first two octets as a free variable in the host definition. Then you can use the $_HOSTMACRONAME$ in your notification commands.

Of course that adds the complexity of ensuring your host objects ALWAYS have this free variable defined.

http://nagios.sourceforge.net/docs/3_0/ ... tvars.html