注册 | 登录 忘记密码? 51cto首页 | 博客 | 论坛 | 招聘
热点文章 35岁技术人遭遇年龄坎儿,..
 帮助

我用nagios--用脚本添加配置文件


2008-05-03 23:11:06
 标签:nagios 脚本   [推送到博客圈]

版权声明:原创作品,如需转载,请与作者联系。否则将追究法律责任。
当我们配置好nagios以后,还需要不断的往配置文件中加入监控对象.记得第一次追加监控对象时,有700多个服务及400多个主机,我用vi编辑,花了大量的时间--上万行都是一个一个字符输进去的,很没效率.这次又做了一个nagios监控平台,为了提高效率,我写了一个脚本来处理这些重复输入.
 
在这些配置文件中,hosts.conf与services.conf关联特别大,大量的输入工作就在这里,所以就从这个地方着手吧.
 
先建两个模版文件,其内容分别如下:
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. sery@163.com
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地址列表,自动完成这个工作.
 

本文出自 “sery” 博客,转载请与作者联系!





    文章评论
 
2008-05-03 23:21:13
建立老大把每台主机的文件独立开,然后在主文件中include
这样修改起来方便,查找的时候根据文件名也好定位。
要是都在一个文件里面,700台机器,vi编辑这个文件也挺累的。


2008-05-03 23:25:17
好主意 但1000个主机 就会有1000个以上的文件 可好好考虑文件分组

2008-05-04 02:25:05
来看看,学习一下经验

2008-05-04 18:36:04
学习,还没有用到哪么深的地步,继续关注秋老师的佳作了,哈哈

2008-05-04 18:36:06
学习,还没有用到哪么深的地步,继续关注秋老师的佳作了,哈哈

2008-05-07 13:04:36
秋香老师有没有使用WEB来配置NAGIOS类?

2008-05-08 00:57:55
有基于php mysql方式的

 

发表评论

昵   称:
验证码:  点击图片可刷新验证码  博客过2级,无需填写验证码
内   容: