Nagios Bulk Add monitoring host

Source: Internet
Author: User

#!/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 $; The name of the HostGroup

Alias $; 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 $ (such as Shanghai-jj_host) '

Exit 1

Else

Addfun $

Fi


This article is from the "Xbzy" blog, make sure to keep this source http://3861088.blog.51cto.com/3851088/1435241

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.