Configuring remote service checks using nagios

From Notes_Wiki

Home > CentOS > CentOS 6.x > Monitoring tools > Nagios configuration > Configuring remote service checks using nagios

We can check lot of remote services including ping, http, ftp, smtp, pop3 and imap using nagios. For other services we can write our own check command, add command to commands.cfg file (located in /etc/nagios/objects in CentOS 5.4) and then check custom services.


Create configuration directory for hosts

For easier maintenance later it is better to put configuration of only one host in one configuration file. Also we can put all host configuration files in one directory, all switch configuration file in other directory and so on for easier management. Edit file 'nagios.cfg' and add/uncomment line like

cfg_dir=/etc/nagios/servers

After this create folder '/etc/nagios/servers' if it does not exists and change its user and group owner to nagios.


Configure host

To check services on a host we first define host and then we define services running on the host. To define host use

define host{
        use                     linux-server  ; Name of template
        host_name               students      ; Short name of server, will be used in nagios configuration
        alias                   students.iiit.ac.in ; Long name of server, will be used in reporting
        address                 students.iiit.ac.in ; FQDN or IP address of host, will be used for checks
        }

You have to add the above defination to file with extension .cfg and save the file in /etc/nagios/servers directory.


Add host to host group

Sample host groups are defined in sample configuration files. We can define our own host groups if we like. We can also add hosts to existing host groups. Sample host group 'Linux Servers' is defined in file 'localhost.cfg' and hence we can add more hosts to same group. Sample changed host group definition can be like

define hostgroup{
        hostgroup_name  linux-servers ; The name of the hostgroup
        alias           Linux Servers ; Long name of the group
        members         localhost,labpc,students,ss1  ; Comma separated list of hosts that belong to this group
        }

Do not re-define hostgroup. Change the definition of hostgroup in localhost.cfg file whenever you want to add host to it


Configuring ping check

The simplest check is ping check. Modify host_name appropriately.

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       students
        service_description             PING
        check_command                   check_ping!100.0,20%!500.0,60%
        notifications_enabled           1
        }


Check things are fine

After this check if things are fine using 'nagios -v' and then 'service nagios reload'. Open nagios web interface and see the host is being pinged properly. If all goes fine then you can add more services running on the host that can be accessed remotely


Checking SSH service

We can use something like this to configure check for SSH service. Modify host_name appropriately.

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       ss1
        service_description             SSH
        check_command                   check_ssh
        notifications_enabled           1
        }


Checking HTTP service

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       ss1
        service_description             HTTP
        check_command                   check_http
        notifications_enabled           1
        }


Checking FTP service

define service{
        use             generic-service         ; Inherit default values from a template
        host_name               ss1
        service_description     FTP
        check_command   check_ftp
        }


Checking SMTP service

define service{
        use             generic-service         ; Inherit default values from a template
        host_name               students
        service_description     SMTP
        check_command   check_smtp
        }


Checking IMAP service

define service{
        use             generic-service         ; Inherit default values from a template
        host_name               students
        service_description     IMAP
        check_command   check_imap
        }


Checking POP3 service

define service{
        use             generic-service         ; Inherit default values from a template
        host_name               students
        service_description     POP3
        check_command   check_pop
        }



Troubleshooting

Permission issues

If you see error 'It appears as though you do not have permission to view information for any of the services you requested...' then it is caused by username configuration in /etc/nagios/cgi.cfg where by default only nagiosadmin user has permissions to do everything. This is not desirable if LDAPAuthentication is being used for nagios. This can be solved by replacing nagiosadmin by a specific username or by * everywhere in /etc/nagios/cgi.cfg file.


Automated nagios configuration

For automated nagios configuration refer to:


Home > CentOS > CentOS 6.x > Monitoring tools > Nagios configuration > Configuring remote service checks using nagios