nagios 批量添加监控主机

发布时间:2020-06-09 05:09:00 作者:xbzy77
来源:网络 阅读:873

#!/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


推荐阅读:
  1. nagios监控远端主机
  2. nagios 监控自身

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

nagios 批量添加

上一篇:GEO组织及数据

下一篇:OSPF多区域设置

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》