Page 1 of 1

Need customization in email

Posted: Tue Jul 07, 2015 3:16 pm
by yunushaikh
Hello Experts,

I need to do some customization in email alerts which I get from Nagios. For example, I dont need hostname and IP address mentioned in the email as it is not secure.
Last 2 octets of IP addresses will do but not the whole IP address.

Email is sent by nagios@hostname. I want some other email id to send an email from Nagios.
Is this possible anyways.

Below is the example content of the email:

***** Nagios *****

Notification Type: PROBLEM

Service: MySQL Replication 5951
Host: localhost
Address: 192.168.0.1
State: CRITICAL

Date/Time: Tue Jul 7 14:50:18 CDT 2015

Additional Info:

CRIT Slave_IO_Running: No Slave_SQL_Running: No Last_Error:

--------------------------------------------------------------------------------------------------------------------------------------

Instead of Address I need just X.X.0.1 or the last 2 octets will also do. and email should be sent by any other email id. Please suggest any ideas.

Re: Need customization in email

Posted: Tue Jul 07, 2015 4:00 pm
by jdalrymple
This is the default service notification command:


Code: Select all

/usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
You can just omit $HOSTALIAS$
You can run a cut on $HOSTADDRESS$ - something like `cut -d '.' -f 3-`
You can add -r to your mail command for the from address

Result:

Code: Select all

/usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nAddress: `echo $HOSTADDRESS$ | cut -d '.' -f 3-`\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -r [email protected] $CONTACTEMAIL$
cutting $HOSTADDRESS$ may not work if you use DNS names at all... YMMV

Re: Need customization in email

Posted: Tue Jul 07, 2015 4:25 pm
by yunushaikh
I will check and let you know sir

Thanks for you quick help

Re: Need customization in email

Posted: Wed Jul 08, 2015 10:56 am
by abrist
Great, let us know how it works for you.

Re: Need customization in email

Posted: Wed Jul 08, 2015 3:57 pm
by yunushaikh
Hello Sir this is working.

Thanks for your great help.