nagios本身并没有监控的功能,所有的监控是由插件完成的,插件将监控的结果返回给nagios,nagios分析这些结果,以web的方式展现给我们,同时提供相应的报警功能(这个报警的功能也是由插件完成的如:notify-host-by-email)
   这些插件是一些实现特定功能的可执行程序,默认安装的路径是/usr/local/nagios/libexec,可以查看:

我们查看check_dns这个插件的用法则可以使用#./check_dns –h
./check_dns --help
check_dns v1992 (nagios-plugins 1.4.13)
Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>
Copyright (c) 2000-2008 Nagios Plugin Development Team
<nagiosplug-devel@lists.sourceforge.net>

This plugin uses the nslookup program to obtain the IP address for the given host/domain query.
An optional DNS server to use may be specified.
If no DNS server is specified, the default server(s) specified in /etc/resolv.conf will be used.


Usage:check_dns -H host [-s server] [-a expected-address] [-A] [-t timeout] [-w warn] [-c crit]

Options:
-h, --help
Print detailed help screen
-V, --version
Print version information
-H, --hostname=HOST
The name or address you want to query
-s, --server=HOST
Optional DNS server you want to use for the lookup
-a, --expected-address=IP-ADDRESS|HOST
Optional IP-ADDRESS you expect the DNS server to return. HOST must end with
a dot (.). This option can be repeated multiple times (Returns OK if any
value match). If multiple addresses are returned at once, you have to match
the whole string of addresses separated with commas (sorted alphabetically).
-A, --expect-authority
Optionally expect the DNS server to be authoritative for the lookup
-w, --warning=seconds
Return warning if elapsed time exceeds value. Default off
-c, --critical=seconds
Return critical if elapsed time exceeds value. Default off
-t, --timeout=INTEGER
Seconds before connection times out (default: 10)

Send email to nagios-users@lists.sourceforge.net if you have questions
regarding use of this software. To submit patches or suggest improvements,
send email to nagiosplug-devel@lists.sourceforge.net

现在就开始讲关于在nagios上面应用这此插件吧:
 在这里,我就简单地说一些安装时nagios已经为我们写好的插件的用方法,它们在commands.cfg已经有定义了,我们直接使用就可以了:
     1、不用输入参数的插件用法。
         如: # 'check-host-alive' command definition

            define command{

            command_name check-host-alive

            command_line $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 1

      }
   从上面可以看出,它里面的command_line 里的没有我们要手动添加参数的部分。(注:$HOSTADDRESS$这也是一个变量,不过它在引用时会被程序自定义为使用这个命令的主机的IP地址)
    接用,这个命令的用法:它可以在hosts.cfg、localhosts.cfg、services.host这些有主机定义的配置文件里使用:
   如:在services.cgf中:
    define service{
       host_name CentOS-Server               //这个名字我已经在hosts.cgf有定义,他的IP是192.168.1.105
       service_descripti插件的命令调用on check-host-alive  //标识,在nagios的web管理显示   
       check_command check-host-alive   //( 插件的命令调用
       max_check_attempts 5
       check_period 24x7
       normal_check_interval 3
       retry_check_interval 2
       notification_interval 10
       notification_period 24x7
       notification_options w,u,c,r
       contact_groups admins
}

2、有参数的插件命令使用。在引用要手动填写参数,否则在nagios的web的相应的执行结果为“Unknow argument”
    例:#vi commands.cfg里面

       # 'check_local_disk' command definition

          define command{

          command_name check_local_disk

          command_line $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$

       }



  check_local_disk实际上是执行的check_disk插件.这里的$ARG1$, $ARG2$, $ARG3$是三个变量,要我们在使用它的时侯为他们赋值,在之前我们已经提到了这个check_disk这个插件的用法,-w的参数指定磁盘剩了多少是警告状态,-c的参数指定剩多少是严重状态,-p用来指定路径.
   使用:vi services.cfg
 
define service{
        host_name localhost
        service_description check-local-disk
        check_command check_local_disk!10%!5%!/
        max_check_attempts 5
       .......
        notification_options w,u,c,r
        contact_groups admins
  }

 在命令名后面用!分隔出了3个参数,10%是$ARG1$的值,5%是$ARG2$的值,/ 是$ARG3$的值,也就是根分区。

注:使用步骤
      a、services.cfg定义监控项目用某个命令

      b、这个命令必须在commands.cfg中定义

      c、定义这个命令时使用了libexec下的插件

  如果命令不带$ARG1$就可以在services.cfg中直接使用,如果带了使用时就带上参数,以!相隔。