Different Emails For Different Alerts
Different Emails For Different Alerts
I know where I can set the generic email template for all host and service alerts.
I need to include a custom link based upon the different types of notifications. For instance, let's say I have a notification type A, type B, type C. I want a custom email for each that has a link to a specific web page based upon the host IP macro, but followed with a different link.
Example:
http://192.168.1.1/typeA.html
http://192.168.1.1/typeB.html
http://192.168.1.1/typeC.html
Where 192.168.1.1 is generated from $HOSTADDRESS$.
I need to include a custom link based upon the different types of notifications. For instance, let's say I have a notification type A, type B, type C. I want a custom email for each that has a link to a specific web page based upon the host IP macro, but followed with a different link.
Example:
http://192.168.1.1/typeA.html
http://192.168.1.1/typeB.html
http://192.168.1.1/typeC.html
Where 192.168.1.1 is generated from $HOSTADDRESS$.
-
slansing
- Posts: 7698
- Joined: Mon Apr 23, 2012 4:28 pm
- Location: Travelling through time and space...
Re: Different Emails For Different Alerts
Hmm, this will take some looking into. That could be done at a base level by creating more notification handler commands and assigning them to different contacts based on what notification type they should be receiving.
Re: Different Emails For Different Alerts
I would clone notify-service-by-email to a new handler, like notify-custom-service-by-email and make it call a script with all the macros as arguments. In the script, just put the logic to include the URL you want based on the value of one of those macros, depending on what you need. I've done this with Nagios core so I could have more control and flexibility with notifications.
- Kyle
Re: Different Emails For Different Alerts
Thanks, hhlodge!
@jbennett
Let us know if this worked out for you.
@jbennett
Let us know if this worked out for you.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: Different Emails For Different Alerts
I'm not sure I follow 100%. When you say to make it call a script, this is where I'm lost.hhlodge wrote:I would clone notify-service-by-email to a new handler, like notify-custom-service-by-email and make it call a script with all the macros as arguments. In the script, just put the logic to include the URL you want based on the value of one of those macros, depending on what you need. I've done this with Nagios core so I could have more control and flexibility with notifications.
As it is now, my notify-service-by-email command is as follows:
Code: Select all
/usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ Code: Select all
usr/bin/php /usr/local/nagiosxi/scripts/handle_nagioscore_notification.php --notification-type=service --contact="$CONTACTNAME$" --contactemail="$CONTACTEMAIL$" --type=$NOTIFICATIONTYPE$ --escalated="$NOTIFICATIONISESCALATED$" --author="$NOTIFICATIONAUTHOR$" --comments="$NOTIFICATIONCOMMENT$" --host="$HOSTNAME$" --hostaddress="$HOSTADDRESS$" --hostalias="$HOSTALIAS$" --hostdisplayname="$HOSTDISPLAYNAME$" --service="$SERVICEDESC$" --hoststate=$HOSTSTATE$ --hoststateid=$HOSTSTATEID$ --servicestate=$SERVICESTATE$ --servicestateid=$SERVICESTATEID$ --lastservicestate=$LASTSERVICESTATE$ --lastservicestateid=$LASTSERVICESTATEID$ --servicestatetype=$SERVICESTATETYPE$ --currentattempt=$SERVICEATTEMPT$ --maxattempts=$MAXSERVICEATTEMPTS$ --serviceeventid=$SERVICEEVENTID$ --serviceproblemid=$SERVICEPROBLEMID$ --serviceoutput="$SERVICEOUTPUT$" --longserviceoutput="$LONGSERVICEOUTPUT$" --datetime="$LONGDATETIME$"Or, do I create it more like the xi_service_notification_handler command and add in my needed argument as such?
Code: Select all
--veslink="http://$HOSTADDRESS$/mainmenu.html"
Re: Different Emails For Different Alerts
Make your new notification command something like this.
Then in notifications.ksh, something along these lines.
Just make sure you pass all the macros you want as arguments to the script and set a variable for them and then use the variables you set with the normal $VAL constuct, i.e. no trailing $ as in the macros. I hope this makes sense.
Code: Select all
/usr/local/bin/notifications.ksh $NOTIFICATIONTYPE$ $SERVICEDESC$ $HOSTALIAS$ $HOSTADDRESS$ $SERVICESTATE$ $LONGDATETIME$ $CONTACTEMAIL$ .... etc. ... Code: Select all
#!/bin/ksh
NOTIFICATIONTYPE=$1
SERVICEDESC=$2
HOSTALIAS=$3
....
case $NOTIFICATIONTYPE in
PROBLEM)
URL=http://192.168.1.1/typeA.html
;;
RECOVERY)
URL=http://192.168.1.1/typeB.html
;;
ACKNOWLEDGEMENT)
URL=http://192.168.1.1/typeC.html
;;
*)
URL=http://whatever
;;
esac
/usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE\n\nService: $SERVICEDESC\nHost: $HOSTALIAS\nAddress: $HOSTADDRESS\nState: $SERVICESTATE\nURL: $URL ..... " | /bin/mail -s "** $NOTIFICATIONTYPE Service Alert: $HOSTALIAS/$SERVICEDESC is $SERVICESTATE **" $CONTACTEMAIL
- Kyle
Re: Different Emails For Different Alerts
I have found the bash references below to be extremely helpful for those new to bash scripting:
http://www.tldp.org/LDP/abs/html/
http://www.tldp.org/LDP/Bash-Beginners-Guide/html/
Happy scripting!
http://www.tldp.org/LDP/abs/html/
http://www.tldp.org/LDP/Bash-Beginners-Guide/html/
Happy scripting!
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.
"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.
Re: Different Emails For Different Alerts
Thanks for the help, but I don't think the above will do what I'm looking for. I'm not looking to get a different email for an problem/recovery/acknowledgement.
I have service checks that range from checking processes on boxes, to checking the state of hardware as reported back through the software.
Some of these checks are checking cameras. We have developed a page that is specific to these cameras. Since cameras are tied to certain boxes, the IP of hte box is the web address, followed by ":8080/mainmenu.html".
As it is set-up now, I have a generic link in the main notifications email as follows: http://%hostaddress%:8080/mainmenu.html
This link is only valid for camera issues. The information that is reported on this page is specific to the cameras. Since that link is included in the standard notification template, it is generating the link for service messages that aren't related to camera issues.
I was hoping to create a template to apply to only the services that concern camera issues and thus have notification emails for the cameras be the only ones to contain this link.
Since we will be generating pages for the other issues as well (in the future, but not currently) having a generic link in the notification template makes sense.
I was looking at the misc settings tab under the service template management and it seems that I can call these fields with a macro.
My thought was to create a service template with all of the settings I need, then include the :8080/mainmenu.html portion of the link in the notes field here.
Then, under the notification management templates, I would include a link as follows:
Is there any reason this wouldn't work?
It also seems that when I make changes to these notification templates and select all of the users and usergroups to apply it, my notifications stop. I managed to get them working once, but I'm not sure what I did. Does a process stop that's having trouble restarting perhaps?
I have service checks that range from checking processes on boxes, to checking the state of hardware as reported back through the software.
Some of these checks are checking cameras. We have developed a page that is specific to these cameras. Since cameras are tied to certain boxes, the IP of hte box is the web address, followed by ":8080/mainmenu.html".
As it is set-up now, I have a generic link in the main notifications email as follows: http://%hostaddress%:8080/mainmenu.html
This link is only valid for camera issues. The information that is reported on this page is specific to the cameras. Since that link is included in the standard notification template, it is generating the link for service messages that aren't related to camera issues.
I was hoping to create a template to apply to only the services that concern camera issues and thus have notification emails for the cameras be the only ones to contain this link.
Since we will be generating pages for the other issues as well (in the future, but not currently) having a generic link in the notification template makes sense.
I was looking at the misc settings tab under the service template management and it seems that I can call these fields with a macro.
My thought was to create a service template with all of the settings I need, then include the :8080/mainmenu.html portion of the link in the notes field here.
Then, under the notification management templates, I would include a link as follows:
Code: Select all
http://%hostaddress%%servicenotes%It also seems that when I make changes to these notification templates and select all of the users and usergroups to apply it, my notifications stop. I managed to get them working once, but I'm not sure what I did. Does a process stop that's having trouble restarting perhaps?
Re: Different Emails For Different Alerts
A few comments:
This will only work for services, as you include the %servicenotes% macro, it you try to use this template with hosts, it will break.
In order to use the templates for contacts, those contacts need to be originally configured as XI users.
If you can test this without breaking notifications in production, please do so. Once the new notification is enabled on a user, force a notification to get sent and then check the maillogs:
In order to test it correctly, you most likely need to submit a passive critical check for a service that the user is a contact of.
This will only work for services, as you include the %servicenotes% macro, it you try to use this template with hosts, it will break.
In order to use the templates for contacts, those contacts need to be originally configured as XI users.
If you can test this without breaking notifications in production, please do so. Once the new notification is enabled on a user, force a notification to get sent and then check the maillogs:
Code: Select all
tail -25 /var/log/maillogFormer 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.
"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.
Re: Different Emails For Different Alerts
That's perfect since I only want to use it for services anyways!abrist wrote:This will only work for services, as you include the %servicenotes% macro, it you try to use this template with hosts, it will break.
I'm trying to get away with not doing this via the contacts template.In order to use the templates for contacts, those contacts need to be originally configured as XI users.
I'm wondering if it's possible to do this by using the macros that Nagios has built in instead (as this would be the most simple way of having custom notifications for different services).
In the notification template under Admin -> Notification Management -> Email Notifications, I would be able to just include the macros to call the host address and the notes field (Service Management -> Misc Settings) from the service as follows: http://%hostaddress%%servicenotes%
The notes field on the services in question would be like this: :8080/mainmenu.html
Other services might be like this: :8080/vesmenu.html
Again, the Notes field link to depend on teh type of service (camera, router, etc).
This way, when we get the email, the link that is generated will take you directly to that device page that we have created.
I think you're still trying to help me with the method that hhlodge suggested, which isn't what I'm trying to do in this instance.