If you previously followed my guide on Nagios 4 Setup then you are probably wondering how to add hosts to your Nagios 4 install.
Well below is how I added some basic hosts to Nagios 4 through the command line so continue reading to see how I did it.
Make a new object definition by typing:
sudo nano /usr/local/nagios/etc/objects/newhost.cfg
Now add the following lines to it:
# Define a host for the local machine
define host{ use linux-server ; Name of host template to use ; This host definition will inherit all variables that are defined ; in (or inherited by) the linux-server host template definition. host_name google.com alias google.com address www.google.com }
############################################################################### ############################################################################### # # SERVICE DEFINITIONS # ############################################################################### ###############################################################################
# Define a service to "ping" the local machine
define service{ use generic-service ; Name of service template to use host_name google.com service_description PING check_command check_ping!100.0,20%!500.0,60% }
# Define a service to check HTTP on the local machine. # Disable notifications for this service by default, as not all users may have HTTP enabled.
define service{ use generic-service ; Name of service template to use host_name google.com service_description HTTP check_command check_http notifications_enabled 0 }
now edit your main config file to tell it the location of the new config file:
sudo nano /usr/local/nagios/etc/nagios.cfg
add the following line to the file:
cfg_file=/usr/local/nagios/etc/objects/newhost.cfg
Now restart your nagios daemon:
sudo /etc/init.d/nagios restart
Check for errors prior to restarting before continuing with last step
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Restart nagios after changing any config files with:
sudo /etc/init.d/nagios restart

