Chinaunix首页 | 论坛 | 博客
  • 博客访问: 310313
  • 博文数量: 50
  • 博客积分: 494
  • 博客等级: 下士
  • 技术积分: 1045
  • 用 户 组: 普通用户
  • 注册时间: 2012-11-06 16:49
文章分类

全部博文(50)

文章存档

2016年(1)

2014年(4)

2013年(29)

2012年(16)

分类: 系统运维

2013-04-07 16:16:01

原文地址:nagios 监控log文件 作者:左手_wanggy

插件脚本:(file.sh
说明:返回值。0为正常、1为警告、2为紧急。格式:file.sh –w 2 –c 3

将该脚本保存至/usr/local/nagios/libexec目录下,此时file.sh成为一个可调用的命令。如何引用?我们再次回顾下命令引用方式:
首先:我们需要在commands.cfg里面定义该命令的引用格式:本例如下
# 'check_monitor_file' command definition  for wanggy 2013-03-13
define command{
        command_name    check_file
        command_line    $USER1$/check_monitor_file.sh  -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$
        }  

其次:我们需要添加一监控对像

define service{
        host_name               192.168.1.9
        service_description     monitor_line_file
        check_command           check_file!1!1

        max_check_attempts      5  
        normal_check_interval   4  
        retry_check_interval    1  
        check_period            24x7
        notification_interval   4  
        notification_period     24x7
        notification_options    w,u,c,r
        contact_groups          admins
        }  

最后效果:


附插件脚本:

 点击(此处)折叠或打开

  1. #!/bin/bash
  2. #**************************************#
  3. #for wanggy 2013-03-13 15:03 #
  4. #采用shell 插件监控文件内容 #
  5. #格式必须符合USAGE定义 #
  6. #note: #
  7. #monitor.cfg为监控原文件 #
  8. #$err_count判断异常个数(=1) #
  9. #本例监控名为monitor_line_file在.9上 #
  10. #对应command查看commands.cfg配置 #
  11. #**************************************#
  12. cd /usr/local/nagios/libexec
  13. USAGE="`basename $0` [-w|--warning] [-c|--critical]"
  14. warning=""
  15. critical=""
  16. #STATE_OK=0
  17. #STATE_WARNING=1
  18. #STATE_CRITICAL=2
  19. # read input
  20. if [[ $# -lt 4 ]]
  21. then
  22. echo ""
  23. echo "Wrong Syntax: `basename $0` $*"
  24. echo ""
  25. echo "Usage: $USAGE"
  26. echo ""
  27. exit 0
  28. fi
  29. while [[ $# -gt 0 ]]
  30. do
  31. case "$1" in
  32. -w|--warning)
  33. shift
  34. warning=$1
  35. ;;
  36. -c|--critical)
  37. shift
  38. critical=$1
  39. ;;
  40. esac
  41. shift
  42. done
  43. #echo $warning
  44. #echo $critical
  45. grep "=1" monitor.cfg >err_count_file
  46. err_count=`wc -l err_count_file |awk '{print$1}'`
  47. #本例主判断critical状态跟ok状态
  48. if [ $err_count -ge $critical ];then
  49. err_monitor=`cat err_count_file`
  50. echo -n "告警!!!!共有:$err_count条链路出现异常.请确认!!!!"
  51. echo $err_monitor
  52. exit 2
  53. else
  54. list_monitor=`cat monitor.cfg`
  55. echo -n "全部链路正常!!"
  56. #在nagios显示内容信息
  57. echo $list_monitor
  58. exit 0
  59. fi



 
阅读(993) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~