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