nagios批量添加监控主机-创新互联
#!/bin/bash
主要从事网页设计、PC网站建设(电脑版网站建设)、wap网站建设(手机版网站建设)、响应式网站开发、程序开发、微网站、微信小程序等,凭借多年来在互联网的打拼,我们在互联网网站建设行业积累了丰富的网站制作、成都网站设计、网络营销经验,集策划、开发、设计、营销、管理等多方位专业化运作于一体,具备承接不同规模与类型的建设项目的能力。#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
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
分享题目:nagios批量添加监控主机-创新互联
网站网址:http://ybzwz.com/article/dposci.html