Chinaunix首页 | 论坛 | 博客
  • 博客访问: 408321
  • 博文数量: 403
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: -70
  • 用 户 组: 普通用户
  • 注册时间: 2016-09-05 12:45
文章分类

全部博文(403)

文章存档

2014年(3)

2013年(1)

2012年(3)

2011年(21)

2010年(13)

2009年(64)

2008年(9)

2007年(36)

2006年(253)

分类: 系统运维

2010-04-14 09:55:53

先建两个模版文件,其内容分别如下:
host.tempt:
define host {
       host_name                 
       alias                     
       address                   
       contact_groups             sagroup
       check_command             check-host-alive
       max_check_attempts         5
       notification_interval      10
       notification_period        24x7
       notification_options        d,u,r
       }
 
services.tempt:
define service {
        host_name            
        service_description   check_tcp 80
        check_period          24x7
        max_check_attempts    4
        normal_check_interval 3
        retry_check_interval  2
        contact_groups        sagroup
        notification_interval   10
        notification_period     24x7
        notification_options    w,u,c,r
        check_command      check_tcp!80
        }
define service {
        host_name            
        service_description   check_disk
        check_period          24x7
        max_check_attempts    4
        normal_check_interval 3
        retry_check_interval  2
        contact_groups        sagroup
        notification_interval   10
        notification_period     24x7
        notification_options    w,u,c,r
        check_command           check_nrpe!check_disk
        }
define service {
        host_name            
        service_description   check_load
        check_period          24x7
        max_check_attempts    4
        normal_check_interval 3
        retry_check_interval  2
        contact_groups        sagroup
        notification_interval   10
        notification_period     24x7
        notification_options    w,u,c,r
        check_command           check_nrpe!check_load
        }
define service {
        host_name            
        service_description   check_procs
        check_period          24x7
        max_check_attempts    4
        normal_check_interval 3
        retry_check_interval  2
        contact_groups        sagroup
        notification_interval   10
        notification_period     24x7
        notification_options    w,u,c,r
        check_command           check_nrpe!check_total_procs
        }
 
然后我们再建立添加脚本add_nagios.sh,其内容如下
#!/bin/bash
#writed by sery in Apr 28,2008.
cd /root/nagios_cfg_script
echo "please  input  host_name: "
read  host_name
echo "please input alias: "
read  alias
echo "please input address: "
read  address
sed -e /host_name/{s/$/$host_name/} -e /alias/{s/$/$alias/} -e /address/{s/$/$address/}\  hosts.tempt>>hosts
sed -e /host_name/{s/$/$host_name/}  services.tempt>>services
 
给脚本执行权限,然后执行add_nagios.sh,交互输入ip地址,别名,主机名3项,就可生成hosts及services文件,然后再备份nagios下的配置文件,把这两个文件追加进去,然后nagios -v nagios.cfg检查一下.
 
如果不想手工交互输入,可以建一个ip地址列表,自动完成这个工作.
阅读(1010) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~