Nagios map setting issue 4.3.2
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Nagios map setting issue 4.3.2
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$
-
- Posts: 26
- Joined: Sat Jun 16, 2018 7:21 am
Re: Nagios map setting issue 4.3.2
scottwilkerson wrote :
-> How to create your own custom notification script ,is there any links means please forward those links.
-> How to create your own custom notification script ,is there any links means please forward those links.
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Nagios map setting issue 4.3.2
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
https://www.nagios.com/products/nagios-xi/
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 trialCode: 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$ }
https://www.nagios.com/products/nagios-xi/
-
- Posts: 26
- Joined: Sat Jun 16, 2018 7:21 am
Re: Nagios map setting issue 4.3.2
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 .
-> 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 .
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Nagios map setting issue 4.3.2
Script your-handler.sh
then add new notification handler
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
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$"
}