Nagios自定义扩展
2015-11-04 19:00
323 查看
原理:监控端通过check_nrpe把要监控的指令发送给被监控端,被监控端在本机执行监控任务,并把执行的结果发送回监控端。
View Code
-------------------------------------------------------------------------------------------------------
查看配置文件 template.cfg,是否为主动检测模式
# -*- coding: utf-8 -*- #!/usr/bin/python import mmap import os import sys import getopt def usage(): print """ check_log is a Nagios monitor logs Script Usage: check_log [-h|--help][-l|--log][-s|--string][-w|warning][-c|critical] Options: --help|-h) check_log help. --log|-l) sets log file path. --string|-s) sets monitor Keywords. --warning|-w) sets Keywords quantity.Default is: off --critical|-c) sets Keywords quantity.Default is: off example: ./check_log -l /var/log/nginx.log -s "502 Bad Gateway" -w 5 -c 10 """ sys.exit(3) try: options,args = getopt.getopt(sys.argv[1:],"hl:s:w:c:",["--help","log=","string=","warning=","critical="]) except getopt.GetoptError: usage() for n,v in options: if n in ("-h","--help"): usage() if n in ("-l","--log"): log = v if n in ("-s","--string"): string = v if n in ("-w","--warning"): warning = v if n in ("-c","--critical"): critical = v if 'log' in dir() and 'string' in dir(): try: file = open(log,"r+") size = os.path.getsize(log) data = mmap.mmap(file.fileno(),size) # 用了mmap模块的功能! text = data.read(-1) counts = text.count(string) counts = str(counts) data.close() file.close() except IOError: print "No such file or directory:"+log else: usage() if 'warning' in dir() and 'critical' in dir(): if warning < critical: if counts >= warning and counts < critical: print 'WARNING - %s views %s' % (string,counts) sys.exit(2) elif counts >= critical: print 'CRITICAL - %s views %s' % (string,counts) sys.exit(1) else: print 'OK - %s views %s' % (string,counts) sys.exit(0) else: print "Must critical > warning" sys.exit(0) else: print 'OK - %s views %s' % (string,counts) sys.exit(0)
View Code
command[check_mylog]=/usr/bin/python /usr/local/nagios/libexec/check_mylog -l /var/logs/nginx.log -s "No such file or directory" -w 2 -c 5
-------------------------------------------------------------------------------------------------------
查看配置文件 template.cfg,是否为主动检测模式
define service{ name passive_service use generic-service max_check_attempts 1 active_checks_enabled 0 #(关闭主动检测) passive_checks_enabled 1 #(开启被动检测) normal_check_interval 5 retry_check_interval 1 check_freshness 1 # (开启强制刷新) notifications_enabled 1 notification_interval 5 notification_period 24x7 contact_groups admins register 0 #(必须) }
相关文章推荐
- iOS替换字符串中的分号为换行符
- iOS开发日常安全防护(一)
- Git 使用规范流程
- iOS开发中邮箱,电话号码,身份证,密码,昵称正则表达式验证
- 正则表达式在IOS中的应用及IOS中三种正则表达式的使用与比较
- iOS 应用发布流程
- 致歉
- IOS申请发布证书-图文详解
- KVC与KVO
- iOS申请证书,Certificates, Identifiers &Profiles 简介
- iOS "此证书由未知颁发机构签名"此问题的解决方法
- iOS 导出 ipa 包时 三个选项的意义
- 芒果iOS开发之NSComparisonResult比较结果
- 如何在xcode7上打包越狱系统可用的ipa文件
- iOS实现多种语言具体步骤
- iOS开发笔记--关于 @synchronized,这儿比你想知道的还要多
- 建立多人协作git仓库/git 仓库权限控制(SSH)
- 记录一些优秀的iOS第三方框架
- IOS @符号
- iOS 修改状态栏颜色