#!/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
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。