做nagios监控系统,发现在添加主机与服务的时候,每次都要打开主机和服务配合文件,且需要修改参数,于是就想用脚本来代替这些重复性的工作。
复制代码代码如下:
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 }
注意:模板里面的参数可以自行添加和修改。
复制代码代码如下:
#!/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 只要运行脚本输入自己服务器的信息,就可以在配置文件后面添加主机以及服务的配置内容了。 (责任编辑:IT) |