客户端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通用应用检测插件的更多相关文章

  1. check_mk检测插件编写

    参考 Writing Checks (Introduction) Writing agent based checks The New Check API http://www2.steinkogle ...

  2. Sublime Text编辑工具带有 PEP 8 格式检测插件

    Sublime Text编辑工具带有 PEP 8 格式检测插件

  3. 浏览器特性检测插件Feature.js

    <script src="js/feature.js"></script> if (feature.webGL) { console.log("你 ...

  4. Java代码规范与质量检测插件SonarLint

    1.  SonarLint SonarLint是一个代码质量检测插件,可以帮助我们检测出代码中的坏味道 下载与安装 在需要检测的单个文件或者单个项目上右键 --> Analyze --> ...

  5. 《阿里巴巴 Java 开发规约》自动化检测插件安装及体验

    2017 开春之际,有助于提高行业编码规范化水平的<阿里巴巴 Java 开发手册>首次面世.汇聚阿里集团近万名技术精英的经验知识,这套高含金量的手册一经公开,便引起业界普遍关注和学习. 历 ...

  6. FCOS论文复现:通用物体检测算法

    摘要:本案例代码是FCOS论文复现的体验案例,此模型为FCOS论文中所提出算法在ModelArts + PyTorch框架下的实现.本代码支持FCOS + ResNet-101在MS-COCO数据集上 ...

  7. check_mk检测插件 - raid监控

    mk_raidstatus python版本 #!/usr/bin/env python # -*- encoding: utf-8; py-indent-offset: 4 -*- import s ...

  8. spring-boot | 整合通用Mabatis 分页插件PageHelper

    Mybatis通用Mapper介绍 Mybatis 通用 Mapper 极其方便的使用 Mybatis 单表的增删改查,支持单表操作,不支持通用的多表联合查询 优点: 通用 Mapper 可以极大的方 ...

  9. laravel administrator 一款通用的后台插件(PHP框架扩展)

    前几天我看了一下zend framework 2的一些官方文档,也找了一些例子,可惜所有的资料少之甚少.于是我就开始去找这国外用的比较流行的PHP框架laravel,希望能够找到其合适的例子,而且我本 ...

随机推荐

  1. Mysql Update更新错误 Error Code:1175

    Mysql 5.7,默认执行 update 语句时遇到错误提示: Error Code: 1175. You are using safe update mode and you tried to u ...

  2. [转] 最简单实现跨域的方法:使用nginx反向代理

    [From] http://blog.jobbole.com/90975/ 什么是跨域 跨域,指的是浏览器不能执行其他网站的脚本.它是由浏览器的同源策略造成的,是浏览器对javascript施加的安全 ...

  3. 【研究】Metasploit自动攻击模块

    环境:kali-linux-2017.3-vm-amd64 一.安装postgresql数据库 apt-get install postgresql apt-get install rubygems ...

  4. Shiro登录的故事

    从前,有一个subject,他有一个UsernamePasswordToken的实例,也就是token: 他准备登录,于是调用subject.login(AuthenticationToken tok ...

  5. 数据插入INSERT

    一.INSERT SELECT :将查询的数据直接插入 特点: 1.一次性插入所有查询出来的数据. 2.数据原子性,有一个失败全部失败. 3.没有指定的列加默认值或NULL,都没有就报错. 二.INS ...

  6. 小程序wxml文件引用方式

    import<!--header.wxml --> <template name="item"> <text>{{text}}</text ...

  7. Dubbo解析及原理浅析

    原文链接:https://blog.csdn.net/chao_19/article/details/51764150 一.Duboo基本概念解释 Dubbo是一种分布式服务框架. Webservic ...

  8. (转)用shell脚本实现杨辉三角的4个实例!

    概述:    中国古代数学家在数学的许多重要领域中处于遥遥领先的地位.中国古代数学史曾经有自己光辉灿烂的篇章,而杨辉三角的发现就是十分精彩的一页.杨辉三角形,是二项式系数在三角形中的一种几何排列.杨辉 ...

  9. java的访问修饰符

    Java中通过访问控制符(default,private,public,protected)来控制对类.变量.方法.构造方法的访问. 下表说明了4中修饰符的访问权限: 修饰符 当前类 同一包内 子孙类 ...

  10. OpenLayers 案例一

    序 OpenLayers 是一个专为Web GIS 客户端开发提供的JavaScript 类库包,用于实现标准格式发布的地图数据访问. 例子 <!doctype html> <htm ...