客户端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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类