2012년 9월 25일 화요일

Nagios: Adding additional host

Nagios has configuration files that are written to manage servers. Generally, they are divided into two files: One is for Linux server and the other is for Windows. 

Server group can be defined to manage one more servers that have similar purposes. Looking at the configuration file for the sever. 

For a start, I defined a windows server. At that time, I didn't use any hostgroup.

vi /etc/nagios/objects/windows.cfg

define host{
        use             windows-server  ;  Inherit default values from a template
        host_name       winserver       ; The name we're giving to this host
        alias           My Windows Server  ; A longer name 
        address         192.168.20.169  ;   IP address of the host
        }

###################################################
###################################################
#
# HOST GROUP DEFINITIONS
#
###################################################
###################################################

# Define a hostgroup for Windows machines
# All hosts that use the windows-server template will automatically be a member of this group

define hostgroup{
        hostgroup_name  windows-servers ; The name of the hostgroup
        alias           Windows Servers ; Long name of the group
        }

###################################################
###################################################
#
# SERVICE DEFINITIONS 
#
###################################################
###################################################

# Create a service for monitoring the version of NSCLient++ that is installed
# Change the host_name to match the name of the host you defined above
define service{
        use                     generic-service
        host_name               winserver
        service_description     NSClient++ Version
        check_command           check_nt!CLIENTVERSION
        }

# Create a service for monitoring the uptime of the server
# Change the host_name to match the name of the host you defined above
define service{
        use                     generic-service
        host_name               winserver
        service_description     Uptime
        check_command           check_nt!UPTIME
        }


# Create a service for monitoring CPU load
# Change the host_name to match the name of the host you defined above
define service{
        use                     generic-service
        host_name               winserver
        service_description     CPU Load
        check_command           check_nt!CPULOAD!-l 5,80,90
        }
....
....


I needed to register one more server. I wanted it to have same monitoring items with the previously registered server. How can I do for this? It is just simple. It has to use hostgroup. Let's modify configuration file like the following: 

vi /etc/nagios/objects/windows.cfg

## New host definition 
define host{
        use             windows-server  ; Inherit default values from a template
        host_name       adserver       ; The name we're giving to this host
        alias           Active Directory Server       ; A longer name
        address         192.168.20.168  ; IP address of the host
        }
....

## Members are added to the group
define hostgroup{
        hostgroup_name  windows-servers ; The name of the hostgroup
        alias           Windows Servers ; Long name of the group
        members         adserver, winserver     ; Comma separated list of hosts
        }
....

###################################################
###################################################
#
# SERVICE DEFINITIONS 
#
###################################################
###################################################

## hostgroup_name is added to "service definition"
define service{
        use                     generic-service
        host_name
        hostgroup_name          windows-servers

        service_description     NSClient++ Version
        check_command           check_nt!CLIENTVERSION
        }
....

With nagios online manual, the description for the "service definition" is:
hostgroup_name: This directive is used to specify the short name(s) of the hostgroup(s) that the service "runs" on or is associated with. The hostgroup_name may be used instead of, or in addition to, the host_name directive.
OR, there is another way to do this without using hostgroup: 

## Use a comma-separated list in the "service definition"
define service{
        use                     generic-service
        host_name               winserver, adserver
        hostgroup_name        
        service_description      Uptime
        check_command           check_nt!UPTIME
        }

You can also use a comma-separated list of hosts.

For the Linux host configuration file, it has the same way for this. In summarized, for the same monitoring service items with different hosts, it is effective way to manage by with the same hostgroup and define only specific sevices of each host.

댓글 없음:

댓글 쓰기