- Lab
- A Cloud Guru
Using SSH to Check Services
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.
Path Info
Table of Contents
-
Challenge
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
- On the Nagios server, become the
-
Challenge
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.
-
Challenge
Test the SSH Connection
- From the Nagios server, run the following command:
ssh cloud_user@CLIENT_IP
-
Challenge
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/
-
Challenge
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
-
Challenge
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
-
Challenge
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
-
Challenge
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.
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.