check_mk通用应用检测插件
2017-07-19 11:05
330 查看
客户端mk_tvmapp
import json filename = '/tmp/tvmapp.json' print '<<<tvmapp>>>' for a in json.load(open(filename)): print 'item_name %s' % a['item_name'] print 'timestamp %s' % a['timestamp'] print 'check_type %s' % a['check_type'] if a['check_type'] == '0': print 'status %s' % a['status'] print 'message %s' % a['message'] else: print 'unit %s' % a['unit'] print 'current_value %s' % a['current_value'] print 'threhold_value %s' % a['threhold_value'] #output <<<tvmapp>>> item_name mtq_unique_visitor timestamp 1499320801 check_type 0 status 1 message this is a status message - current status is 1 item_name mtq_page_view timestamp 1499320801 check_type 1 unit % current_value 92 threhold_value >90|<60
/tmp/tvmapp.json
[ { "check_type": "0", "item_name": "mtq_unique_visitor", "message": "this is a status message - current status is 1", "status": "1", "timestamp": "1499320801" }, { "check_type": "1", "item_name": "mtq_page_view", "current_value": "92", "threhold_value": ">90|<60", "unit": "%", "timestamp": "1499320801" } ]
服务端tvmapp
import time, re def inventory_app(info): inventory = [] for line in info: if line[0] == 'item_name': inventory.append((' '.join(line[1:]), None)) return inventory def parse_app(info): ''' data: { 'mtq_unique_visitor': { 'timestamp': '', 'check_type': '', 'status': '', 'message': '' }, 'mtq_page_view': { 'timestamp': '', 'check_type': '', 'unit': '', 'current_value': '', 'threhold_value': ''} } ''' data = {} tmp = '' for line in info: if line[0] == 'item_name': tmp = ' '.join(line[1:]) data[tmp] = {} else: data[tmp][line[0]] = ' '.join(line[1:]) return data def check_app(item, params, info): data = parse_app(info) if data[item] is None: return 2, 'The data is not exist.', [(item, 1)] elif int(time.time()) - int(data[item]['timestamp']) >= 300: return 2, 'The data is not update.', [(item, 1)] elif data[item]['check_type'] == '0': if data[item]['status'] == '0': return 0, data[item]['message'], [(item, 0)] else: return 2, data[item]['message'], [(item, 1)] elif data[item]['check_type'] == '1': exp = re.sub('([!<>]=?|=)', \ lambda x: data[item]['current_value'] + '=' + x.group(0) if x.group(0) == '=' else data[item]['current_value'] + x.group(0), data[item]['threhold_value']) \ .replace('|', ' or ').replace('&', ' and ') if eval(exp): return 0, 'threhold is %s, current value is %s%s' % (data[item]['threhold_value'], data[item]['current_value'], data[item]['unit']), [(item, int(data[item]['current_value']))] else: return 2, 'threhold is %s, current value is %s%s' % (data[item]['threhold_value'], data[item]['current_value'], data[item]['unit']), [(item, int(data[item]['current_value']))] check_info['tvmapp'] = { 'inventory_function' : inventory_app, 'check_function' : check_app, 'has_perfdata' : True, 'service_description' : 'tvmapp %s', }
相关文章推荐
- check_mk检测插件 - raid监控
- check_mk检测插件编写
- js通用方法检测浏览器是否已安装指定插件(IE与非IE通用)
- 立波广告检测:普及android手机广告插件的科普应用(souapp.com搜应用网推荐)
- check_mk自定义监控插件
- check_mk自定义监控插件监控IIS站点的性能计数器
- 一款德国的Nagios插件---Check_mk 搭建
- maven 使用 checkstyle findbugs pmd 代码覆盖率检测等插件的使用
- iOS Universal Framework Mk 7 Xcode 4 的项目模板用来构建通用的 iOS 应用框架。
- 自定义check_mk监控插件过程中遇到的问题1
- check_mk插件 redis
- 安全检测Java Web应用网站漏洞(上)
- 通用快速检测邮件故障思路方法(三)
- C#中检测某个类(方法、程序集等各种部分)是否应用了指定的特性以及对特性的一些简单操作
- [RK3399][Android7.1] 调试笔记 --- 检测应用是32还是64位方法
- subline应用之常用插件
- 8款迷人的jQuery/CSS3 3D应用插件
- iOS 应用版本检测更新
- 朴素贝叶斯应用之语种检测
- jquery.query.js 插件(示例及简单应用)