#!/root/environments/minhkma/bin/python3.5
#from pprint import pprint


factory_settings['check_mk_info_default_value'] = {
    'config': ((None, None), False),
}


def inventory_check_mk_info(info):
    if len(info)>0:
        for line in info:
            check_mk_info_item = ''
            line = " ".join(line)
            line = str(line)
            if line.startswith('$') or line.startswith('#'):
                continue
            #endif
            errors = ['Failed', 'Error']
            line_as_list = line.split(':')
            if any(error in line for error in errors):
                check_mk_info_item = "error " + str(line_as_list[0])
                #check_mk_info_item = ": error"
                yield (check_mk_info_item, "check_mk_info_default_value")
            else:
                #line_as_list = line.split(':')
                check_mk_info_item =  "MySQL service: " + str(line_as_list[0])
                yield (check_mk_info_item, "check_mk_info_default_value")


def float_int_or_string(value):
    if isinstance(value, int):
        return saveint(value)
    if isinstance(value, float):
        return savefloat(value)
    if isinstance(value, basestring):
        value_int = saveint(value)
        value_float = savefloat(value)
        if str(value_int) == str(value):
            return value_int
        elif str("{0:.2f}".format(round(value_float, 2))) == str(value):
            return value_float
        else:
            return value


def check_mk_info(item, params, info):
    perfdata = []
    state = 0
    hostinfo_in_item=''
    if ":" in item:
        item_as_list = item.split(": ")
        host_in_item, hostinfo_in_item = item_as_list
    #print host_in_item
    #print hostinfo_in_item
    info_as_dict = {}
    create_perfdata = False
    errors = ['Failed', 'Error']
    warn, crit = params['config'][0]
    create_perfdata = params['config'][1]
    warn_crit_append_string = ""
    message = ""
    perfdata_value = None
    perfdata_value_str = None
    check_string_crit = False
    for line in info:
        #print line
        line = " ".join(line)
        line = str(line)
        if ":" in line:
            line_as_list = line.split(':')
            info_as_dict.update({line_as_list[0]: line_as_list[1]})
    #pprint(info_as_dict)
    try:
        hostinfo_in_item_value = str(info_as_dict[hostinfo_in_item])
    except KeyError:
        hostinfo_in_item_value = "Error  - CheckMK - Instance or Check not avaiable"
    if "error" in item:
        state = 2
    elif any(error in hostinfo_in_item_value for error in errors):
        state = 2
    else:
        warn = float_int_or_string(warn)
        crit = float_int_or_string(crit)
        perfdata_value = float_int_or_string(info_as_dict[hostinfo_in_item])
    if isinstance(perfdata_value, basestring):
        if (warn is None) and (crit is None):
            warn_crit_append_string = " "
        else:
            warn_crit_append_string = " (crit if string changes) "
            check_string_crit = True
    else:
        if (warn is None) and (crit is None):
            warn_crit_append_string = " "
        else:
            warn_crit_append_string = " (warn/crit at " + str(warn) + "/" + str(crit) + ")"
    perfdata_value_str = str(perfdata_value)
    if create_perfdata:
        if (warn is None) or (crit is None):
            perdata = [(hostinfo_in_item, perfdata_value_str)]
        else:
            perfdata = [(hostinfo_in_item, perfdata_value_str, warn, crit, 0)]
    if state != 2:
        message = str(hostinfo_in_item) + ": " + str(perfdata_value_str) + str(warn_crit_append_string)
    else:
        try:
            message = "!!! An error occured: " + hostinfo_in_item_value
        except KeyError:
            state = 2
            message = "(!!) - Item not found, maybe xyz"
    if (warn is not None) or (crit is not None) and (state!=2):
        if check_string_crit:
            if str(crit) != perfdata_value_str:
                state = 2
                message += "difference between set string '" + str(crit) + "'detectec(!!)"
        else:
            if float_int_or_string(perfdata_value) >= crit:
                state = 2
                message += " (!!)"
            elif float_int_or_string(perfdata_value) >= warn:
                state = 1
                message += " (!)"
    perfdata = [('number',int(perfdata_value_str))]
    #print('state: {0}\nmessage: {1}\nperfdata: {2}'.format(state, message, perfdata))
    return state, message, perfdata


check_info ["check_mk_info"] = {
    'default_levels_variable': "check_mk_info_default_value",
    'inventory_function': inventory_check_mk_info,
    'check_function': check_mk_info,
    'service_description': 'CheckMK info',
    'has_perfdata': True,
    'group': "check_mk_info",
}

f9fa066d7c3eb6e264810d6b0d7a7ef699f53c10
<mask token>


def float_int_or_string(value):
    if isinstance(value, int):
        return saveint(value)
    if isinstance(value, float):
        return savefloat(value)
    if isinstance(value, basestring):
        value_int = saveint(value)
        value_float = savefloat(value)
        if str(value_int) == str(value):
            return value_int
        elif str('{0:.2f}'.format(round(value_float, 2))) == str(value):
            return value_float
        else:
            return value


<mask token>

<mask token>


def inventory_check_mk_info(info):
    if len(info) > 0:
        for line in info:
            check_mk_info_item = ''
            line = ' '.join(line)
            line = str(line)
            if line.startswith('$') or line.startswith('#'):
                continue
            errors = ['Failed', 'Error']
            line_as_list = line.split(':')
            if any(error in line for error in errors):
                check_mk_info_item = 'error ' + str(line_as_list[0])
                yield check_mk_info_item, 'check_mk_info_default_value'
            else:
                check_mk_info_item = 'MySQL service: ' + str(line_as_list[0])
                yield check_mk_info_item, 'check_mk_info_default_value'


def float_int_or_string(value):
    if isinstance(value, int):
        return saveint(value)
    if isinstance(value, float):
        return savefloat(value)
    if isinstance(value, basestring):
        value_int = saveint(value)
        value_float = savefloat(value)
        if str(value_int) == str(value):
            return value_int
        elif str('{0:.2f}'.format(round(value_float, 2))) == str(value):
            return value_float
        else:
            return value


<mask token>

<mask token>


def inventory_check_mk_info(info):
    if len(info) > 0:
        for line in info:
            check_mk_info_item = ''
            line = ' '.join(line)
            line = str(line)
            if line.startswith('$') or line.startswith('#'):
                continue
            errors = ['Failed', 'Error']
            line_as_list = line.split(':')
            if any(error in line for error in errors):
                check_mk_info_item = 'error ' + str(line_as_list[0])
                yield check_mk_info_item, 'check_mk_info_default_value'
            else:
                check_mk_info_item = 'MySQL service: ' + str(line_as_list[0])
                yield check_mk_info_item, 'check_mk_info_default_value'


def float_int_or_string(value):
    if isinstance(value, int):
        return saveint(value)
    if isinstance(value, float):
        return savefloat(value)
    if isinstance(value, basestring):
        value_int = saveint(value)
        value_float = savefloat(value)
        if str(value_int) == str(value):
            return value_int
        elif str('{0:.2f}'.format(round(value_float, 2))) == str(value):
            return value_float
        else:
            return value


def check_mk_info(item, params, info):
    perfdata = []
    state = 0
    hostinfo_in_item = ''
    if ':' in item:
        item_as_list = item.split(': ')
        host_in_item, hostinfo_in_item = item_as_list
    info_as_dict = {}
    create_perfdata = False
    errors = ['Failed', 'Error']
    warn, crit = params['config'][0]
    create_perfdata = params['config'][1]
    warn_crit_append_string = ''
    message = ''
    perfdata_value = None
    perfdata_value_str = None
    check_string_crit = False
    for line in info:
        line = ' '.join(line)
        line = str(line)
        if ':' in line:
            line_as_list = line.split(':')
            info_as_dict.update({line_as_list[0]: line_as_list[1]})
    try:
        hostinfo_in_item_value = str(info_as_dict[hostinfo_in_item])
    except KeyError:
        hostinfo_in_item_value = (
            'Error  - CheckMK - Instance or Check not avaiable')
    if 'error' in item:
        state = 2
    elif any(error in hostinfo_in_item_value for error in errors):
        state = 2
    else:
        warn = float_int_or_string(warn)
        crit = float_int_or_string(crit)
        perfdata_value = float_int_or_string(info_as_dict[hostinfo_in_item])
    if isinstance(perfdata_value, basestring):
        if warn is None and crit is None:
            warn_crit_append_string = ' '
        else:
            warn_crit_append_string = ' (crit if string changes) '
            check_string_crit = True
    elif warn is None and crit is None:
        warn_crit_append_string = ' '
    else:
        warn_crit_append_string = ' (warn/crit at ' + str(warn) + '/' + str(
            crit) + ')'
    perfdata_value_str = str(perfdata_value)
    if create_perfdata:
        if warn is None or crit is None:
            perdata = [(hostinfo_in_item, perfdata_value_str)]
        else:
            perfdata = [(hostinfo_in_item, perfdata_value_str, warn, crit, 0)]
    if state != 2:
        message = str(hostinfo_in_item) + ': ' + str(perfdata_value_str) + str(
            warn_crit_append_string)
    else:
        try:
            message = '!!! An error occured: ' + hostinfo_in_item_value
        except KeyError:
            state = 2
            message = '(!!) - Item not found, maybe xyz'
    if warn is not None or crit is not None and state != 2:
        if check_string_crit:
            if str(crit) != perfdata_value_str:
                state = 2
                message += "difference between set string '" + str(crit
                    ) + "'detectec(!!)"
        elif float_int_or_string(perfdata_value) >= crit:
            state = 2
            message += ' (!!)'
        elif float_int_or_string(perfdata_value) >= warn:
            state = 1
            message += ' (!)'
    perfdata = [('number', int(perfdata_value_str))]
    return state, message, perfdata


