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
Modifying HOSTADDRESS IP addresses in notifications
Re: Modifying HOSTADDRESS IP addresses in notifications
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.
Former Nagios employee
- Box293
- Too Basu
- Posts: 5126
- Joined: Sun Feb 07, 2010 10:55 pm
- Location: Deniliquin, Australia
- Contact:
Re: Modifying HOSTADDRESS IP addresses in notifications
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
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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.