Distinguish critical alerts and warning with colors

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
kalyanivalaboju
Posts: 5
Joined: Thu Jan 02, 2020 4:30 am

Distinguish critical alerts and warning with colors

Post by kalyanivalaboju »

Hi Team,

Do we have any mechanism to have email notification highlighted in different colors for critical alerts to distinguish.
Kindly help.

Regards,
Kalyani
User avatar
tacolover101
Posts: 432
Joined: Mon Apr 10, 2017 11:55 am

Re: Distinguish critical alerts and warning with colors

Post by tacolover101 »

yes, but it would require you to set it up. there's a bit of work needed for this. i can provide you a skeleton to use to build it out.

1. setup a new host notification command to tell nagios to use your custom command (look at notify-host-by-email for reference)
2. rewrite the command to evaluate $HOSTSTATE$ (or $SERVICESTATE$ if a service), here is an example of what it's likely set to:

Code: Select all

/usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
3. once you evaluate, and have your different logic set for the different states, add the html to each.
example:

Code: Select all

<font color="red">AUSTRALIA IS ON FIRE</font>
another option would be to evaluate a variable such as $fontcolor, and change that based on what the variable $HOSTSTATE$ equals to, then use this:

Code: Select all

if [ $HOSTSTATE$ = "critical" ] then
fontcolor=red
else
##placeholder for additional logic
fi
then modify your mailing command to use the variable:

Code: Select all

<font color="$fontcolor">AUSTRALIA IS ON FIRE</font>
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Distinguish critical alerts and warning with colors

Post by scottwilkerson »

Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
kalyanivalaboju
Posts: 5
Joined: Thu Jan 02, 2020 4:30 am

Re: Distinguish critical alerts and warning with colors

Post by kalyanivalaboju »

Hi,

Thanks for the response.
Can i get step by step document as i am new to this.

Regards,
Kalyani.V
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Distinguish critical alerts and warning with colors

Post by scottwilkerson »

We don't have a step by step guide because yo are asking for something that isn't done out of the box.

The only guidance we could give as an example @tacolover101 already gave
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked