Migration Custom Checks to CheckMK 2.0 - Python Problems

Hi There
We are currently migrating old custom CheckMK checks to CheckMK 2.0.
I have already considered the migration documentation and am aware of the differences with Python3.
The checks have been converted with 2to3, works for most Checks, but one error i could not solve.
Seems like there is still something wrong with the type definition, but o could not find where.
Can anybody help?

Thanks Roger

**Exception**	
TypeError ('in <string>' requires string as left operand, not NoneType)
**Traceback**	
  File "/omd/sites/cmktest/lib/python3/cmk/base/checking.py", line 577, in get_aggregated_result
    result = _aggregate_results(check_function(**kwargs))
  File "/omd/sites/cmktest/lib/python3/cmk/base/checking.py", line 808, in _aggregate_results
    perfdata, results = _consume_and_dispatch_result_types(subresults)
  File "/omd/sites/cmktest/lib/python3/cmk/base/checking.py", line 852, in _consume_and_dispatch_result_types
    for subr in subresults:
  File "/omd/sites/cmktest/lib/python3/cmk/base/api/agent_based/register/check_plugins.py", line 89, in filtered_generator
    for element in generator(*args, **kwargs):
  File "/omd/sites/cmktest/lib/python3/cmk/base/api/agent_based/register/check_plugins_legacy.py", line 171, in check_result_generator
    subresults = sig_function(**kwargs)
  File "/omd/sites/cmktest/lib/python3/cmk/base/api/agent_based/register/check_plugins_legacy.py", line 257, in check_migration_wrapper
    return original_function(None, params, section)
  File "/omd/sites/cmktest/local/share/check_mk/checks/bi_totemomail_queue", line 38, in check_bi_totemomail_queue
    if (item in " ".join(line)) and (item == " ".join(line)[:len(item)]):

    def inventory_bi_totemomail_queue(info):
  p = re.compile('^[0-9a-zA-Z-]*:$')
  for line in info:
    if p.match(line[0]):
      #found an interesting line, yield it to check_mk
      yield line[0][:-1], None

def check_bi_totemomail_queue(item, params, info):
  pattern_error = re.compile('^error.*$|^DBUnavailable.*$|^directoryUnavailable.*$')
  pattern_mailflow = re.compile('^incoming.*$|^outgoing.*$|^spool.*$|^delivery.*$')
  for line in info:
    if (item in " ".join(line)) and (item == " ".join(line)[:len(item)]):
      if len(item) == len(line[0])-1:
        name = line[0]
        count = line[1]
        if pattern_error.match(name):
          if 'error-PW-Mail-detected' in name or 'error-PW-mail-detected' in name:
            warn = 25
            crit = 50
          else:
            warn = 1
            crit = 1
        elif pattern_mailflow.match(name):
          warn = 10
          crit = 20
        if int(count) >= crit:
          return (2, "has " + count + " items")
        elif int(count) >= warn:
          return (1, "has " + count + " items")
        elif int(count) < warn:
          return (0, "has " + count + " items")
        else:
          return (3, "Something went wrong")

# declare the check to Check_MK
check_info["bi_totemomail_queue"] = {
    'check_function':            check_bi_totemomail_queue,
    'inventory_function':        inventory_bi_totemomail_queue,
    'service_description':       'BI Totemomail queue',
}

The inventory function who builds the item looks a little bit strange.
You generate an item but your check by itself don’t have a item.

check_info["bi_totemomail_queue"] = {
    'check_function':            check_bi_totemomail_queue,
    'inventory_function':        inventory_bi_totemomail_queue,
    'service_description':       'BI Totemomail queue',
}

If you have an item then the info should looks like this

check_info["bi_totemomail_queue"] = {
    'check_function':            check_bi_totemomail_queue,
    'inventory_function':        inventory_bi_totemomail_queue,
    'service_description':       'BI Totemomail queue %s',
}
1 Like

Thank you so much Andreas, the %s was the solution!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.