<mask token>

factory_settings['check_mk_info_default_value'] = {'config': ((None, None),
    False)}


def inventory_check_mk_info(info):
    if len(info) > 0:
        for line in info:
            check_mk_info_item = ''
            line = ' '.join(line)
            line = str(line)
            if line.startswith('$') or line.startswith('#'):
                continue
            errors = ['Failed', 'Error']
            line_as_list = line.split(':')
            if any(error in line for error in errors):
                check_mk_info_item = 'error ' + str(line_as_list[0])
                yield check_mk_info_item, 'check_mk_info_default_value'
            else:
                check_mk_info_item = 'MySQL service: ' + str(line_as_list[0])
                yield check_mk_info_item, 'check_mk_info_default_value'


def float_int_or_string(value):
    if isinstance(value, int):
        return saveint(value)
    if isinstance(value, float):
        return savefloat(value)
    if isinstance(value, basestring):
        value_int = saveint(value)
        value_float = savefloat(value)
        if str(value_int) == str(value):
            return value_int
        elif str('{0:.2f}'.format(round(value_float, 2))) == str(value):
            return value_float
        else:
            return value


def check_mk_info(item, params, info):
    perfdata = []
    state = 0
    hostinfo_in_item = ''
    if ':' in item:
        item_as_list = item.split(': ')
        host_in_item, hostinfo_in_item = item_as_list
    info_as_dict = {}
    create_perfdata = False
    errors = ['Failed', 'Error']
    warn, crit = params['config'][0]
    create_perfdata = params['config'][1]
    warn_crit_append_string = ''
    message = ''
    perfdata_value = None
    perfdata_value_str = None
    check_string_crit = False
    for line in info:
        line = ' '.join(line)
        line = str(line)
        if ':' in line:
            line_as_list = line.split(':')
            info_as_dict.update({line_as_list[0]: line_as_list[1]})
    try:
        hostinfo_in_item_value = str(info_as_dict[hostinfo_in_item])
    except KeyError:
        hostinfo_in_item_value = (
            'Error  - CheckMK - Instance or Check not avaiable')
    if 'error' in item:
        state = 2
    elif any(error in hostinfo_in_item_value for error in errors):
        state = 2
    else:
        warn = float_int_or_string(warn)
        crit = float_int_or_string(crit)
        perfdata_value = float_int_or_string(info_as_dict[hostinfo_in_item])
    if isinstance(perfdata_value, basestring):
        if warn is None and crit is None:
            warn_crit_append_string = ' '
        else:
            warn_crit_append_string = ' (crit if string changes) '
            check_string_crit = True
    elif warn is None and crit is None:
        warn_crit_append_string = ' '
    else:
        warn_crit_append_string = ' (warn/crit at ' + str(warn) + '/' + str(
            crit) + ')'
    perfdata_value_str = str(perfdata_value)
    if create_perfdata:
        if warn is None or crit is None:
            perdata = [(hostinfo_in_item, perfdata_value_str)]
        else:
            perfdata = [(hostinfo_in_item, perfdata_value_str, warn, crit, 0)]
    if state != 2:
        message = str(hostinfo_in_item) + ': ' + str(perfdata_value_str) + str(
            warn_crit_append_string)
    else:
        try:
            message = '!!! An error occured: ' + hostinfo_in_item_value
        except KeyError:
            state = 2
            message = '(!!) - Item not found, maybe xyz'
    if warn is not None or crit is not None and state != 2:
        if check_string_crit:
            if str(crit) != perfdata_value_str:
                state = 2
                message += "difference between set string '" + str(crit
                    ) + "'detectec(!!)"
        elif float_int_or_string(perfdata_value) >= crit:
            state = 2
            message += ' (!!)'
        elif float_int_or_string(perfdata_value) >= warn:
            state = 1
            message += ' (!)'
    perfdata = [('number', int(perfdata_value_str))]
    return state, message, perfdata


check_info['check_mk_info'] = {'default_levels_variable':
    'check_mk_info_default_value', 'inventory_function':
    inventory_check_mk_info, 'check_function': check_mk_info,
    'service_description': 'CheckMK info', 'has_perfdata': True, 'group':
    'check_mk_info'}

