Many users use Nagios to monitor a broad range of network services over protocols that include SMTP and POP3 (email), HTTP (web), ICMP (ping), and SSH.
In addition to simple uptime monitoring, Nagios also contains features for advanced notification and graphing as well as an extensible plugin architecture that allows users to develop simple plugins for accessing unique monitoring information and providing customized reports.
Before beginning this document, we assume that you have followed our getting started guide and LAMP Guide to achieve a fully functional LAMP stack on your Linode. If you're new to Linux system administration, you may also want to consider the administration basics article in our using linux series.
These instructions work with the Linode platform. If you don't have a Linode yet, sign up for a Linux VPS and get started today.
Prepare for Nagios Installation.
Ensure that your system's package repository and installed packages are up to date by issuing the following commands:
Before we can begin installing Nagios, we must first install several prerequisites. Issue the following command:
Create Users and Groups.
Create a new system user account to run Nagios under. Issue the following commands:
Now we're ready to continue with the installation of Nagios itself.
Download Nagios Software.
Begin by downloading the latest version of the Nagios Core. At the time of writing the latest version of Nagios is 3.2.1, but be sure that you are downloading the latest version by checking the Nagios download page. Issue the following command:
Next, download the official plugin package for Nagios. At the time of writing this is version 1.4.14, but check the Nagios plugin download page to ensure that this remains the latest version. Issue the following commands:
Build and Install Nagios Core.
Issue the following command to extract, compile and install the Nagios Core software:
Configure Nagios Core.
Begin by editing the /usr/local/nagios/etc/objects/contacts.cfg file's email field, according to the example below:
File excerpt: /usr/local/nagios/etc/objects/contacts.cfg
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias John Doe ; Full name of user
email email@example.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ****** } Issue the following commands to configure the web interface for Nagios:
Now issue the following command to create a password for the nagiosadmin user.
To learn more about HTTP Authentication consider our documentation. You will use this password to log into the Nagios administration panel when it is configured.
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Now reload the configuration of the web server by issuing the following command:
Before we continue with the web configuration of Nagios we need to install the default plugins for Nagios.
Build and install Nagios Plugins.
To install and configure the Nagios plugins, issue the following commands to extract, build, and install them:
We're now ready to run Nagios for the first time and continue with the configuration process!
Issue the following command to ensure that Nagios will be restarted following a system boot.
Run the following command to check your Nagios configuration file for errors:
Any errors will be shown in red. If everything is okay, you may issue the following command to start Nagios for the first time:
Now you can access the web based administration and reporting tools by visiting http://ducklington.org/nagios/, where ducklington.org refers to your Linode's default virtual host. You may also access this interface by visiting http://18.104.22.168/nagios/ where 22.214.171.124 is the IP address of your Linode. You will need to authenticate with the nagiosadmin user you created earlier.
Configure Nagios Alerts.
A great deal of the power of Nagios is its ability to send notifications and alerts of the status of the components of your network on a very granular level. While most of this fine grained configuration is beyond the scope of this document, we have outlined some basic notification systems below.
Installing Prerequsites to send Mail Alerts.
Before Nagios can send Alerts by way of email, basic mail services need to be installed. Issue the following command:
When the installation process prompts you to define the type of mail setup you're running, select "Internet Site." You will also want to specify the machine specific hostname for this server during the installation process. Next, we'll need to update the path to the mail binary in the Nagios command file. Change both references from /bin/mail to /usr/bin/mail. The relevant section of this file should look like this:
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
# 'notify-service-by-email' command definition
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$" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
Issue the following command to restart Nagios and put the changes into effect:
You will now be able to successfully configure and send email alerts using Nagios.
Configuring Basic IRC Notifications
You can also configure Nagios to send notifications to an IRC channel. Issue the following commands to download, extract, and build the IRC bot:
You are now ready to run the bot, however you will need to specify some parameters such as the IRC network and channel. For a list of parameters, issue the following command:
Now to start the Nagios IRC bot issue the nagircbot command. See the following example as a starting point. Replace irc.ducklington.net with the domain of your IRC network, and #bucknell with the name of the IRC channel to which you would like to send notifications. Replace nagircbot with the desired nickname for your bot, and ident and realname with the ident and real name strings for the IRC bot.
nagircbot -f /usr/local/nagios/var/status.dat -s irc.duckligton.net:6667 -c \#bucknell -C -n nagircbot -u ident -U realname -I 900
In the above example, "-f /usr/local/nagios/var/status.dat" tells the bot where to get status updates. The "-C" flag will allow the bot to send colored messages to the channel depending on the status of the service. When services are down, red status messages are displayed, and these messages turn green when the service has recovered. Warnings are displayed in yellow, but do not typically represent a critical status. The "-I 900" parameter tells the bot to send a status message to the channel every 900 seconds (or 15 minutes). For example, the bot may send something like "Critical: 0, warning: 1, ok: 6, up: 2, down: 0, unreachable: 0, pending: 0", which indicates that there are no critical messages and 1 warning.
These two examples only scratch the surface of the kinds of monitoring and notifications that are possible with Nagios. Explore the resources listed below and the administrative interface for more information regarding the setup and configuration of Nagios. Congratulations on your new Nagios monitoring and notification system.
Default Nagios Interface.
The screenshots below are from the default interface that gets installed with Nagios Core.
|Main Splash Screen||Tactical Overview||Service Detail||Host Detail|
|Hostgroup Overview||Hostgroup Summary||Hostgroup Grid||Service Problems|
|Circular Status Map||Balloon Status Map||Tree Status Map||Comments|
|Scheduled Downtime||Scheduling Host Downtime||Scheduling Service Downtime||Nagios Process Info|
|Performance Info||Scheduled Event Queue||Alert History||Notification History|
|Event Log||Configuration View||Alert Summary Menu||Trends Menu|
|Host State Trends||Service State Trends||Hostgroup Availibility Report||Service Availibility Report|
|Service Alert Histogram||Host Alert Histogram||PNP Addon Graphs||WAP Interface|
This guide is licensed under a Creative Commons Attribution-No Derivative Works 3.0 United States License. Please feel free to redistribute unmodified copies of it as long as attribution is provided, preferably via a link to this page.