Need customization in email

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
yunushaikh
Posts: 176
Joined: Sat Jun 20, 2015 9:04 pm

Need customization in email

Post 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.
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: Need customization in email

Post 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
yunushaikh
Posts: 176
Joined: Sat Jun 20, 2015 9:04 pm

Re: Need customization in email

Post by yunushaikh »

I will check and let you know sir

Thanks for you quick help
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Need customization in email

Post by abrist »

Great, let us know how it works for you.
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
yunushaikh
Posts: 176
Joined: Sat Jun 20, 2015 9:04 pm

Re: Need customization in email

Post by yunushaikh »

Hello Sir this is working.

Thanks for your great help.
Locked