由于前不久做nagios监控系统,发现在添加主机与服务的时候,每次都要打开主机和服务配合文件,并且需要修改参数,甚是麻烦,于是就想用脚本来代替这些重复性的工作,首先需要建立2个模板文件hosts.temp services.temp,2个模板文件的内容如下:
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
只要运行脚本输入自己服务器的信息,就可以在配置文件后面添加主机以及服务的配置内容了。
阅读(3785) | 评论(1) | 转发(0) |