LAB: RRDTool Lab - Nagios
Please follow the lab guide to login to the VM.
Note:
Commands preceded with $ imply that you should execute the command as a general user - not as root. Commands preceded with # imply that you should be working as root. If a command line ends with \ this indicates that the command continues on the next line and you should treat this as a single line.
1. Install Required Packages
Update the package index for the APT package manager and install necessary packages:
$ sudo apt-get update $ sudo apt-get install -y autoconf gcc libc6 make wget unzip apache2 php \ libapache2-mod-php7.2 libgd-dev libmcrypt-dev libssl-dev bc \ gawk dc build-essential snmp libnet-snmp-perl gettext
2. Downloading the source
With the prerequisites installed, we can install Nagios itself. Download the source code for the latest stable release of Nagios Core.
$ cd /tmp $ wget -O nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.5.tar.gz $ tar xzf nagioscore.tar.gz
3. Compile source and install Nagios
Before building Nagios, run the configure script and specify the Apache configs directory:
$ cd /tmp/nagioscore-nagios-4.4.5/ $ sudo ./configure --with-httpd-conf=/etc/apache2/sites-enabled
We will see the following output from the configure command:
*** Configuration summary for nagios 4.4.5 2019-08-20 ***:
General Options: ------Nagios executable: nagios Nagios user/group: nagios,nagios Command user/group: nagios,nagios Event Broker: yes Install ${prefix}: /usr/local/nagios Install ${includedir}: /usr/local/nagios/include/nagios Lock file: /run/nagios.lock Check result directory: /usr/local/nagios/var/spool/checkresults Init directory: /lib/systemd/system Apache conf.d directory: /etc/apache2/sites-enabled Mail program: /usr/sbin/sendmail Host OS: linux-gnu IOBroker Method: epoll
Web Interface Options: ------HTML URL: http://localhost/nagios/ CGI URL: http://localhost/nagios/cgi-bin/ Traceroute (used by WAP): /usr/bin/traceroute
Review the options above for accuracy. If they look okay, type 'make all' to compile the main program and CGIs.
Now compile Nagios with this command:
$ sudo make all
Next create a nagios user and nagios group. They will be used to run the Nagios process:
$ sudo make install-groups-users $ sudo usermod -a -G nagios www-data
Now run these make commands to install Nagios binary files, service files, and its sample configuration files:
$ sudo make install $ sudo make install-daemoninit $ sudo make install-commandmode $ sudo make install-config
We will use Apache to serve Nagios’ web interface, so run the following to install the Apache configuration files and configure its settings:
$ sudo make install-webconf
Enable the Apache rewrite and cgi modules with the a2enmod command:
$ sudo a2enmod rewrite $ sudo a2enmod cgi
Now need to create an Apache user account to be able to log into Nagios. The following command will create a user account called nagiosadmin and will be prompted to provide a password for the account.
$ sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Please enter training as password at the prompt. Remember this password, as we will need it to access the Nagios web interface.
Restart Apache to load the new Apache configuration:
$ sudo systemctl restart apache2
Nagios is now running, to confirm this you need to log into the Nagios Web Interface. Point the web browser to the ip address or FQDN of your Nagios Core server, for example:
If you are doing the lab on-line/remote, refer to the lab access guide for instructions on creating a tunnel with ssh
http://groupX-server.apnictraining.net/nagios
Will be prompted for a username and password. The username is nagiosadmin and the password is training
We have only installed the Nagios Core engine. But for this to work, it is necessary to install the Nagios Plugins, which you’ll cover in the next step.
4. Installing the Nagios Plugins
Nagios needs plugins to operate properly. The official Nagios Plugins package contains over 50 plugins that allow you to monitor basic services such as uptime, disk usage, swap usage, NTP, and others.
Download and extract the archive
$ cd /tmp $ wget --no-check-certificate -O nagios-plugins.tar.gz https://github.com/nagios- plugins/nagios-plugins/archive/release-2.2.1.tar.gz $ tar zxf nagios-plugins.tar.gz
Compile and install:
$ cd /tmp/nagios-plugins-release-2.2.1/ $ sudo ./tools/setup $ sudo ./configure $ sudo make $ sudo make install
Now start nagios service
$ sudo systemctl restart nagios
If you are doing the lab on-line/remote, refer to the lab access guide for instructions on creating a tunnel with ssh
Point your web browser to the ip address or FQDN of your Nagios Core server, for example: http://groupX-server.apnictraining.net/nagios
Go to a host and check the status of localhost .
5. Configuring Nagios
Now let’s perform the initial Nagios configuration, which involves editing some configuration files.
Open the main Nagios configuration file and find the line #cfg_dir=/usr/local/nagios/etc/servers
$ sudo vi /usr/local/nagios/etc/nagios.cfg
Uncomment this line by deleting the # character from the front of the line:
cfg_dir=/usr/local/nagios/etc/servers
Now create the directory that will store the configuration file for each server that you will monitor:
$ sudo mkdir /usr/local/nagios/etc/servers
6. Monitoring Hosts with Nagios
To monitor any hosts with Nagios, we will add configuration files for each host specifying what we want to monitor.
On the Nagios server, create a new configuration file for each of the remote hosts that we want to monitor in /usr/local/nagios/etc/servers/ . The following example is to monitor core- router.apnictraining.net
$ sudo vi /usr/local/nagios/etc/servers/core-router.cfg
Add the following host definition:
define host { use generic-host host_name core-router alias core-router address core-router.apnictraining.net check_command check-host-alive max_check_attempts 5 check_period 24x7 notification_interval 30 notification_period 24x7 }
Restart the Nagios service to put any changes into effect:
$ sudo systemctl restart nagios
After several minutes, Nagios will check the new hosts.
Lets add few more nodes and start monitoring them.
Following configuration is for core-switch : $ sudo vi /usr/local/nagios/etc/servers/core-switch.cfg
define host { use generic-host host_name core-switch alias core-switch address core-switch.apnictraining.net check_command check-host-alive max_check_attempts 5 check_period 24x7 notification_interval 30 notification_period 24x7 }
Now add your group router groupX-router . Replace X with group number:
$ sudo vi /usr/local/nagios/etc/servers/groupX-router.cfg
define host { use generic-host host_name groupX-router alias groupX-router address groupX-router.apnictraining.net check_command check-host-alive max_check_attempts 5 check_period 24x7 notification_interval 30 notification_period 24x7 }
Restart the Nagios service to put any changes into effect:
$ sudo systemctl restart nagios
Go to Nagios web interface and validate.
7. Monitoring Services with Nagios
In previous step we have configured Nagios to monitor the uptime. Nagios will only tell if the host is up or down. Let’s add some services to monitor.
Following configuration is to monitor group1-server.apnictraining.net HTTP service:
$ sudo vi /usr/local/nagios/etc/servers/group1-server.cfg
Add the following host definition:
define host { use generic-host host_name group1-server alias group1-server address group1-server.apnictraining.net check_command check-host-alive max_check_attempts 5 check_period 24x7 notification_interval 30 notification_period 24x7 }
define service { use generic-service host_name group1-server service_description HTTP check_command check_http }
The use generic-service directive tells Nagios to inherit the values of a service template called generic-service , which is predefined by Nagios.
Restart the Nagios service to put any changes into effect:
$ sudo systemctl restart nagios
From Nagios web interface go to Services tab and verify.
We can add other hosts (servers and routers) and start monitoring them.
8. Adding Parent Relationships
The keyword parents define the parent-child relationship between nodes. For example as per our lab topology below is the connectivity diagram:
groupX-server -> groupX-router -> core-switch -> core-router
Where core-router is parent of core-switch and core-switch is parent of groupX-router
We can update our nodes configuration accordingly.
core-switch.cfg :
define host { use generic-host host_name core-switch alias core-switch address core-switch.apnictraining.net check_command check-host-alive max_check_attempts 5 check_period 24x7 notification_interval 30 notification_period 24x7 parents core-router }
groupX-router.cfg [replace X with group number]: define host { use generic-host host_name groupX-router alias groupX-router address groupX-router.apnictraining.net check_command check-host-alive max_check_attempts 5 check_period 24x7 notification_interval 30 notification_period 24x7 parents core-switch }
groupX-server.cfg [replace X with group number]:
define host { use generic-host host_name groupX-server alias groupX-server address groupX-server.apnictraining.net check_command check-host-alive max_check_attempts 5 check_period 24x7 notification_interval 30 notification_period 24x7 parents core-switch }
Restart the Nagios service to put any changes into effect:
$ sudo systemctl restart nagios
Please confirm nagios has been loaded properly.
$ sudo systemctl status nagios
If nagios service is broken please check /usr/local/nagios/var/nagios.log for more details.
From Nagios web interface go to Map tab and verify.
End of Lab