關於nagios監控系統添加主機和服務腳本

 因爲前不久作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
 
只要運行腳本輸入本身服務器的信息,就能夠在配置文件後面添加主機以及服務的配置內容了。
相關文章
相關標籤/搜索