您好,登錄后才能下訂單哦!
#!/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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。