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
本文出自 “xbzy” 博客,请务必保留此出处http://3861088.blog.51cto.com/3851088/1435241
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。