真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

交互式添加nagios主機(jī)和服務(wù)腳本

        搭建好nagios 服務(wù)器之后,剩下的工作其實(shí)就是將欲監(jiān)控的主機(jī)和服務(wù)添加到配置文件中,這過(guò)程其實(shí)有很多重復(fù)性的工作,所以我寫(xiě)了個(gè)交互式腳本,可以一步到位。

創(chuàng)新互聯(lián)建站是一家從事企業(yè)網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、行業(yè)門(mén)戶網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)制作的專業(yè)網(wǎng)站設(shè)計(jì)公司,擁有經(jīng)驗(yàn)豐富的網(wǎng)站建設(shè)工程師和網(wǎng)頁(yè)設(shè)計(jì)人員,具備各種規(guī)模與類型網(wǎng)站建設(shè)的實(shí)力,在網(wǎng)站建設(shè)領(lǐng)域樹(shù)立了自己獨(dú)特的設(shè)計(jì)風(fēng)格。自公司成立以來(lái)曾獨(dú)立設(shè)計(jì)制作的站點(diǎn)千余家。

 

腳本思路分析:

首先分析下主機(jī)和服務(wù)的配置:

主機(jī):

define host{
        use     linux-server,hosts-pnp
        host_name       client
        alias                 client
        address         192.168.56.105
}

 

服務(wù):

define service{
        use     generic-service,services-pnp
        host_name       client
        service_description      check_load
        check_command           check_nrpe!check_load
        max_check_attempts 5
        normal_check_interval 1
}

 

注:上面紅色部分為變化的部分,其余的都是固定的。也就是說(shuō)需要將紅色部分設(shè)置成變量。

接下來(lái)的問(wèn)題就是配置服務(wù)的時(shí)候,如何一次性讀入多個(gè)服務(wù),實(shí)現(xiàn)一步到位。也就是說(shuō),我可以一次性添加多個(gè)服務(wù),而無(wú)需重復(fù)性的運(yùn)行腳本。下面我是通過(guò)數(shù)組來(lái)實(shí)現(xiàn)的。

 

腳本如下:

添加主機(jī):

#!/bin/bash
echo "Please input the infomations of the server you want to set."
read -p "hostname:" HNAME
read -p "alias:" ALIAS
read -p "IP:" IP
cat << EOF > /usr/local/nagios/etc/hosts/${HNAME}.cfg
define host{
use     linux-server,hosts-pnp
host_name       ${HNAME}
alias                  ${ALIAS}
address            ${IP}
}
EOF
service nagios reload

 

 

添加服務(wù):

#!/bin/bash
read -p "Please input your hostname :" HNAME
read -p "please input the number of the services you want to set :" n
echo "Please input the services' name :"
read -a SHELL
for ((i=0;i<=${n}-1;i++))
do
echo "${SHELL[$i]}" >> /tmp/name.txt
done
while read line
do
cat << EOF >> /usrl/local/nagios/etc/services/${HNAME}.cfg
define service{
use     generic-service,services-pnp
host_name       ${HNAME}
service_description     check_${line}
check_command           check_nrpe!check_${line}
max_check_attempts 5
normal_check_interval 1
}
EOF
echo "$line"
done < /tmp/name.txt
rm -rf /tmp/name.txt
service nagios reload

 

運(yùn)行結(jié)果如下:(注意:下面藍(lán)色部分為交互式輸入部分)

添加主機(jī):

[root@localhost nagios]# ./autochost.sh 
Please input the infomations of the server you want to set.
hostname:slave3
alias:slave3
IP:192.168.56.110
Running configuration check...done.
Reloading nagios configuration...done


[root@localhost nagios]# cat etc/hosts/slave3.cfg 
define host{
        use     linux-server,hosts-pnp
        host_name       slave3
        alias           slave3
        address         192.168.56.110
}

 

交互式添加nagios主機(jī)和服務(wù)腳本

 

添加服務(wù):

[root@localhost nagios]# ./autocservice.sh 
Please input your hostname :slave3
please input the number of the services you want to set :4
Please input the services' name :
http ssh MySQL ftp

 

[root@localhost nagios]# cat etc/services/slave3.cfg 
define service{
 use     generic-service,services-pnp
        host_name       slave3
        service_description     check_http
        check_command           check_nrpe!check_http
        max_check_attempts 5
        normal_check_interval 1
 }
define service{
 use     generic-service,services-pnp
        host_name       slave3
        service_description     check_ssh
        check_command           check_nrpe!check_ssh
        max_check_attempts 5
        normal_check_interval 1
 }
define service{
 use     generic-service,services-pnp
        host_name       slave3
        service_description     check_mysql
        check_command           check_nrpe!check_mysql
        max_check_attempts 5
        normal_check_interval 1
 }
define service{
 use     generic-service,services-pnp
        host_name       slave3
        service_description     check_ftp
        check_command           check_nrpe!check_ftp
        max_check_attempts 5
        normal_check_interval 1
 }

 

交互式添加nagios主機(jī)和服務(wù)腳本


分享文章:交互式添加nagios主機(jī)和服務(wù)腳本
轉(zhuǎn)載注明:http://weahome.cn/article/gesghp.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部