[Nagios]Nagios批量添加host的脚本

标签: nagios

Nagios一个一个添加Host真的是太麻烦了,于是写了个脚本批量添加下面是目录结构:


[root@monitor addhost]# tree
.
|-- createcfg.sh 按照list表中每行的内容创建相应名称host配置文件的脚本
|-- hosts        存放host配置文件的文件夹
|-- ips          存放host对应ip的文件,ip要与list中的名称一一对应,每次运行rename.sh会被清空
|-- list         存放host配置文件名称的文件
|-- rename.sh    更改host配置文件中的标识IP为ips列表中的ip的脚本
`-- template.cfg 模板配置文件,所有的host配置文件都是由它得来,这个很重要我的模板文件只添加了PING监控,当让你也可以添加别的服务进取。


然后是脚本中的内容:


[root@monitor addhost]# cat createcfg.sh 
#!/bin/bash
##create $host.cfg in list
for i in $(cat list)
        do
        yes | cp template.cfg ./hosts/$i.cfg
done



[root@monitor addhost]# cat rename.sh
#!/bin/bash
for HOST in $(cat list)
        do
        cat ./hosts/$HOST.cfg | sed "s/xxxxxxx/$HOST/" > ./hosts/tmp.cfg
        yes | mv ./hosts/tmp.cfg ./hosts/$HOST.cfg
            for IP in $(cat ips)  ;
                do
                        echo $host $IP
                        cat ./hosts/$HOST.cfg | sed "s/yyyyyyy/$IP/" > ./hosts/tmp.cfg
                        yes | mv ./hosts/tmp.cfg ./hosts/$HOST.cfg
                        sed -i '1d' ips
                break
            done
done
[root@monitor hosts]# cat /home/zhangky/addhost/template.cfg 
define host{
        use     linux-server
        host_name       xxxxxxx
        alias           172.30.4.126
        address         172.30.4.126
}





define service{
        use                             local-service         ; Name of service template to use
        host_name                       xxxxxxx
        service_description             PING
        check_command                   check_ping!100.0,20%!500.0,60%
        max_check_attempts 1 
        flap_detection_enabled 1
        normal_check_interval  1  
        notification_interval  5 
        notifications_enabled 0 #需求原因这里关了报警,要开报警改成1
}

搞定,后面直接把hosts目录中的文件添加到services目录中重启nagios就行啦~~~~后面会写联系人分组通知的文章,还在研究ing。。。

版权所有:《Hoiwan's 》 => 《[Nagios]Nagios批量添加host的脚本
本文地址:http://ihoiwan.com/?post=24
除非注明,文章均为 《Hoiwan's 》 原创,欢迎转载!转载请注明本文地址,谢谢。

评论:

GlennaNob
2017-06-19 04:25
[url=http://www.wowfanes.com/viewtopic.php?f=44&t=8887]Buy Isosorbide Mononitrate Australia Buy Isosorbide Mononitrate Online Eu[/url] [url=https://www.adsbexchange.com/forum/threads/buy-alphamox-online-mastercard-alphamox.396198]Buy Alphamox Online Mastercard : Alphamox[/url] [url=http://www.salutron.com/forums/forum/how-does-lorem-ipsum-betrasd]Buy Frusenex With American Express No Prescription[/url] [url=http://www.av200.org/forums/topic/mysoline-no-prior-script-online-order-mysoline-now]Online! Order Mysoline now![/url] [url=http://www.pacname.org/forums/topic/buy-cheap-zebeta-fedex-no-prescription-zebeta-online-cheap]Buy Zebeta Visa Without Prescription[/url] Cipro For Acne Vulgaris Headache Of Weaning Off Lexapro Quick Ship Viagra Cialis Levitra [url=http://www.oriflame.annarawska.pl/?option=com_k2&view=itemlist&task=user&id=230724]Buy Petcam Shipped Ups No Prescription, Money Order Petcam.[/url] [url=http://www.binaryoptions.ac/forums/topic/buy-black-cialis-online-from-canada-black-cialis-online-usa]Buy Black Cialis Online Without Dr Approval No Prescription[/url] [url=http://piamidam.org/forums/topic/buy-cialis-professional-online-visa-buy-cialis-professional-with-visa]http://piamidam.org/forums/topic/buy-cialis-professional-online-visa-buy-cialis-professional-with-visa/[/url] [url=http://projectlyme.org/forums/forum/new-forum]Buy Red Viagra Is Pepcid Safe To Take Heartburn During Pregnancy  
Ciprofloxacin Wirkung
Infection Of Casein Allergy  Seroquel Syncope Nasal Congestion . Lynne Allegra Ototoxic Doxycycline Physicians Desk Reference  Causes Gas Prevacid 30mg Drugs To Kelsey Blood Pressure Phenergan What Is Types Of Allergic Reactions 29 Dec 2012. Yerba mate is a widely-cultivated, medium-sized evergreen tree that can grow to 20 m high in the wild. Commonly, when. 4–8%. 200–400 mg. Chocolate ( Cacao seed). 0.25%. 13 mg. Main Actions (in order): stimulant. . Paxil Decreased Anxiety Metformin Dose Response Non Insulin Dependent Diabetes Mellitus Neurontin Lawsuit United Kingdom [url=]Order Diuretics Generic Lasix[/url]
[url=http://www.herballove.com/forum/buy-lopid-without-prescription-overnight-delivery-order-lopid-online]buy Lopid Online purchase Lopid without a prescription overnight delivery[/url]

发表评论: