check_mk检测插件 - raid监控
mk_raidstatus
python版本
#!/usr/bin/env python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
import subprocess, re
def cfggen(): # 192.168.48.116
command = ['/opt/raid/cfggen 0 DISPLAY |egrep \'Controller type|Volume ID|Status of volume|RAID level|Size|Physical hard disks|Target ID|State|Model Number\'']
proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, error = proc.communicate()
print '<<<raidstatus>>>'
print 'cfggen'
print out
def megacli64(): # 10.0.120.196, 10.20.10.237, 10.160.1.211
command = ['/opt/raid/MegaCli64 -ShowSummary -a0 -NoLog |egrep \'ProductName|Status|Connector|Product Id|State|Virtual drive|Size|State|RAID Level\'']
proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, error = proc.communicate()
print '<<<raidstatus>>>'
print 'megacli64'
print out
def sas2ircu(): # 10.0.120.207, 10.160.1.36
command = ['/opt/raid/sas2ircu 0 DISPLAY |egrep \'Controller type|Volume ID|Status of volume|RAID level|Size|Slot #|State|Model Number\'']
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, error = proc.communicate()
print '<<<raidstatus>>>'
print 'sas2ircu'
print out
def check_model():
command = ['lspci |grep -Po \'SAS\s*\d+\' |sed -e \'s/ //g\'']
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, error = proc.communicate()
line = ' '.join(out.split())
m = re.match(r'(.*)(SAS\s*\d+)(.*)', line)
model = m.group(2).strip()
if model in ['SAS1068']:
cfggen()
elif model in ['SAS1078', 'SAS2108', 'SAS2208', 'SAS9240']:
megacli64()
elif model in ['SAS2008', 'SAS2308']:
sas2ircu()
if __name__ == '__main__':
check_model()
bash版本
#!/bin/bash
bin_path='/opt/raid'
model=$(lspci |grep -Po 'SAS\s*\d+'|sed -e 's/ //g')
case $model in
'SAS1068' )
echo '<<<raidstatus>>>'
echo 'cfggen'
$bin_path/cfggen 0 DISPLAY |egrep 'Controller type|Volume ID|Status of volume|RAID level|Size|Physical hard disks|Target ID|State|Model Number'
;;
'SAS1078'|'SAS2108'|'SAS2208'|'SAS9240' )
echo '<<<raidstatus>>>'
echo 'megacli64'
$bin_path/MegaCli64 -ShowSummary -a0 -NoLog |egrep 'ProductName|Status|Connector|Product Id|State|Virtual drive|Size|State|RAID Level'
;;
'SAS2008'|'SAS2308' )
echo '<<<raidstatus>>>'
echo 'sas2ircu'
$bin_path/sas2ircu 0 DISPLAY |egrep 'Controller type|Volume ID|Status of volume|RAID level|Size|Slot #|State|Model Number'
;;
esac
exit 0
raidstatus
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# output
'''
<<<raidstatus>>>
cfggen
Controller type : SAS1068
Volume ID : 0
Status of volume : Okay (OKY)
RAID level : 1
Size (in MB) : 285568
Physical hard disks (Target ID) : 9 1
Target ID : 1
State : Online (ONL)
Size (in MB)/(in sectors) : 286102/585937500
Model Number : ST3300657SS
Target ID : 8
State : Standby (SBY)
Model Number : BACKPLANE
Target ID : 9
State : Online (ONL)
Size (in MB)/(in sectors) : 286102/585937500
Model Number : ST3300657SS
'''
'''
<<<raidstatus>>>
megacli64
ProductName : PERC H710 Mini(Bus 0, Dev 0)
Status : Optimal
Status : Healthy
Product Id : BP12G+EXP
Status : OK
Connector : 00<Internal><Encl Pos 1 >: Slot 0
Product Id : ST2000VN000-1H31
State : Online
Power State : Active
Connector : 00<Internal><Encl Pos 1 >: Slot 1
Product Id : ST2000VN000-1H31
State : Online
Power State : Active
Connector : 00<Internal><Encl Pos 1 >: Slot 2
Product Id : ST2000VN000-1H31
State : Online
Power State : Active
Connector : 00<Internal><Encl Pos 1 >: Slot 3
Product Id : ST2000VN000-1H31
State : Online
Power State : Active
Connector : 00<Internal><Encl Pos 1 >: Slot 4
Product Id : ST2000VN000-1H31
State : Online
Power State : Active
Connector : 00<Internal><Encl Pos 1 >: Slot 5
Product Id : ST2000VN000-1H31
State : Online
Power State : Active
Connector : 00<Internal><Encl Pos 1 >: Slot 6
Product Id : ST2000VN000-1H31
State : Online
Power State : Active
Connector : 00<Internal><Encl Pos 1 >: Slot 7
Product Id : ST2000VN000-1H31
State : Online
Power State : Active
Connector : 00<Internal><Encl Pos 1 >: Slot 8
Product Id : ST2000VN000-1H31
State : Online
Power State : Active
Connector : 00<Internal><Encl Pos 1 >: Slot 9
Product Id : ST2000VN000-1H31
State : Online
Power State : Active
Connector : 00<Internal><Encl Pos 1 >: Slot 10
Product Id : ST2000VN000-1H31
State : Online
Power State : Active
Connector : 00<Internal><Encl Pos 1 >: Slot 11
Product Id : ST2000VN000-1H31
State : Online
Power State : Active
Connector : 00<Internal><Encl Pos 1 >: Slot 12
Product Id : ST300MM0006
State : Online
Power State : Active
Connector : 00<Internal><Encl Pos 1 >: Slot 13
Product Id : ST300MM0006
State : Online
Power State : Active
Connector : 00<Internal>: Slot 0
Product Id : SAS2 EXP BP
State : Unconfigured Good
Power State : Active
Virtual drive : Target Id 0 ,VD name Virtual Disk 0
Size : 278.875 GB
State : Optimal
RAID Level : 1
Virtual drive : Target Id 1 ,VD name Virtual Disk 1
Size : 10.913 TB
State : Optimal
RAID Level : 10
'''
'''
<<<raid>>>
<<<raidstatus>>>
sas2ircu
Controller type : SAS2008
Volume ID : 323
Status of volume : Okay (OKY)
RAID level : RAID1
Size (in MB) : 1906394
Slot # : 5
State : Optimal (OPT)
Size (in MB)/(in sectors) : 1907729/3907029167
Model Number : ST32000645NS
Slot # : 6
State : Optimal (OPT)
Size (in MB)/(in sectors) : 1907729/3907029167
Model Number : ST32000645NS
'''
# the inventory function
def inventory_raidstatus(info):
#print info
inventory = []
inventory.append((None,None))
return inventory
def parse_cfggen(info):
'''
controller: SAS1068E
vdisks:
[
{'status': 'Okay', 'disk': '9 1', 'size': '285568MB', 'id': '0', 'level': '1'}
]
pdisks
[
{'status': 'Online', 'model': 'ST3300657SS', 'id': '1'},
{'status': 'Standby', 'model': 'BACKPLANE', 'id': '8'},
{'status': 'Online', 'model': 'ST3300657SS', 'id': '9'}
]
'''
vdisks = []
pdisks = []
vd = {}
pd = {}
for line in info:
if line[0] == 'Controller':
controller = line[3]
continue
if line[0] == 'Volume':
vd['id'] = line[3]
continue
if line[0] == 'Status':
vd['status'] = line[4]
continue
if line[0] == 'RAID':
vd['level'] = line[3]
continue
if line[0] == 'Size':
vd['size'] = line[4] + 'MB'
continue
if line[0] == 'Physical':
vd['disk'] = ' '.join(line[6:])
vdisks.append(vd)
vd = {}
continue
if line[0] == 'Target':
pd['id'] = line[3]
continue
if line[0] == 'State':
pd['status'] = line[2]
if line[0] == 'Model':
pd['model'] = line[3]
pdisks.append(pd)
pd = {}
continue
return controller, vdisks, pdisks
def parse_megacli64(info):
'''
controller: 'PERC H710'
vdisks:
[
{'status': 'Optimal', 'level': '1', 'id': '0', 'size': '278.875GB'},
{'status': 'Optimal', 'level': '10', 'id': '1', 'size': '10.913TB'}
]
pdisks
[
{'status': 'Online', 'model': 'ST2000VN000-1H31', 'id': '0'},
{'status': 'Online', 'model': 'ST2000VN000-1H31', 'id': '1'},
{'status': 'Online', 'model': 'ST2000VN000-1H31', 'id': '2'},
{'status': 'Online', 'model': 'ST2000VN000-1H31', 'id': '3'},
{'status': 'Online', 'model': 'ST2000VN000-1H31', 'id': '4'},
{'status': 'Online', 'model': 'ST2000VN000-1H31', 'id': '5'},
{'status': 'Online', 'model': 'ST2000VN000-1H31', 'id': '6'},
{'status': 'Online', 'model': 'ST2000VN000-1H31', 'id': '7'},
{'status': 'Online', 'model': 'ST2000VN000-1H31', 'id': '8'},
{'status': 'Online', 'model': 'ST2000VN000-1H31', 'id': '9'},
{'status': 'Online', 'model': 'ST2000VN000-1H31', 'id': '10'},
{'status': 'Online', 'model': 'ST2000VN000-1H31', 'id': '11'},
{'status': 'Online', 'model': 'ST300MM0006', 'id': '12'},
{'status': 'Online', 'model': 'ST300MM0006', 'id': '13'}
]
'''
vdisks = []
pdisks = []
vd = {}
pd = {}
for line in info:
if line[0] == 'ProductName':
controller = ' '.join(line[2:])
continue
if line[0] == 'Connector' and len(line) == 8:
pd['id'] = line[7]
continue
if line[0] == 'Product' and len(line) ==4:
pd['model'] = line[3]
continue
if line[0] == 'State' and len(line) == 3 and line[2] not in ['Optimal', 'Degraded']:
pd['status'] = line[2]
pdisks.append(pd)
pd = {}
continue
if line[0] == 'Virtual':
vd['id'] = line[5]
continue
if line[0] == 'Size':
vd['size'] = ''.join(line[2:4])
continue
if line[0] == 'State':
vd['status'] = line[2]
continue
if line[0] == 'RAID':
vd['level'] = line[3]
vdisks.append(vd)
vd = {}
continue
return controller, vdisks, pdisks
def parse_sas2ircu(info):
'''
controller: SAS2008
vdisks:
[
{'status': 'Okay', 'size': '1906394MB', 'id': '323', 'level': 'RAID1'}
]
pdisks
[
{'status': 'Optimal', 'model': 'ST32000645NS', 'id': '5'},
{'status': 'Optimal', 'model': 'ST32000645NS', 'id': '6'}
]
'''
vdisks = []
pdisks = []
vd = {}
pd = {}
for line in info:
if line[0] == 'Controller':
controller = line[3]
continue
if line[0] == 'Volume':
vd['id'] = line[3]
continue
if line[0] == 'Status':
vd['status'] = line[4]
continue
if line[0] == 'RAID':
vd['level'] = line[3]
continue
if line[0] == 'Size' and len(line) == 5:
vd['size'] = line[4] + 'MB'
vdisks.append(vd)
vd = {}
continue
if line[0] == 'Slot':
pd['id'] = line[3]
continue
if line[0] == 'State':
pd['status'] = line[2]
if line[0] == 'Model':
pd['model'] = line[3]
pdisks.append(pd)
pd = {}
continue
return controller, vdisks, pdisks
# the check function
def check_raidstatus(item, params, info):
# cfggen handle
if info[0][0] == 'cfggen':
controller, vdisks, pdisks = parse_cfggen(info)
if controller is None and len(vdisks) == 0 and len(pdisks) == 0:
status = 3
else:
status = 0
pids = []
vdinfo = []
pdinfo = []
for vdisk in vdisks:
pids += vdisk['disk'].split(' ')
if vdisk['status'] != 'Okay':
status = 2
vdinfo.append('vd' + vdisk['id'] + '(raid-' + vdisk['level'] + ', ' + vdisk['size'] + '): ' + vdisk['status'])
for pdisk in pdisks:
if pdisk['status'] not in ['Online', 'Standby'] and pdisk['id'] in pids:
pdinfo.append('pd' + pdisk['id'] + '(' + pdisk['model'] +'): ' + pdisk['status'])
# megacli64 handle
elif info[0][0] == 'megacli64':
controller, vdisks, pdisks = parse_megacli64(info)
if controller is None and len(vdisks) == 0 and len(pdisks) == 0:
status = 3
else:
status = 0
vdinfo = []
pdinfo = []
for vdisk in vdisks:
if vdisk['status'] != 'Optimal':
status = 2
vdinfo.append('VD' + vdisk['id'] + '(raid-' + vdisk['level'] + ', ' + vdisk['size'] + '): ' + vdisk['status'])
for pdisk in pdisks:
if pdisk['status'] != 'Online':
pdinfo.append('PD' + pdisk['id'] + '(' + pdisk['model'] +'): ' + pdisk['status'])
# sas2ircu handle
elif info[0][0] == 'sas2ircu':
controller, vdisks, pdisks = parse_sas2ircu(info)
if controller is None and len(vdisks) == 0 and len(pdisks) == 0:
status = 3
else:
status = 0
pids = []
vdinfo = []
pdinfo = []
for vdisk in vdisks:
if vdisk['status'] != 'Okay':
status = 2
vdinfo.append('vd' + vdisk['id'] + '(' + vdisk['level'] + ', ' + vdisk['size'] + '): ' + vdisk['status'])
for pdisk in pdisks:
if pdisk['status'] not in ['Optimal'] and pdisk['id'] in pids:
pdinfo.append('pd' + pdisk['id'] + '(' + pdisk['model'] +'): ' + pdisk['status'])
# check status & output
if status == 0:
if info[0][0] in ['cfggen']:
return (status, 'Controller Type: %s, Virtual Disks: %d, Physical Disks: %d' % (controller, len(vdisks), len(pids)))
else:
return (status, 'Controller Type: %s, Virtual Disks: %d, Physical Disks: %d' % (controller, len(vdisks), len(pdisks)))
elif status == 2:
return (status, 'Controller Type: %s, %s, %s' % (controller, ', '.join(vdinfo), ', '.join(pdinfo)))
else:
return (3, 'invalid check output')
# declare the check to Check_MK
check_info["raidstatus"] = {
'check_function': check_raidstatus,
'inventory_function': inventory_raidstatus,
'service_description': 'raidstatus',
'has_perfdata': False,
}
check_mk检测插件 - raid监控的更多相关文章
- check_mk检测插件编写
参考 Writing Checks (Introduction) Writing agent based checks The New Check API http://www2.steinkogle ...
- zabbix通过第三方插件percona监控mysql数据库
zabbix通过第三方插件percona监控mysql数据库 ...
- Sublime Text编辑工具带有 PEP 8 格式检测插件
Sublime Text编辑工具带有 PEP 8 格式检测插件
- 浏览器特性检测插件Feature.js
<script src="js/feature.js"></script> if (feature.webGL) { console.log("你 ...
- Java代码规范与质量检测插件SonarLint
1. SonarLint SonarLint是一个代码质量检测插件,可以帮助我们检测出代码中的坏味道 下载与安装 在需要检测的单个文件或者单个项目上右键 --> Analyze --> ...
- zabbix3.0.4使用percona-monitoring-plugins插件来监控mysql5.6的详细实现过程
zabbix3.0.4使用percona-monitoring-plugins插件来监控mysql5.6的详细实现过程 因为Zabbix自带的MySQL监控没有提供可以直接使用的Key,所以一般不采用 ...
- 《阿里巴巴 Java 开发规约》自动化检测插件安装及体验
2017 开春之际,有助于提高行业编码规范化水平的<阿里巴巴 Java 开发手册>首次面世.汇聚阿里集团近万名技术精英的经验知识,这套高含金量的手册一经公开,便引起业界普遍关注和学习. 历 ...
- check_mk通用应用检测插件
客户端mk_tvmapp import json filename = '/tmp/tvmapp.json' print '<<<tvmapp>>>' for a ...
- 基于PLC-C#串口通讯,温度检测和转速监控的c#/.Net实现。
我司为五金加工企业,其中有一条喷涂车间和流水线,客户要求能实时监控炉温温度.流水线速,并设置上下限值,达到上下限时报警. 开始考虑过USB的温度采集器,但是却没有找到带USB的光电开关,并且线路长度受 ...
随机推荐
- hdu6438 Buy and Resell 买卖物品 ccpc网络赛 贪心
题目传送门 题目描述: 有n座城市,每座城市都可以对一个物品进行一次的买进或者卖出,可以同时拥有多个物品,计算利润最大值,并且交易次数要最少.(买入卖出算两次操作) 思路: 建立两个小根堆 优先队列, ...
- 2015苏州大学ACM-ICPC集训队选拔赛(1) 1007
连通图 Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other) Total Submissio ...
- Linux系统lvm管理
pv: 物理卷,被pv命令处理过的物理分区vg:物理卷组 被组装到一起的物理卷pe: 物理扩展 lvm设备的最小存储单元 lvm是pe的整数倍lvm:逻辑卷 ...
- http协议&接口规范&接口测试入门
http协议 请求: 请求行:请求方法.url(协议名://ip;端口/工程名/资源路径).协议版本 请求头 :键值对 请求正文 响应: 响应行:协议版本.响应状态码.响应状态码描述 响应头 :键值对 ...
- python3 enumerate()函数笔记
d={"A":"a","B":"b","C":"c","D" ...
- 单点登录-JWT(Json Web Tokens)
来自:http://www.ruanyifeng.com/blog/2018/07/json_web_token-tutorial.html 1.跨域认证 1.用户向服务器发送用户名和密码. 2.服务 ...
- Day03 知识点
一.单行注释与多行注释 # 用来标记不运行的程序 pycharm 快捷键 ctrl+/ 可以在程序上方 也可以在程序后面 (PEP8) 多行注释 用三引号,一般推荐三双引号来做注释. 二.数据类型 ( ...
- hdu 6288(二分法加精度处理问题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6288 题意:给出a,b,k,n可满足(n^a)*(⌈log2n⌉)^b<=k ,求最大的n值三个 ...
- 查看CPU和内存,用机器指令和汇编指令编程【Debug模式】
命令 作用 举例 R 查看,改变CPU寄存器的内容 查看:r 改写:r ax D 查看内存中的内容 d 1000:0 f E 改写内存中的内容 e 1000:0 f U 将内存中的机器指令翻译成汇编指 ...
- python—datetime time 模板学习
写在前面:本人在学习此内容是通过 https://www.cnblogs.com/pycode/p/date.html 文章学习! 时间模块——time python 中时间表示方法有:时间戳_:格式 ...