nagios服务端能检测客户端版本后,接下来的工作则是对客户端的监控,我的配置文件是这样操作的

把所有的监控主机节点都放到hosts.cfg中,所有主机的服务都放到services.cfg中,如果日后要添加的话,则只需要改动这2个文件就可以了

cfg_file=/usr/local/nagios/etc/objects/templates.cfg

cfg_file=/usr/local/nagios/etc/objects/commands.cfg

cfg_file=/usr/local/nagios/etc/objects/contacts.cfg

cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg

cfg_file=/usr/local/nagios/etc/objects/services.cfg

cfg_file=/usr/local/nagios/etc/objects/hosts.cfg

cfg_file=/usr/local/nagios/etc/objects/contactgroups.cfg

cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg

####

cat services.cfg

#####远程主机host 122.49.3x.xxx###

define service{

       host_name               xxxx

       service_description     Current Load

       check_command           check_nrpe!check_load

       max_check_attempts      5

       normal_check_interval   3

       retry_check_interval    2

       check_period            24x7

       notification_interval   10

       notification_period     24x7

       notification_options    w,u,c,r

       contact_groups          shyygroup

       }

###下面是本机的监控

define service{      

       host_name               xxx

       service_description     Current Users

       check_command           check_local_users!20!50

       max_check_attempts      5

       normal_check_interval   3

       retry_check_interval    2

       check_period            24x7

       notification_interval   10

       notification_period     24x7

       notification_options    w,u,c,r

       contact_groups          shyygroup

       }

root># cat hostgroups.cfg

define hostgroup{

       hostgroup_name  shyy-servers

       alias           shyy-servers

       members         xx,xxx   (主机名)

       }

root># cat contacts.cfg

define contact {

    contact_name                       nagiosadmin

    alias                              nagios administrator

    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

    pager 1371xx

}

root>#cat commands.cfg(如下几行是新增的)

define command{

      command_name  check_nrpe

      command_line  $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

      }

define command{

      command_name  process-service-perfdata

      command_line   /usr/local/nagios/libexec/process_perfdata.pl

      }

define command{

      command_name  process-host-perfdata

      command_line  /usr/local/nagios/libexec/process_perfdata.pl

      }

define command{

       command_name    check_mem

       command_line    $USER1$/check_mem.sh -w $ARG1$ -c $ARG2$

       }

define command{

       command_name    check_traffic

       command_line    $USER1$/check_traffic.sh -V 2c -C public -H $HOSTADDRESS$ -I $ARG1$ -w $ARG2$ -c $ARG3$ -K -b

       }

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


Total Warnings: 0

Total Errors:   0         如果有警告或错误,都是有提示的,根据提示检查配置文件


【nagios客户端】,需要在nagios客户端先定义,/usr/local/nagios/libexec插件下的所有插件都必须要有执行权限,否则会报“NRPE: Command 'xx’ not defined”

command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10

command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20

command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1

command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z

command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200

command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 190 -c 200

command[check_http]=/usr/local/nagios/libexec/check_http -H localhost -p 80

command[check_sda3]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda3

command[check_mysql]=/usr/local/nagios/libexec/check_mysql -H localhost -unagios -p123456

command[check_ping]=/usr/local/nagios/libexec/check_ping -H localhost -w 200.0,20% -c 800.0,40%

command[check_mem]=/usr/local/nagios/libexec/check_mem.sh -w 150 -c 100

command[check_traffic]=/usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H 127.0.0.1 -I 3 -w 300,400 -c 500,600 -K -B

command[check_5666]=/usr/local/nagios/libexec/check_tcp -H 127.0.0.1 -p 5666

command[check_port]=/usr/local/nagios/libexec/check_tcp -H 127.0.0.1 -p 3306

command[check_java_9801]=/usr/local/nagios/libexec/check_tcp -H 127.0.0.1 -p 9801

command[check_java_9800]=/usr/local/nagios/libexec/check_tcp -H 127.0.0.1 -p 9800

重启nrpe
【nrpe测试】在nagios服务器测试
./check_nrpe -H 122xx -c check_sda3
DISK OK - free space: / 876739 MB (98% inode=99%);| /=12366MB;749349;843018;0;936687
就可以了
如图:

nagios监控客户端_nagios监控客户端