nagios 布署配置笔记(1)(3)
下面就要批量生成监控主机的信息了.为此需要一些shell,还有一些配置文件的模板.还有一个非常重要的就是ip列表,而且是要做好分类的,具体是看你的实际情况,这个是前期一个准备工作,很重要也很乏味.我这里的是分两类:服务器的位置和节点.分好类后就可以利用shell批量生成配置文档了,这又需要模板,如下:
host.temp
define host{
host_name
alias
address
check_command check-host-alive
max_check_attempts 5
check_period 24x7
contact_groups sagroup
notification_interval 10
notification_period 24x7
notification_options d,u,r
}
services.temp
define service{
host_name
service_description check_tcp 80
check_command check_tcp!80
max_check_attempts 5
check_interval 5
retry_interval 3
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups sagroup
}
量产shell
#!/bin/bash
echo "input hostgroup name:"
read hostgroup
for address in $(cat ip.txt)
do
sed -e /host_name/{s/$/$address/} -e /alias/{s/$/$address/} -e /address/{s/$/$address/} host.temp > /usr/local/nagios/etc/hosts/$address.cfg
sed -e /host_name/{s/$/$address/} services.temp > /usr/local/nagios/etc/servers/$address.cfg
done
members=$(sed ':a N;$!b a;s/\n/\,/g' ip.txt)
echo "define hostgroup{" >> /usr/local/nagios/etc/objects/host.cfg
echo " hostgroup_name $hostgroup" >> /usr/local/nagios/etc/objects/hostgroup.cfg
echo " alias $hostgroup" >> /usr/local/nagios/etc/objects/hostgroup.cfg
echo " members $members" >> /usr/local/nagios/etc/objects/hostgroup.cfg
echo " }" >> /usr/local/nagios/etc/objects/hostgroup.cfg
exit 0
把上面三个文件放在同一目录下,然后将ip列表存入同一目录下的ip.txt文件里就可以了
Tags: 监控 nagios shell 批量脚本
通过文章的介绍,我们清楚的知道了nagios 布署配置,希望对你们有用!
评论暂时关闭