You need to connect to and perform a check on a client machine from the Nagios server. Due to your university’s firewall rules (port 5666 is not allowed for NRPE), you will need to use SSH. In this hands-on lab, we will configure an SSH check on a client and the Nagios server.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Generate SSH Keys for the nagios User
On the Nagios server, become the
nagios
user.sudo su nagios
Generate SSH keys for the
nagios
user.ssh-keygen
- Copy the Public Key from the Nagios Server to the Client
- Run the following command from the Nagios server:
vim /home/nagios/.ssh/id_rsa.pub
- Select the SSH key, and copy it to your clipboard.
- On the client, open the
authorized_keys
file.sudo vim /home/cloud_user/.ssh/authorized_keys
- Paste the SSH key at the end of the file, then save and exit.
- Run the following command from the Nagios server:
- Test the SSH Connection
- From the Nagios server, run the following command:
ssh cloud_user@CLIENT_IP
- From the Nagios server, run the following command:
- Copy the check_disk Binaries from the Nagios Server to the Client
- Run the following command from the Nagios server:
sudo -i scp /usr/local/nagios/libexec/check_disk cloud_user@CLIENT_IP:/home/cloud_user/
- Run the following command from the Nagios server:
- Define an SSH Check Command Object on the Nagios Server
- From the Nagios server, change to the
/usr/local/nagios/etc/objects/
directory.cd /usr/local/nagios/etc/objects/
- Open the
commands.cfg
file.sudo vim commands.cfg
Add the following to the file:
define command { command_name ssh_check_disk command_line /usr/local/nagios/libexec/check_by_ssh -H $HOSTADDRESS$ -i /home/nagios/.ssh/id_rsa -l cloud_user -C "/home/cloud_user/check_disk -w 10% -c 5% -p /" }
- From the Nagios server, change to the
- Create the Host, Host Group, and Service Object Definitions
- Create a new file named
linux-server.cfg
in the/usr/local/nagios/etc/objects/
directory.sudo touch /usr/local/nagios/etc/objects/linux-server.cfg
- Open the file.
sudo vim /usr/local/nagios/etc/objects/linux-server.cfg
Add the following to the file:
define host { use linux-server host_name Linux Server alias linuxSrv address CLIENT_IP } define hostgroup { hostgroup_name my-linux-servers alias Linux Servers members Linux Server } define service { use generic-service host_name Linux Server service_description Check DISK check_command ssh_check_disk }
- Create a new file named
- Inform Nagios of the New File, Perform a Preflight Check, and Restart Nagios
- Run the following command:
sudo vim /usr/local/nagios/etc/nagios.cfg
- Add the following to the file:
Definitions for monitoring a network printer cfg_file=/usr/local/nagios/etc/objects/linux-server.cfg
- Save and exit the file.
- Run a preflight check.
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
- Restart Nagios.
sudo systemctl restart nagios
- Check the status of Nagios.
sudo systemctl status nagios
- Run the following command:
- Log In to the Nagios Web Interface and Reschedule a Check for the Check DISK Service
- In a private browser tab, navigate to http://NAGIOS_SERVER_IP/nagios.
- Log in with the following credentials:
- User Name: nagiosadmin
- Password: BlaBla321
- Click Services > Check DISK.
- Under Service Commands, click Re-schedule the next check of this service.
- Next to Check Time, enter a time approximately 10-20 seconds from now (you can check the current time using the
date
command in your terminal window). - Click Commit, then Done.
- Click Services in the left sidebar.
- Verify that there are no errors for the Check DISK service under Status Information.