可以拓展做成菜单式等更详细的配置,如果你足够努力,可以做到一键 部署几百台服务器的服务监控,是没有问题的(包括host.cfg,service.cfg等),如果配置支持目录就更简单了。
1.建立机器名和IP对应列表
- cat >host.list <
- oldboyVM-001 192.168.1.1
- oldboyVM-002 192.168.1.2
- oldboyVM-003 192.168.1.3
- oldboyVM-004 192.168.1.4
- EOFoldboy
复制代码
#提示:上面列表可以手工编辑或者脚本批量去取
2.批量生成 nagios host配置文件
- rm -f new.host
- exec
- while read line
- do
- echo 'define host {' >>new.host
- echo ' use linux-server' >>new.host
- echo " host_name `echo $line|awk '{print $1}'`" >>new.host
- echo " alias `echo $line|awk '{print $1}'` " >>new.host
- echo " address `echo $line|awk '{print $2}'` " >>new.host
- echo "}" >>new.host
- done
复制代码
3.最终host内容
- $ cat new.host
- define host {
- use linux-server
- host_name oldboyVM-001
- alias oldboyVM-001
- address 192.168.1.1
- }
- define host {
- use linux-server
- host_name oldboyVM-002
- alias oldboyVM-002
- address 192.168.1.2
- }
- define host {
- use linux-server
- host_name oldboyVM-003
- alias oldboyVM-003
- address 192.168.1.3
- }
- define host {
- use linux-server
- host_name oldboyVM-004
- alias oldboyVM-004
- address 192.168.1.4
- }
复制代码
|