Nagios map setting issue 4.3.2

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.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Nagios map setting issue 4.3.2

Post 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$
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
jagannathan
Posts: 26
Joined: Sat Jun 16, 2018 7:21 am

Re: Nagios map setting issue 4.3.2

Post by jagannathan »

scottwilkerson wrote :

-> How to create your own custom notification script ,is there any links means please forward those links.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Nagios map setting issue 4.3.2

Post 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/
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
jagannathan
Posts: 26
Joined: Sat Jun 16, 2018 7:21 am

Re: Nagios map setting issue 4.3.2

Post 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 .
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Nagios map setting issue 4.3.2

Post 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$"
   }
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked