Chinaunix首页 | 论坛 | 博客
  • 博客访问: 77790
  • 博文数量: 17
  • 博客积分: 679
  • 博客等级: 上士
  • 技术积分: 178
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-15 12:31
文章分类
文章存档

2012年(3)

2011年(12)

2010年(2)

分类: LINUX

2011-12-09 19:34:51

只是添加服务及escalations.cfg,比一行行复制再改好多了了,首先要在host.cfg中把主机添加好,然后在命令行sh nagios-add-services.sh host-name services.cfg test escalation.cfg这样就会添加完成相应的服务项,每次都会备份及检测,所以不会担心添加错,可以出现问题时适当调整。代码如下:

usage(){
      echo "Usage: must four argv..."
      echo "first argv  is: host-name"
      echo "second argv is: services.cfg"
      echo "three argv  is: contactgroup"
      echo "four argv   is: escalation.cfg"
}
if [ $# -ne 4 ];then
      usage
fi
##backup###
cp $2 /tmp/$2.bak
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg > /dev/null
if [ $? -eq 0 ];then
    :
else
     echo "Nagios Config Error"
     exit 1
fi
for  i in cpu  mem  disk raid  80
  do
     echo "define service {" >> $2

     echo "host_name  $1"    >> $2

     echo "service_description  check_$i" >> $2

         if [ "$i" = "cpu" -o "$i" = "raid" -o "$i" = "mem" ];then

              echo "check_command check_nrpe!check_$i" >>$2

         elif  [ "$i" = "disk" ];then

              echo "check_command  check_nrpe!check_df" >> $2
        
         elif [ "$i" = "80" -o  "$i" = "8080" ];then
              
              echo "check_command check_tcp!$i" >> $2
         fi
     echo "contact_groups $3" >> $2
     echo "use local-service" >> $2
#     echo "normal_check_interval           20 " >> $2
#     echo "retry_check_interval            5" >> $2
#     echo "notification_interval           20" >> $2
     echo "}" >>$2
 done


###########add escalatons.cfg#############
echo "define hostescalation{" >> $4
echo "host_name $1" >> $4
echo "first_notification 4" >>$4
echo "last_notification 0" >>$4
echo "notification_interval 240" >>$4
echo "contact_groups $3" >>$4
echo "}" >> $4
echo "define serviceescalation{" >> $4
echo "host_name guanggao-yanfa-31" >> $4
echo "service_description     *">>$4
echo "first_notification 4">> $4
echo "last_notification 0">>$4
echo "notification_interval 240" >>$4
echo "contact_groups $3" >> $4
echo "}">> $4
阅读(1496) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~