参考

Writing Checks (Introduction)

Writing agent based checks

The New Check API

http://www2.steinkogler.org/steinkogler.org/2016/08/21/check-mk-write-your-own-check/

https://github.com/leibler/check_mk-sas2ircu/blob/master/agent/plugins/sas2ircu

agent/plugins/sas2ircu

尽量使用bash编写客户端插件

# example output of this check:
# <<<sas2ircu>>>
# volume 0 79 okay_(oky) 0d9383a8258e32ac raid1 1907200
# disk 0 0 optimal_(opt) 5000c50-0-569e-8a83 seagate st2000nm0023 z1x065wj sas sas_hdd
# disk 0 1 optimal_(opt) 5000c50-0-569f-2021 seagate st2000nm0023 z1x0j231 sas sas_hdd
#
# each line starts with the type ('disk' or 'volume')
# the 2nd column is the controller id (first controller=0, second controller=1, ...)
# the 3rd column for volume is the volume id and for disks is the slot number
# the 4th column is the state
# the order of the fields is configured in the arrays 'volumeOutputOrder' and 'diskOutputOrder' # 标签,使用<<< ... >>>引用,与服务端的检测插件名称匹配
# 信息部分,处理为行列二维列表,用于服务端接收 import subprocess
import sys # raidCommand is the cli utility name which is executed to get the information
raidCommand = "sas2ircu" # volumeAttrs is a list of key:value pairs where key is the volume fieldname of the output from sas2ircu cli utility and value is the internal name used in *OutputOrder list. use lower case letters!
volumeAttrs = { 'volume id': 'volumeid', 'status of volume': 'status', 'volume wwid': 'wwid', 'raid level': 'raid', 'size (in mb)': 'size' }
# diskAttrs is a list of key:value pairs where key is the disk fieldname of the output from sas2ircu cli utility and value is the internal name used in *OutputOrder list. use lower case letters!
diskAttrs = { 'slot #': 'slot', 'state': 'status', 'sas address': 'sasaddr', 'manufacturer': 'manufacturer', 'model number': 'model', 'serial no': 'serial', 'protocol': 'protocol', 'drive type': 'type' } # volumeOutputOrder is a list of the internal names for volumes used for the output in the given order
volumeOutputOrder = [ 'controller', 'volumeid', 'status', 'wwid', 'raid', 'size' ]
# diskOutputOrder is a list of the internal names for disks used for the output in the given order
diskOutputOrder = [ 'controller', 'slot', 'status', 'sasaddr', 'manufacturer', 'model', 'serial', 'protocol', 'type' ] def returnVolumeTpl():
volumeTpl = { 'controller': '-1' }
for name, code in volumeAttrs.items():
volumeTpl[code] = '-'
return volumeTpl def returnDiskTpl():
diskTpl = { 'controller': '-1' }
for name, code in diskAttrs.items():
diskTpl[code] = '-'
return diskTpl # checkNextController is a flag if current controller (int 0-255) is present and so the next controller id should be checked
checkNextController = True
listVolumes = []
listDisks = [] for i in range( 0, 255 ):
if checkNextController:
cmd = subprocess.Popen( raidCommand+" "+str(i)+" DISPLAY", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
mode = "unknown"
volumeNr = 0
diskNr = 0
volume = returnVolumeTpl()
disk = returnDiskTpl()
for line in cmd.stdout:
line = line.strip().lower()
if "sas2ircu: not found" in line:
checkNextController = False
break
checkIfPresentLine = "SAS2IRCU: No Controller Found at index "+str(i)+"."
checkIfPresentLine = checkIfPresentLine.lower()
if line == checkIfPresentLine:
checkNextController = False
break
parts = map( str.strip, line.split(":") )
if parts[0] == "sas2ircu" or parts[0].startswith("------") or parts[0].startswith("ir volume") or len(parts[0]) == 0:
if mode == "volume":
if volume['controller'] != "-1":
listVolumes.append(volume)
volume = returnVolumeTpl()
if mode == "harddisk":
if disk['controller'] != "-1":
listDisks.append(disk)
disk = returnDiskTpl()
if parts[0] == "volume id":
volume['controller'] = str(i)
volume['volume'] = parts[1]
mode = "volume"
if parts[0] == "device is a hard disk":
disk['controller'] = str(i)
mode = "harddisk"
if mode == "volume" and len(parts) > 1:
if parts[0] in volumeAttrs:
volume[volumeAttrs[parts[0]]] = parts[1].replace( " ", "_" )
if mode == "harddisk" and len(parts) > 1:
if parts[0] in diskAttrs:
disk[diskAttrs[parts[0]]] = parts[1].replace( " ", "_" )
else:
break # output the checks in order of volumeOutputOrder and diskOutputOrder if len(listVolumes) > 0 or len(listDisks) > 0:
sys.stdout.write( "<<<sas2ircu>>>\n" )
for volume in listVolumes:
sys.stdout.write( "volume " )
for name in volumeOutputOrder:
sys.stdout.write( volume[name]+" " )
sys.stdout.write( "\n" )
for disk in listDisks:
sys.stdout.write( "disk " )
for name in diskOutputOrder:
sys.stdout.write( disk[name]+" " )
sys.stdout.write( "\n" ) sys.stdout.flush()

check_mk/checks/sas2ircu

#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*- # EXAMPLE DATA FROM CHECK 'sas2ircu':
# <<<sas2ircu>>>
# volume 0 79 okay_(oky) 0691440a258e54cc raid1 1907200
# disk 0 0 optimal_(opt) 5000c50-0-569e-9bad seagate st2000nm0023 z1x08nwc sas sas_hdd
# disk 0 1 optimal_(opt) 5000c50-0-569f-8055 seagate st2000nm0023 z1x091jj sas sas_hdd
#
# Integrated RAID Volume State values are as follows:
#  Okay (OKY) – The volume is active and drives are functioning properly. User data is protected if the current RAID level provides data protection.
#  Degraded (DGD) – The volume is active. User data is not fully protected because the configuration has changed or a drive has failed.
#  Failed (FLD) – The volume has failed.
#  Missing (MIS) – The volume is missing.
#  Initializing (INIT) – The volume is initializing.
#  Online (ONL) – The volume is online.
# Physical device State values are as follows:
#  Online (ONL) – The drive is operational and is part of a volume.
#  Hot Spare (HSP) – The drive is a hot spare that is available to replace a failed drive in a volume.
#  Ready (RDY) – The drive is ready for use as a normal disk drive, or it is ready to be assigned to a volume or a hot spare pool.
#  Available (AVL) – The drive might not be ready, and it is not suitable for use in a volume or a hot spare pool.
#  Failed (FLD) – The drive failed and is now offline.
# n Missing (MIS) – The drive has been removed or is not responding.
#  Standby (SBY) – The device is not a hard-disk device.
#  Out of Sync (OSY) – The drive, which is part of an Integrated RAID volume, is not in sync with other drives that are part of the volume.
#  Degraded (DGD) – The drive is part of a volume and is in degraded state.
#  Rebuilding (RBLD) – The drive is part of a volume and is currently rebuilding.
#  Optimal (OPT) – The drive is optimal and is part of a volume.
# Physical device Drive Type values are as follows:
#  SAS_HDD – The drive is a SAS HDD.
#  SATA_HDD – The drive is a SATA HDD.
#  SAS_SSD – The drive is a SAS SSD.
#  SATA_SSD – The drive is a SATA SSD.
# Physical device Protocol values are as follows:
#  SAS – The drive supports SAS protocol.
#  SATA – The drive supports SATA protocol. def inventory_sas2ircu(info):
inventory = []
for line in info:
itemName = ""
if line[0] == "volume":
# input: volume 0 79 okay_(oky) 0691440a258e54cc raid1 1907200
# itemName=VOLUME 0/79 (raid1, 1862GB)
itemName = "VOLUME "+line[1]+"/"+line[2]+" ("+line[5]+", "+str(int(line[6])/1024)+"GB)"
elif line[0] == "disk":
# input: disk 0 1 optimal_(opt) 5000c50-0-569f-8055 seagate st2000nm0023 z1x091jj sas sas_hdd
# itemName=DISK 0/1 ST2000NM0023_Z1X091JJ (SAS_HDD)
itemName = "DISK "+line[1]+"/"+line[2]+" "+line[6].upper()+"_"+line[7].upper()+" ("+line[9].upper()+")"
if len(itemName) > 0:
inventory.append((itemName, None))
return inventory # info是客户端插件传递来的二组列表,inventory函数返回包含元组的列表,元组第1个值是checkname,元组第2个值是agnetdata输出,如果没有值的话,使用None代替 def check_sas2ircu(item, params, info):
infoText = "" for line in info:
itemName = ""
if line[0] == "volume":
# input: volume 0 79 okay_(oky) 0691440a258e54cc raid1 1907200
# itemName=VOLUME 0/79 (raid1, 1862GB)
itemName = "VOLUME "+line[1]+"/"+line[2]+" ("+line[5]+", "+str(int(line[6])/1024)+"GB)"
infoText = "Volume Status "+line[3]
elif line[0] == "disk":
# input: disk 0 1 optimal_(opt) 5000c50-0-569f-8055 seagate st2000nm0023 z1x091jj sas sas_hdd
# itemName=DISK 0/1 ST2000NM0023_Z1X091JJ (SAS_HDD)
itemName = "DISK "+line[1]+"/"+line[2]+" "+line[6].upper()+"_"+line[7].upper()+" ("+line[9].upper()+")"
infoText = "Disk Status "+line[3]
if itemName == item:
if line[0] == "volume":
if line[3] == "okay_(oky)":
return (0, "OK - %s" % infoText)
elif line[3] == "failed_(fld)" or line[3] == "missing_(mis)" :
return (2, "CRIT - %s" % infoText)
else:
return (1, "WARN - %s" % infoText)
if line[0] == "disk":
if line[3] == "optimal_(opt)" or line[3] == "hot_spare_(hsp)" or line[3] == "ready_(rdy)":
return (0, "OK - %s" % infoText)
elif line[3] == "failed_(fld)" or line[3] == "missing_(mis)" or line[3] == "out_of_sync_(osy)" or line[3] == "degraded_(dgd)" :
return (2, "CRIT - %s" % infoText)
else:
return (1, "WARN - %s" % infoText)
return (3, "UNKNOWN - Invalid check output from %s" % item) # check函数传递变量,item,可以理解为是inventory的返回值itemName, params,是定义的default_level, info客户端插件的输出
# check函数返回值,也是元组
# 检测状态 a Nagios status code (0=OK, 1=WARN, 2=CRIT, 3=UNKNOWN)
# 检测结果 a text to be used by Nagios as plugin output
# 性能数据,用于画图,是可选项,由has_perfdata变量控制 optionally: performance data # perfdata 值是元组,由以下部分组成
# A variable name (string)
# The current value of the variable (int or float)
# The warning level or ""
# The critical level or ""
# The minimum possible value or ""
# The maximum possible value or "" # perfdata example
#check_foobar(item, params, info):
# return (0, "Foobar", [
# ( "size", 125 ), # simple value, no levels, no range
# ( "used", 88.5, "", "", 0, 100), # no levels, range is from 0 to 100
# ( "guzzi", -14.5, -20, -30), # warning at -20, crit at -30
# ( "argl", 66, 80, 90, 0, 100), # levels at 80/90, min/max at 0/100
# ]) # 控制
check_info["sas2ircu"] = {
'check_function': check_sas2ircu,
'inventory_function': inventory_sas2ircu,
'service_description': '%s',
'has_perfdata': False
}

check_mk/checkman/sas2ircu

title: Check state of physical disks and volumes of LSI SAS2008, Dell PERC H200 Raid controllers
agents: linux
author: Leo Eibler <le@sprossenwanne.at>
license: Apache License, Version 2.0
distribution: none
description:
This check monitors the state of the physical disks and volumes
of LSI SAS2008, Dell PERC H200 raid controllers (used in Dell R200, R210, R210II servers).
The Linux agent sends the neccessary data,
if the command line utility {sas2ircu} is found in the shells
search path. The utility {sas2ircu} debian x64 package can be downloaded from
{http://hwraid.le-vert.net/debian/pool-wheezy/sas2ircu_16.00.00.00-1_amd64.deb} and
installed with {dpkg -i sas2ircu_16.00.00.00-1_amd64.deb}. item:
For volumes: The word 'VOLUME' followed by the controller number (1st controller={0}),
the volume id and the volume raid type and size.
For example {"VOLUME 0/79 (raid1, 1862GB)"} means a volume on 1st controller {0} with
id {79} using {raid1} with a size of {1862GB}.
For disks: The word 'DISK' followed by the controller number (1st controller={0}),
the disk number, the disk model and serial and disk type.
For example {"DISK 0/1 ST2000NM0023_Z1X091JJ (SAS_HDD)"} means a disk on 1st controller {0},
the 2nd disk {1} of model and serial {ST2000NM0023_Z1X091JJ} which is a {SAS_HDD} disk type. inventory:
All disks and volumes of all controllers are automatically inventorized. The current state is
taken as the target state.

check_mk检测插件编写的更多相关文章

  1. check_mk检测插件 - raid监控

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

  2. robots检测插件编写

    首先先把url分割 url = 'https://www.baidu.com/s?wd=123&rsv_spt=1&rsv_iqid=0x8d22781d000014ad&is ...

  3. [Linux实用工具]munin-node插件配置和插件编写

    前面介绍了2篇munin使用的相关文章: [Linux实用工具]Linux监控工具munin的安装和配置 [Linux实用工具]Linux监控工具munin的展示(Nginx)   这次介绍一下mun ...

  4. BugScan插件编写高(gǎo)级(jī)教程

    声明:本文最先发布在:http://q.bugscan.net/t/353 转载请注明出处 有问题可以和我交流 邮件(Medici.Yan@gmail.com) 个人博客地址:http://www.c ...

  5. vim语法高亮插件编写

    # vim语法高亮插件编写 编写vim语法高亮插件很简单,只需要编写两个文件.vim放到vim的安装目录下的目录就可以了. ## 输出------------------------------ sy ...

  6. jQuery插件编写及链式编程模型小结

    JQuery极大的提高了我们编写JavaScript的效率,让我们可以愉快的编写代码,做出各种特效.大多数情况下,我们都是使用别人开发的JQuery插件,今天我们就来看看如何把我们常用的功能做出JQu ...

  7. Wireshark插件编写

    Wireshark插件编写 在抓包的过程中学习了使用wireshark,同时发现wireshark可以进行加载插件,便在网上学习了一下相应的插件开发技术. 需求编写一个私有协议名为SYC,使用UDP端 ...

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

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

  9. typecho插件编写教程1 - 从HelloWorld说起

    typecho插件编写教程1 - 从HelloWorld说起 老高 187 5月25日 发布 推荐 0 推荐 收藏 2 收藏,189 浏览 最近老高正在编写一个关于typecho的插件,由于typec ...

随机推荐

  1. tinkphp中的自动验证

    tinkphp是国内非常流行的一个开源框架,国内大小公司都在用的框架.对于初学的好多同学感觉不太好上手,其实并没没有大家想的那么复杂.自动验证功能是thinkphp提高的一种数据验证方法,分为动态和静 ...

  2. springcloud系列九 整合Hystrix Dashboard

    Hystrix Dashboard是Hystrix的仪表盘组件,主要用来实时监控Hystrix的各项指标信息,通过界面反馈的信息可以快速发现系统中存在的问题. 整合快速体验: pom.xml(这个是F ...

  3. Python-6-字典-函数dict,字典的基本操作及将字符串设置功能用于字典

    phonebook = {'Alice': '2341', 'Beth': '9102', 'Cecil': '3258'} 字典由键及其相应的值组成,这种键-值对称为项. 键必须为独一无二,值不必如 ...

  4. [題解](最小生成樹)luogu_P2916安慰奶牛

    可以發現每個點經過次數恰好等於這個點的度數,所以把點權下放邊權,跑最小生成樹,原來邊權乘二在加上兩端點權,答案再加一遍起點最小點權 #include<bits/stdc++.h> #def ...

  5. POJ-2112 Optimal Milking(floyd+最大流+二分)

    题目大意: 有k个挤奶器,在牧场里有c头奶牛,每个挤奶器可以满足m个奶牛,奶牛和挤奶器都可以看成是实体,现在给出两个实体之间的距离,如果没有路径相连,则为0,现在问你在所有方案里面,这c头奶牛需要走的 ...

  6. keepalived企业管理

    实践案例一:更改nginx反向代理只监听vip地址 10.0.0.3/nana.html 可以使用 10.0.0.5/nana.html  不可以使用 10.0.0.6/nana.html  不可以使 ...

  7. Android RecyView 滑动置指定位置

    1,直接回到顶部 recyview.getLinearLayoutManager().scrollToPositionWithOffset(0, 0); 2,慢慢的回到顶部 private void ...

  8. STL-----c++标准模板

    一.排序和检索 1.sort(v.begin,v.end) 2.lower_bound(v.begin,v.end,x)

  9. GO 日志追加记录

    以追加的方式将程序输出到不同的日志文件,当日志文件超过10M大小时,自动清空文件. package tools import ( "fmt" "log" &qu ...

  10. PHP rand 和 mt_rand

    PHP mt_rand() 函数 定义和用法 mt_rand() 使用 Mersenne Twister 算法返回随机整数. 语法 mt_rand(min,max) 说明 如果没有提供可选参数 min ...