#!/root/environments/minhkma/bin/python3.5
#from pprint import pprint


factory_settings['check_mk_info_default_value'] = {
    'config': ((None, None), False),
}


def inventory_check_mk_info(info):
    if len(info)>0:
        for line in info:
            check_mk_info_item = ''
            line = " ".join(line)
            line = str(line)
            if line.startswith('$') or line.startswith('#'):
                continue
            #endif
            errors = ['Failed', 'Error']
            line_as_list = line.split(':')
            if any(error in line for error in errors):
                check_mk_info_item = "error " + str(line_as_list[0])
                #check_mk_info_item = ": error"
                yield (check_mk_info_item, "check_mk_info_default_value")
            else:
                #line_as_list = line.split(':')
                check_mk_info_item =  "MySQL service: " + str(line_as_list[0])
                yield (check_mk_info_item, "check_mk_info_default_value")


def float_int_or_string(value):
    if isinstance(value, int):
        return saveint(value)
    if isinstance(value, float):
        return savefloat(value)
    if isinstance(value, basestring):
        value_int = saveint(value)
        value_float = savefloat(value)
        if str(value_int) == str(value):
            return value_int
        elif str("{0:.2f}".format(round(value_float, 2))) == str(value):
            return value_float
        else:
            return value


def check_mk_info(item, params, info):
    perfdata = []
    state = 0
    hostinfo_in_item=''
    if ":" in item:
        item_as_list = item.split(": ")
        host_in_item, hostinfo_in_item = item_as_list
    #print host_in_item
    #print hostinfo_in_item
    info_as_dict = {}
    create_perfdata = False
    errors = ['Failed', 'Error']
    warn, crit = params['config'][0]
    create_perfdata = params['config'][1]
    warn_crit_append_string = ""
    message = ""
    perfdata_value = None
    perfdata_value_str = None
    check_string_crit = False
    for line in info:
        #print line
        line = " ".join(line)
        line = str(line)
        if ":" in line:
            line_as_list = line.split(':')
            info_as_dict.update({line_as_list[0]: line_as_list[1]})
    #pprint(info_as_dict)
    try:
        hostinfo_in_item_value = str(info_as_dict[hostinfo_in_item])
    except KeyError:
        hostinfo_in_item_value = "Error  - CheckMK - Instance or Check not avaiable"
    if "error" in item:
        state = 2
    elif any(error in hostinfo_in_item_value for error in errors):
        state = 2
    else:
        warn = float_int_or_string(warn)
        crit = float_int_or_string(crit)
        perfdata_value = float_int_or_string(info_as_dict[hostinfo_in_item])
    if isinstance(perfdata_value, basestring):
        if (warn is None) and (crit is None):
            warn_crit_append_string = " "
        else:
            warn_crit_append_string = " (crit if string changes) "
            check_string_crit = True
    else:
        if (warn is None) and (crit is None):
            warn_crit_append_string = " "
        else:
            warn_crit_append_string = " (warn/crit at " + str(warn) + "/" + str(crit) + ")"
    perfdata_value_str = str(perfdata_value)
    if create_perfdata:
        if (warn is None) or (crit is None):
            perdata = [(hostinfo_in_item, perfdata_value_str)]
        else:
            perfdata = [(hostinfo_in_item, perfdata_value_str, warn, crit, 0)]
    if state != 2:
        message = str(hostinfo_in_item) + ": " + str(perfdata_value_str) + str(warn_crit_append_string)
    else:
        try:
            message = "!!! An error occured: " + hostinfo_in_item_value
        except KeyError:
            state = 2
            message = "(!!) - Item not found, maybe xyz"
    if (warn is not None) or (crit is not None) and (state!=2):
        if check_string_crit:
            if str(crit) != perfdata_value_str:
                state = 2
                message += "difference between set string '" + str(crit) + "'detectec(!!)"
        else:
            if float_int_or_string(perfdata_value) >= crit:
                state = 2
                message += " (!!)"
            elif float_int_or_string(perfdata_value) >= warn:
                state = 1
                message += " (!)"
    perfdata = [('number',int(perfdata_value_str))]
    #print('state: {0}\nmessage: {1}\nperfdata: {2}'.format(state, message, perfdata))
    return state, message, perfdata


check_info ["check_mk_info"] = {
    'default_levels_variable': "check_mk_info_default_value",
    'inventory_function': inventory_check_mk_info,
    'check_function': check_mk_info,
    'service_description': 'CheckMK info',
    'has_perfdata': True,
    'group': "check_mk_info",
}
