Thursday 24 March 2011

Creating your own checks in check_mk


It is important to distinguish between inidividual checks and subset check e.g.

LINUX.SUBSET, where the main check is linux, subcheck SUBSET
e.g. linux.version is a subset of check linux, so there will be a check for linux + linux.version, which will both be contained in the same plugin script!


So, any further checks against linux, can be done via linux.XXX
Agent
/usr/lib/check_mk_agent/plugins#


linux_version.sh

#!/bin/sh
echo '<<<linux>>>'
cat /etc/issue.net


this will turn up if you telnet to the agent box i.e. 
telnet server 6556


Check the agent is outputting your plugin
check_mk -d servername | fgrep linux -A 5




The tricky part is the agent check itself.



Follow the guides on the check_mk site, then under the checks directory
/usr/share/check_mk/checks




#!/bin/python
inventory_process = []
inventory_process_version = []


# the inventory version (dummy)
def inventory_linux_version(checkname, info):
        # begin with empty inventory
        inventory = []
# fork to see which subcheck
        if checkname == "linux.version":
                # linux versions
#               print "linux version"
                for line in info:
                        ldistro = line[0]
                        ltype = line[1]
                        lcodename = line[2]
                        inventory.append ( ( None, (ldistro, ltype, lcodename) ) )
                        return inventory
        else:
                # must be std linux command
                inventory = []
                print "std linux check"
                #i
#the actual check
def check_linux_version (item, params, info):
        #print info.strip ('(')
        return (0, "OK - %s" % (info ,))
        #print item
        #print params
        #print info
        #       return (3, "Sorry - not implemented")


#check for std linux command
def check_linux (item, params, info):
        #print item
        #print params,
        #print info
        return (3, "Sorry - not implemented")

# checking function, service description, perf data, invenotry function
# one fucntion for each check (linux, linux.version)
check_info['linux'] = (check_linux, "Linux data (not finished(",0 ,inventory_linux_version)
check_info['linux.version'] = (check_linux_version, "Linux version",0 ,inventory_linux_version)




if it all works out it should have a 
check_mk -L | grep linux
check_mk --checks=linux.version -I servername


dump check info to console
check_mk -nv servername
SIMPLES!

2 comments: