因为前不久作nagios监控系统,发如今添加主机与服务的时候,每次都要打开主机和服务配合文件,而且须要修改参数,甚是麻烦,因而就想用脚原本代替这些重复性的工做,首先须要创建2个模板文件hosts.temp services.temp,2个模板文件的内容以下:ios
hosts.temp 的内容:
define host {
host_name
alias
address
contact_groups sagroup
process_perf_data 1
check_command check-host-alive
max_check_attempts 10
notification_interval 10
notification_period 24x7
notification_options d,u,r
}
services.temp的内容以下:
define service {
host_name
service_description
check_period 24x7
max_check_attempts 10
normal_check_interval 10
retry_check_interval 3
contact_groups sagroup
process_perf_data 1
notification_interval 3
notification_period 24x7
notification_options w,u,c,r
check_command
}
注意:模板里面的参数能够自行添加和修改。
写了2个脚本,addhost.sh addservice.sh ,一个是添加主机,一个是添加服务
addhost.sh的内容以下:
#!/bin/bash
echo "please input host_name: "
read host_name
echo "please input alias: "
read alias
echo "please input address: "
read address
sed -e /host_name/{s/$/$host_name/} -e /alias/{s/$/$alias/} -e /address/{s/$/$address/} hosts.temp>>hosts.cfg
addservice.sh的内容以下:
#!/bin/bash
echo "please input host_name: "
read host_name
echo "please input service_description "
read service_description
echo "please input check_command "
read check_command
sed -e /host_name/{s/$/$host_name/} -e /service_description/{s/$/$service_description/} -e /check_command/{s/$/$check_command/} services.temp>>services.cfg
只要运行脚本输入本身服务器的信息,就能够在配置文件后面添加主机以及服务的配置内容了。