Need URL in the email alert

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
cesar.garza
Posts: 80
Joined: Mon Aug 19, 2013 3:14 pm

Need URL in the email alert

Post by cesar.garza »

Hey Gurus,
I need a small help to figure it out that how can i setup a nagios individual service URL in the email notification. Right now i am getting email alert with XXXX information but i need the email notification with the URL that take you straight to nagios service information page.
Thanks

Code: Select all

# '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" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
        }
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Need URL in the email alert

Post by abrist »

You will have to include the url with the macros in your message body:

Code: Select all

http://<nagios server ip>/nagios/cgi-bin/extinfo.cgi?type=2&host=$HOSTNAME$&service=$SERVICEDESC$
Obviously change <nagios server ip> to your server's ip.
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.
cesar.garza
Posts: 80
Joined: Mon Aug 19, 2013 3:14 pm

Re: Need URL in the email alert

Post by cesar.garza »

Thanks abrist for your reply, but i am pretty new in nagios world so quite slow to understand. The suggestion you gave me, where i need to add that. my configuration is something like that... and do i also need to add anything in the (notification of email) too ?..

Service.cfg

Code: Select all

define service {
        hostgroup_name                  api,EPP,generic-api,generic-svc,PCE,sam
        service_description             Disk Space
        check_command                   check_nrpe_disk_windows
        use                             generic-service
        notification_interval           0
        }
command.cfg

Code: Select all

define command{
        command_name check_nrpe_disk_windows
        command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c alias_disk -a 20% 10%
        }
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Need URL in the email alert

Post by scottwilkerson »

You would need to add it to the notify-service-by-email command definition (which creates the email)
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Need URL in the email alert

Post by abrist »

Edit you service command:

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$\n\nRapid Response:\n$$(echo "http://<nagios server ip>/nagios/cgi-bin/extinfo.cgi?type=2&host=$HOSTNAME$&service=$SERVICEDESC$" | sed 's/ /%20/g')" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
A little explanation of the addition:

Code: Select all

$$(echo "http://<nagios server ip>/nagios/cgi-bin/extinfo.cgi?type=2&host=$HOSTNAME$&service=$SERVICEDESC$" | sed 's/ /%20/g')
Two $$ because we need to escape the $ used for nagios macros.
The reason to echo the url through sed is so that we can replace any spaces in the url (spaces in the service or hostname) with the url encoded %20. This code should add a link to the bottom of your email. Make sure to replace <nagios server ip> with your server's actual ip and to change http to https if needed (like if you force https through rewrite rules).

EDIT: The sed above only url encodes spaces. If your object names have any other characters that need to be url encoded, you will need to extend the sed logic to compensate for them.
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.
cesar.garza
Posts: 80
Joined: Mon Aug 19, 2013 3:14 pm

Re: Need URL in the email alert

Post by cesar.garza »

I edited """notify-service-by-email""" but it is coming as BLANK. I have attached the screenshot.
Attachments
command.cfg
command.cfg
Email
Email
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Need URL in the email alert

Post by abrist »

Try running it from the cli. It will have a bunch of $ in the fields, but we should see the url in the email. Replace <your email> with your address and try running this monster one liner from the cli::

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$\n\nRapid Response:\n$$(echo "http://10.5.56.62/nagios/cgi-bin/extinfo.cgi?type=2&host=$HOSTNAME$&service=$SERVICEDESC$" | sed 's/ /%20/g')" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" <your email>
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.
cesar.garza
Posts: 80
Joined: Mon Aug 19, 2013 3:14 pm

Re: Need URL in the email alert

Post by cesar.garza »

Thanks for your help. It worked out.
Locked