您的位置:首页 > 运维架构

check_mk自定义监控插件

2014-03-31 16:15 1036 查看
客户端:
/usr/lib/check_mk_agent/plugins/filecount

#!/bin/bash

#DIRS="/var/log /tmp"

DIRS="/var/log"

echo '<<<filecount>>>'

for dir in $DIRS

do

   # ls $dir | wc --lines

    count=$(ls $dir | wc --lines)

    echo "$count"

done

cd /usr/lib/check_mk_agent/plugins

chmod +x filecount

服务端:
服务端执行如下命令查看是否能够从客户端获取值

[root@LY-1611-E1 checks]# check_mk -d 10.8.18.53|fgrep -A 5 filecount

<<<filecount>>>

52

<<<postgres_sessions>>>

f 115

t 0

<<<postgres_stat_database:sep(59)>>>

在服务端创建文件filecount

/usr/share/check_mk/checks/filecount

def inventory_filecount_temp(info):

   inventory = []

   for line in info:

      disk = line[0]

      inventory.append( (disk, None) )

   return inventory

def check_filecount_temp(item, params, info):

        for line in info:

                celsius = int(line[0])

                if celsius > 200:

                        return (2, "filecount is %d" % celsius)

                        #return (2, "filecount is %d" % celsius)

                elif celsius > 100:

                        return (1, "filecount50 is %d" % celsius)

                else:

                        return (0, "filecount is %d" % celsius)

        return (3, "Disk %s not found in agent output" % item)

check_info["filecount.temp"] = {

    'check_function':            check_filecount_temp,

    'inventory_function':        inventory_filecount_temp,

    'service_description':       'filecount %s',

}

检查check_mk是否可以识别新增加的check

[root@LY-1611-E1 checks]# check_mk -L|grep filecount

filecount.temp                   tcp     no     yes    filecount %s

[root@LY-1611-E1 checks]# check_mk --checks=filecount.temp -I 10.8.18.53

filecount.temp    1 new checks

查看服务端从客户端获取数据结果

[root@LY-1611-E1 checks]# check_mk -nv 10.8.18.53

Check_mk version 1.2.4

PostgreSQL Daemon Sessions WARN - 109 total(!), 109 running(!)

SMART drive /dev/sda WARN - Temperature40 is 34C

filecount 52         OK - filecount is 52

filecount filecount  OK - filecount is 52

OK - Agent version 1.2.4, execution time 0.2 sec|execution_time=0.190 user_time=0.280 system_time=0.010 children_user_time=0.000 children_system_time=0.000

main.mk中增加监控项
checks += [("10.8.18.53","filecount.temp","filecount",(20,25))]

此文章参考官方网站而写
http://mathias-kettner.de/checkmk_devel_agentbased.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: