Nagios Core - Nagios URL In Notifications


Overview

This KB article shows you how to provide a URL for the Nagios host or service object in your notifications. This allows your end users to go directly to the object they are being notified about.

This functionality was introduced in Nagios Core 4.3.3.

 

Editing Files

In many steps of this article you will be required to edit files. This documentation will use the vi text editor. When using the vi editor:

 

Nagios Configuration

There is a configuration directive called website_url that needs to be defined in nagios.cfg before you can use the URL in your notifications.

Execute the following command to open the nagios.cfg file in vi:

vi /usr/local/nagios/etc/nagios.cfg

 

Add the following line to the file:

website_url=http://xxx.xxx.xxx.xxx/nagios

Change xxx.xxx.xxx.xxx to the IP Address or DNS record of your Nagios Core server, for example:

website_url=http://core-015/nagios

 

Save your changes and close the nagios.cfg file.

 

The next step is to update your host and service notification commands to use the relevant macros. In this example these are defined in the commands.cfg file. Execute the following command to open the file in vi:

vi /usr/local/nagios/etc/objects/commands.cfg

 

For the host notification command you use the $HOSTINFOURL$ as per the following example:

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

 

For the service notification command you use the $SERVICEINFOURL$ as per the following example:

define command{
        command_name    notify-service-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\n
Host: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n
Service Info URL: $SERVICEINFOURL$\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$
Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
        }

 

Save your changes and close the commands.cfg file.

 

Restart the nagios service for these changes to take effect. If you are unsure of the command required for restarting the nagios service please refer to the following KB article:

Nagios Core - Installing Nagios Core From Source

 

Example Notifications

When a notification is now sent there will be a link available for that object in Nagios Core, here are two examples:

Host

***** Nagios *****

Notification Type: CUSTOM
Host: localhost
State: UP
Address: 127.0.0.1
Info: PING OK - Packet loss = 0%, RTA = 0.04 ms

Date/Time: Mon Oct 23 12:58:34 AEDT 2017
Host Info URL: http://core-015/nagios/cgi-bin/extinfo.cgi?type=1&host=localhost

 

Service

***** Nagios *****

Notification Type: CUSTOM

Service: PING
Host: localhost
Address: 127.0.0.1
State: OK

Date/Time: Mon Oct 23 12:58:53 AEDT 2017
Service Info URL: http://core-015/nagios/cgi-bin/extinfo.cgi?type=2&host=localhost&service=PING
Additional Info:

PING OK - Packet loss = 0%, RTA = 0.05 ms

 

 

Final Thoughts

For any support related questions please visit the Nagios Support Forums at:

http://support.nagios.com/forum/



Article ID: 765
Created On: Sun, Oct 22, 2017 at 10:24 PM
Last Updated On: Sun, Oct 22, 2017 at 10:35 PM
Authored by: tlea

Online URL: https://support.nagios.com/kb/article/nagios-core-nagios-url-in-notifications-765.html