| by TheIneptOne | 1 comment

Adding Hosts to Nagios

Hosts or Servers are added to Nagios with text based cfg files and for my setup, are stored in /opt/nagios/servers. Prior to adding a server, it is a good idea to have the Nagios NCPA Agent installed on each server that will be monitored.

When editing a file with Nano, to save your changes to do the following:

  • Ctrl+X to Exit
  • Y to save the edits currently stored in the buffer
  • Enter to write to the current file name

Server Creation

For my setup, the server configuration files are located in /opt/nagios/servers. I keep a template file in the same directory called server-template that can be used to easily add a new server. The template file contains the following

define host{
    host_name        [SERVERNAME]
    alias            [SERVER NAME]
    address          [IP ADDRESS]
    use              servers-template
}

Its a basic file and you’ll only need to change the host_name, alias, and address. You an put all servers in the same file or create a separate file for each location. My setup has a file per physical site regardless of how many servers are at the site. The cfg file can contain a lot more information, which will be covered in a later article

Copy the template and rename it to the servername.cfg

sudo cp server-template servername.cfg

Note: the file needs to end with .cfg. If the file does not have that extension, Nagios will not read and process it.

Use Nano to edit the file

sudo nano servername.cfg

Update the file with your server info

define host{
    host_name    SERVER1
    alias        SERVER1
    address      172.31.1.10
    use          servers-template
}

Notice, I am using the servers-template that we created during the initial Nagios setup

Save the changes by pressing Ctrl+XY for Yes, and Enter to select the file name to write (by default is the file we have opened)

Host Groups

Host groups allow us to group hosts together to easily assign services and templates. The host groups can be named whatever you want, for my setup, I use the following:

  • PhysicalServers – These are virtual hosts and any servers that are installed directly on the hardware. This group provides the standard checks as well as hardware specific check.
  • VirtualServers – Any virtual servers. This group is also a member of the DomainControllers group since all of our DCs are currently virtualized
  • DomainControllers – This group is only for DCs and provides checks for Active Directory
  • LinuxServers – Any Linux based server regardless if virtual or physical

Adding checks to servers requires the server to part of a group. You can a server to a group by adding the hostname under the members option. Each hostname is case sensitive and must be separated by a comma.

The host group configuration files are located in /opt/nagios/groups

cd /opt/nagios/groups

Note: the file needs to end with .cfg. If the file does not have that extension, Nagios will not read and process it.

Use Nano to edit the file

sudo nano host-groups.cfg

Add a server to a group by adding the hostname under the members option. Each hostname is case sensitive and must be separated by a comma. Servers can be members of multiple groups as well

define hostgroup{
    hostgroup_name     DomainControllers
    alias              Domain Controllers
    members            SERVER1
    register 1
}

Save the changes by pressing Ctrl+XY for Yes, and Enter to select the file name to write (by default is the file we have opened)

Completed the same setup for any additional servers

Checking and Restarting Nagios

Once all configurations are completed, we’ll need to do a sanity check to verify there are no errors in the files that were edited and then restart the Nagios service. If the sanity check is not ran and there are errors in the file, the Nagios service will fail to start.

The sanity check can be run with the following comand

sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

As long as Total Warnings and Total Errors are both 0, we’re good to restart the service

To restart the nagios service, run the following command

sudo systemctl restart nagios.service

Typically you will not get any feedback upon successful restart. To verify the service is running, run the following command: (If necessary, type q to exit)

sudo systemctl status nagios.service

 

 

 

1 Comment

Nagios 4.4.6 on Ubuntu 20.04 – Inept Tech

February 1, 2022 at 11:34 pm Reply

[…] Adding Hosts to Nagios […]

Leave a Reply