Page 4 of 4

Re: Nagios map setting issue 4.3.2

Posted: Thu Jun 28, 2018 9:00 am
by scottwilkerson
The only way to have it both ways is to create your own custom notification script, and then change the message based on the value of $NOTIFICATIONTYPE$

Re: Nagios map setting issue 4.3.2

Posted: Fri Jun 29, 2018 9:16 am
by jagannathan
scottwilkerson wrote :

-> How to create your own custom notification script ,is there any links means please forward those links.

Re: Nagios map setting issue 4.3.2

Posted: Fri Jun 29, 2018 9:34 am
by scottwilkerson
You would write it is any programming language you choose, and pass the macros as arguments just like the current commands previously defined.. Unfortunately I cannot show you how to write the script

Code: Select all

# 'notify-host-by-email' command definition
define command{
   command_name   notify-host-by-email
   command_line   /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\nComment: $NOTIFICATIONCOMMENT$ \n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
   }

# 'notify-service-by-email' command definition
define command{
   command_name   notify-service-by-email
   command_line   /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 Comment : $NOTIFICATIONCOMMENT$ \n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ } 
Much of this is way easier in Nagios XI and is configurable through the GUI, you may want to take that for a 60 day free trial
https://www.nagios.com/products/nagios-xi/

Re: Nagios map setting issue 4.3.2

Posted: Mon Jul 02, 2018 7:30 am
by jagannathan
scottwilkerson wrote >>

-> I know commands.cfg file how to add the parameter.

-> Pass the macros as arguments just like the current commands previously defined.. Unfortunately I cannot show you how to write the script ?

-> please show some example how to write the script and psssing the macros as an argument .

Re: Nagios map setting issue 4.3.2

Posted: Mon Jul 02, 2018 11:08 am
by scottwilkerson
Script your-handler.sh

Code: Select all

#!/bin/bash

message=$(cat)

# your logic here to manipulate the message

echo $message | /usr/bin/mail -s "** $1 Host Alert: $2 is $3 **" $4
then add new notification handler

Code: Select all

# 'your-custom-host-handler' command definition
define command{
   command_name   your-custom-host-handler
   command_line   /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\nComment: $NOTIFICATIONCOMMENT$ \n" | your-handler.sh "$NOTIFICATIONTYPE$" "$HOSTNAME$" "$HOSTSTATE$" "$CONTACTEMAIL$"
   }