Automated Host Management
Server - Nagios

 

Nagios XI 2012 provides the automated host management feature. Large scale deployments will often depend heavily upon the use of automation to make things happen. One of the automation tools that is popular is Puppet. The Automated Host Management feature allows for the use of an application like Puppet. Administrators can either create the config file manually or copy the configuration files from another XI or Core server.

 

Manually Create and Import
Before switching to a tool like Puppet, first get the idea of how the automated host management works by manually creating and importing a host. Several points to note here is that the host should have the host and sevice information in one file. The configuration files must be placed in the /usr/local/nagios/etc/import directory where they will be removed once they are imported.

 

This example will create a host “centos” and create a service check just to see how the process works.

 

vi /usr/local/nagios/etc/import/centos.cfg

 

Here is the configuration file which is in the same format as a configuration file on a Nagios Core server. Note, if you make references to templates that do not exist yet it will break the import.

 

define host {

host_name centos

use generic-host

alias CentOS 6 Database

address 192.168.5.190

hostgroups linux-servers

check_command check-host-alive!!!!!!!!

max_check_attempts 5

contacts nagiosadmin

icon_image centos.png

register 1

}

define service{

use generic-service

host_name centos

service_description HTTP

check_command check_http

}

 

Save the file and then from the command line proceed to /usr/local/nagiosxi/scripts. Note you must be in this directory when you execute the command in order for it to work properly.

 

./reconfigure_nagios.sh

This will run the pre-flight check to verify the integrity of the imported file. In this process the script will attempt to pull in new configuration files and/or pull in changes made to hosts and services which already exist. As the script runs it not only creates the output for the pre-flight check but it also will create a return code which is highlighted below.

 

Checking obsessive compulsive processor commands...

Checking misc settings...

 

Total Warnings: 0

Total Errors: 0

 

Things look okay - No serious problems were detected during the pre-flight check

RET: 0

Running configuration check...done.

Stopping nagios: done.

Starting nagios: done.

[root@xiview scripts]# SETUID ROOT OK

RESETTING PERMS

/usr/local/nagiosxi/nom/checkpoints/nagioscore /usr/local/nagiosxi/scripts

tar: Removing leading `/' from member names

/usr/local/nagiosxi/scripts

 

 

Here is a table of the return code meanings:

0 no problems detected

1 configuration verification failed

2 nagiosql login failed

3 nagiosql import failed

4 reset_config_perms failed

5 nagiosql_exportall.php failed (could not write configs)

6 /etc/init.d/nagios restart failed

7 db_connect failed

 

Here is the example of the host and service from above being imported and set up with Nagios XI.

 

Service Status Detail

 

Migrate a Host to Another XI Server

If you wanted to migrate a host to another XI server you could follow this process:

 

Copy the config files from one Nagios XI server to the other. First locate the host file in /usr/local/nagios/etc/hosts and then move it to the other server.

 

scp centos.cfg This e-mail address is being protected from spambots. You need JavaScript enabled to view it :/usr/local/nagios/etc/import/

 

Now move into the services directory which is also in /usr/local/nagios/etc and do the same. Be careful to rename files if they have the same name as not to overwrite the files.

 

scp centos.cfg This e-mail address is being protected from spambots. You need JavaScript enabled to view it :/usr/local/nagios/etc/import/ centos2.cfg

 

Combine the file by copying the host information to the service file.

 

Save the file and then from the command line proceed to /usr/local/nagiosxi/scripts. Note you must be in this directory when you execute the command in order for it to work properly.

 

./reconfigure_nagios.sh

This will run the pre-flight check to verify the integrity of the imported file. In this process the script will attempt to pull in new configuration files and/or pull in changes made to hosts and services which already exist. As the script runs it not only creates the output for the pre-flight check but it also will create a return code which is highlighted below.

 

Just remember that if you are using templates or servicegroups, etc you will need to migrate those as well.