Modifying HOSTADDRESS IP addresses in notifications
Posted: Fri Sep 26, 2014 9:35 am
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
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