nagios批量添加监控主机
#!/bin/bash
公司主营业务:成都网站设计、成都网站建设、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。创新互联建站是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。创新互联建站推出雨湖免费做网站回馈大家。
#by xbzy
#QQ:465667803
#add host to nagios
Addfun()
{
for ip in `cat ips.txt`
do
echo -e "define host{
use linux-server
host_name $ip-record
alias $ip
address $ip
}" >>/usr/local/nagios/etc/objects/$1.cfg
done
echo -e "define hostgroup{
hostgroup_name $1 ; The name of the hostgroup
alias $1 ; Long name of the group
members localhost
}" >> /usr/local/nagios/etc/objects/$1.cfg
echo -e "# Define a service to "ping" the local machine
#define service{
# use local-service ; Name of service template to use
# host_name localhost
# service_description PING
# check_command check_ping!100.0,20%!500.0,60%
# }
define service{
use local-service ; Name of service template to use
host_name localhost
service_description alive
check_command check-host-alive
}
define service{
use local-service ; Name of service template to use
host_name localhost
service_description record_tcp_port
check_command check_tcp!8080
}" >> /usr/local/nagios/etc/objects/$1.cfg
for i in `cat ips.txt`
do
sed -i "/localhost/s/$/,$i-record/" /usr/local/nagios/etc/objects/$1.cfg
done
sed -i 's/localhost,//' /usr/local/nagios/etc/objects/$1.cfg
echo "cfg_file=/usr/local/nagios/etc/objects/$1.cfg" >> /usr/local/nagios/etc/nagios.cfg
}
if [ $# -ne 1 ]
then
echo 'Error , please use $1 (such as shanghai-jj_host)'
exit 1
else
Addfun $1
fi
新闻名称:nagios批量添加监控主机
转载来源:http://azwzsj.com/article/gopics.html