A photo of Mitesh Shah

Mitesh Shah

Linux Expert | Automation Enthusiast | Security Consultant

Email Skype Github Twitter Resume Hire Me Keybase LinkedIn Stackoverflow


Overview

Configure Nagios

$ vim /usr/local/nagios/etc/nagios.cfg
# Add following lines on cfg_dir block
cfg_dir=/usr/local/nagios/etc/contacts
cfg_dir=/usr/local/nagios/etc/contactgroups
cfg_dir=/usr/local/nagios/etc/services
cfg_dir=/usr/local/nagios/etc/commands
cfg_dir=/usr/local/nagios/etc/hosts
cfg_dir=/usr/local/nagios/etc/hostgroups
  • Create Nagios Directory
$ mkdir /usr/local/nagios/etc/{contacts,contactgroups,services,commands,hosts,hostgroups}

Nagios Contacts

$ vim /usr/local/nagios/etc/contacts/alerts.cfg
define contact{
        contact_name                    ops
        alias                           Ops
        service_notification_period     24x7
        host_notification_period        24x7
        service_notification_options    w,u,c,r
        host_notification_options       d,u,r
        service_notification_commands   notify-service-by-email
        host_notification_commands      notify-host-by-email
        email                           alerts@example.com
}

Nagios Contact Groups

$ vim /usr/local/nagios/etc/contactgroups/oncall-admin.cfg
define contactgroup{
        contactgroup_name      oncall-admins
        alias                  On-call Admins
        members                ops
 }

Nagios Hosts

$ vim /usr/local/nagios/etc/hosts/example.com
define host {
        use                             linux-server
        host_name                       example.com
        alias                           example.com
        address                         example.com
        max_check_attempts              5
        check_period                    24x7
        notification_interval           30
        notification_period             24x7
	notification_options    	d,u,r
}
$ vim /usr/local/nagios/etc/hosts/test.com
define host {
        use                             linux-server
        host_name                       test.com
        alias                           test.com
        address                         test.com
        max_check_attempts              5
        check_period                    24x7
        notification_interval           30
        notification_period             24x7
	notification_options    	d,u,r
}

Nagios Host Groups

$ vim /usr/local/nagios/etc/hostgroups/http.cfg
define hostgroup{
        hostgroup_name  HTTP
        alias           HTTP
        members         example.com,test.com
}
$ vim /usr/local/nagios/etc/hostgroups/https.cfg
define hostgroup{
        hostgroup_name  HTTPS
        alias           HTTPS
        members         example.com
}
$ vim /usr/local/nagios/etc/hostgroups/remote_mysql.cfg
define hostgroup{
        hostgroup_name  REMOTE_MYSQL
        alias           REMOTE MYSQL
        members         example.com,test.com
}
$ vim /usr/local/nagios/etc/hostgroups/remote_nginx.cfg
define hostgroup{
        hostgroup_name  REMOTE_NGINX
        alias           REMOTE NGINX
        members         example.com,test.com
}
$ define hostgroup{
        hostgroup_name  REMOTE
        alias           Remote Linux Servers
        members         example.com,test,com
}

Nagios Services

$ vim /usr/local/nagios/etc/services/http.cfg
define service{
        use                             local-service         ; Name of service template to use
        service_description             HTTP
        is_volatile                     0
        check_period                    24x7
        max_check_attempts              3
        normal_check_interval           3
        retry_check_interval            1
        contact_groups                  oncall-admins
        hostgroup_name                  HTTP
        notification_interval           30
        notification_period             24x7
        notification_options            c,r
        check_command                   check_http
}
$ vim /usr/local/nagios/etc/services/https.cfg
define service{
        use                             local-service         ; Name of service template to use
        service_description             HTTPS
        is_volatile                     0
        check_period                    24x7
        max_check_attempts              3
        normal_check_interval           3
        retry_check_interval            1
        contact_groups                  oncall-admins
        hostgroup_name                  HTTPS
        notification_interval           30
        notification_period             24x7
        notification_options            w,c,r
        check_command                   check_https
}
$ vim /usr/local/nagios/etc/services/remote_mysql.cfg
define service{
        use                             local-service         ; Name of service template to use
        service_description             Remote MYSQL
        is_volatile                     0
        check_period                    24x7
        max_check_attempts              3
        normal_check_interval           3
        retry_check_interval            1
        contact_groups                  oncall-admins
        hostgroup_name                  REMOTE_MYSQL
        notification_interval           30
        notification_period             24x7
        notification_options            c,r
        check_command                   check_nrpe!check_mysql
}
$ vim /usr/local/nagios/etc/services/remote_nginx.cfg
define service{
        use                             local-service         ; Name of service template to use
        service_description             Remote NGINX
        is_volatile                     0
        check_period                    24x7
        max_check_attempts              3
        normal_check_interval           3
        retry_check_interval            1
        contact_groups                  oncall-admins
        hostgroup_name                  REMOTE_NGINX
        notification_interval           30
        notification_period             24x7
        notification_options            c,r
        check_command                   check_nrpe!check_nginx
}
$ vim /usr/local/nagios/etc/services/remote.cfg
define service{
        use                             generic-service         ; Name of service template to use
        service_description             Root Partition
        is_volatile                     0
        check_period                    24x7
        max_check_attempts              3
        normal_check_interval           3
        retry_check_interval            1
        contact_groups                  oncall-admins
        hostgroup_name                  REMOTE
        notification_interval           30
        notification_period             24x7
        notification_options            c,r
        check_command                   check_nrpe!check_hda1
}
define service{
        use                             generic-service         ; Name of service template to use
        service_description             Current Load
        is_volatile                     0
        check_period                    24x7
        max_check_attempts              3
        normal_check_interval           3
        retry_check_interval            1
        contact_groups                  oncall-admins
        hostgroup_name                  REMOTE
        notification_interval           30
        notification_period             24x7
        notification_options            c,r
        check_command                   check_nrpe!check_load
}
define service{
        use                             generic-service         ; Name of service template to use
        service_description             Memory Swap
        is_volatile                     0
        check_period                    24x7
        max_check_attempts              3
        normal_check_interval           3
        retry_check_interval            1
        contact_groups                  oncall-admins
        hostgroup_name                  REMOTE
        notification_interval           30
        notification_period             24x7
        notification_options            c,r
        check_command                   check_nrpe!check_memory
}
#define service{
#        use                             generic-service         ; Name of service template to use
#        service_description             Total Process
#        is_volatile                     0
#        check_period                    24x7
#        max_check_attempts              3
#        normal_check_interval           3
#        retry_check_interval            1
#        contact_groups                  oncall-admins
#        hostgroup_name                  REMOTE
#        notification_interval           30
#        notification_period             24x7
#        notification_options            c,r
#        check_command                   check_nrpe!check_total_procs
#}

Nagios Commands

$ cp -av /usr/local/nagios/etc/objects/commands.cfg /usr/local/nagios/etc/commands/
$ vim /usr/local/nagios/etc/commands/https.cfg
define command{
        command_name    check_https
        command_line    $USER1$/check_http -H $HOSTADDRESS$ -C 15 -sni
}
$ vim /usr/local/nagios/etc/commands/nrpe.cfg
define command{
        command_name check_nrpe
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}




Post Navigation