Chinaunix首页 | 论坛 | 博客
  • 博客访问: 923522
  • 博文数量: 119
  • 博客积分: 6248
  • 博客等级: 准将
  • 技术积分: 1419
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-08 14:14
文章分类

全部博文(119)

文章存档

2014年(1)

2012年(1)

2011年(2)

2010年(22)

2009年(81)

2008年(12)

分类: LINUX

2008-12-03 23:09:53

由于前不久做nagios监控系统,发现在添加主机与服务的时候,每次都要打开主机和服务配合文件,并且需要修改参数,甚是麻烦,于是就想用脚本来代替这些重复性的工作,首先需要建立2个模板文件hosts.temp  services.temp,2个模板文件的内容如下:
hosts.temp 的内容:
define host {
       host_name                 
       alias                     
       address                   
       contact_groups             sagroup
       process_perf_data          1
       check_command              check-host-alive
       max_check_attempts         10
       notification_interval      10
       notification_period        24x7
       notification_options       d,u,r
       }

services.temp的内容如下:
define service {
        host_name
        service_description
        check_period              24x7
        max_check_attempts        10
        normal_check_interval     10
        retry_check_interval      3
        contact_groups            sagroup
        process_perf_data         1
        notification_interval     3
        notification_period       24x7
        notification_options      w,u,c,r
        check_command
        }

注意:模板里面的参数可以自行添加和修改。
 
写了2个脚本,addhost.sh  addservice.sh ,一个是添加主机,一个是添加服务
 
addhost.sh的内容如下:
 
#!/bin/bash
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.temp>>hosts.cfg
addservice.sh的内容如下:
 
#!/bin/bash
echo "please  input  host_name: "
read  host_name
echo "please  input service_description "
read  service_description
echo "please input check_command  "
read  check_command
sed -e /host_name/{s/$/$host_name/} -e /service_description/{s/$/$service_description/} -e /check_command/{s/$/$check_command/} services.temp>>services.cfg
 
只要运行脚本输入自己服务器的信息,就可以在配置文件后面添加主机以及服务的配置内容了。
 
阅读(3754) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-04-14 23:51:32

哈哈!!! 用这个方法省事多了,特别是添加多台主机时。