Plugin printer_supply_brother black cyan magenta yellow because actual not see percentual

CMK version:2.0.0p37 (CRE)
OS version:Centos7

**Error message:percentual supply brother black cyan magenta yellow **

**Output of “cmk --debug -vvn hostname”: ** (If it is a problem with checks or plugins)

#.1.3.6.1.2.1.43.9.2.1.8.1.1 Brother
#.1.3.6.1.2.1.25.3.2.1.2.1 .1.3.6.1.2.1.25.3.1.5

#.1.3.6.1.2.1.25.3.2.1.3.1 Brother MFC-L6900DW series
#.1.3.6.1.2.1.25.3.2.1.2.1 .1.3.6.1.2.1.25.3.1.5
#.1.3.6.1.2.1.43.11.1.1.6.1.1 Black Toner Cartridge
#.1.3.6.1.2.1.43.11.1.1.6.1.2 Drum Unit

#.1.3.6.1.2.1.43.12.1.1.4.1.1 black
#.1.3.6.1.2.1.43.12.1.1.5.1.1 2
#.1.3.6.1.2.1.43.13.4.1.2.1.1 7
#.1.3.6.1.2.1.43.13.4.1.2.1.2 7
#.1.3.6.1.2.1.43.13.4.1.2.1.3 7
#.1.3.6.1.2.1.43.13.4.1.3.1.1 4
#.1.3.6.1.2.1.43.13.4.1.3.1.2 4
#.1.3.6.1.2.1.43.13.4.1.3.1.3 4

#.1.3.6.1.2.1.43.12.1.1.4.1.1 black
#.1.3.6.1.2.1.43.12.1.1.4.1.2 cyan
#.1.3.6.1.2.1.43.12.1.1.4.1.3 magenta
#.1.3.6.1.2.1.43.12.1.1.4.1.4 yellow

#.1.3.6.1.2.1.25.3.2.1.3.1 Brother HL-L9310CDW series
#.1.3.6.1.2.1.25.3.2.1.2.1 .1.3.6.1.2.1.25.3.1.5
#.1.3.6.1.2.1.43.11.1.1.6.1.2 Cyan Toner Cartridge
#.1.3.6.1.2.1.43.11.1.1.6.1.3 Magenta Toner Cartridge
#.1.3.6.1.2.1.43.11.1.1.6.1.4 Yellow Toner Cartridge
#.1.3.6.1.2.1.43.11.1.1.6.1.5 Waste Toner Box
#.1.3.6.1.2.1.43.11.1.1.6.1.6 Belt Unit
#.1.3.6.1.2.1.43.11.1.1.6.1.7 Drum Unit

# "SNMPv2-SMI::enterprises.2435.2.3.9.4.2.1.5.5.8.0 = Hex-STRING: 
# 63 01 04 00 00 00 01 68 01 04 00 00 00 01 55 01 
# 04 00 00 00 01 31 01 04 00 00 00 01 32 01 04 00 
# 00 00 01 33 01 04 00 00 00 01 34 01 04 00 00 00 
# 01 70 01 04 00 00 23 F0 71 01 04 00 00 18 38 72 
# 01 04 00 00 18 38 6F 01 04 00 00 05 78 41 01 04 
# 00 00 24 B8 69 01 04 00 00 25 80 11 01 04 00 00 
# 06 CF 67 01 04 00 00 00 01 6B 01 04 00 00 27 10 
# 54 01 04 00 00 00 01 66 01 04 00 00 00 01 35 01 
# 04 00 00 00 01 36 01 04 00 00 00 01 6A 01 04 00 
# 00 27 10 6C 01 04 00 00 27 10 6D 01 04 00 00 27 
# 10 6E 01 04 00 00 27 10 FF"

# "Black : 6F 01 04 00 00 05 78
# Cyan : 70 01 04 00 00 23 F0 
# Magenta : 71 01 04 00 00 18 38 
# Yellow : 72 01 04 00 00 18 38"

# "[Format : Pointer, Fixed Value, Data length, Data, Data, Data, Data]
# Black : Pointer = 6F, Data = 00000578 = 1400 (Decimal) -> 14%
# Cyan : Pointer = 70, Data = 000023F0 = 9200 (Decimal) -> 92%
# Magenta : Pointer = 71, Data = 00001838 = 6200 (Decimal) -> 62%
# Yellow : Pointer = 72, Data = 00001838 = 6200 (Decimal) -> 62%"

from .agent_based_api.v1 import *

def parse_printer_supply_brother(string_table):
    parsed = []
    for tonerblack, status in string_table[0]:
        my_string = status
        # Extract a substring from toner black
        start_position = 84
        end_position = 104
        # Extract a substring from covenrt hex to decimal
        start_position1 = 93
        end_position1 = 104
        # Extract a single substring from covenrt hex to decimal
        start_position2 = 93
        end_position2 = 95
        # Extract a single substring from covenrt hex to decimal
        start_position3 = 96
        end_position3 = 98
        # Extract a single substring from covenrt hex to decimal
        start_position4 = 99
        end_position4 = 101
        # Extract a single substring from covenrt hex to decimal
        start_position5 = 102
        end_position5 = 104

        substring = my_string[start_position:end_position]
        substring1 = my_string[start_position1:end_position1]
        substring2 = my_string[start_position2:end_position2]
        substring3 = my_string[start_position3:end_position3]
        substring4 = my_string[start_position4:end_position4]
        substring5 = my_string[start_position5:end_position5]
        substring6 = substring2+substring3+substring4+substring5

        # converting hexadecimal string to decimal
        res = int(substring6, 16)
        res1 =res/100
        status = render.percent(res1)       
        data = [tonerblack, status]
        parsed.append(data)
    return parsed

register.snmp_section(
    name="printer_supply_brother",
    parse_function=parse_printer_supply_brother,
    fetch=[
        SNMPTree(
            base=".1.3.6.1",
            oids=[
                '2.1.43.12.1.1.4.1.1', # Black Toner Cartridge
#                '2.1.43.12.1.1.4.1.2', # cyan Toner Cartridge
#                '2.1.43.12.1.1.4.1.3', # magenta Toner Cartridge
#                '2.1.43.12.1.1.4.1.4', # yellow Toner Cartridge 
                '4.1.2435.2.3.9.4.2.1.5.5.8.0',
                
            ]

        )
    ],
    detect=startswith(".1.3.6.1.2.1.25.3.2.1.2.1", ".1.3.6.1.2.1.25.3.1.5"), 
)

def discover_printer_supply_brother(section):
    for tonerblack, status in section:
        yield Service(item=tonerblack)

register.check_plugin(
    name="printer_supply_brother",
    service_name="Supply Brother",
    discovery_function=discover_printer_supply_brother,
    check_function=check_printer_supply_brother,
    check_default_parameters={},
)



this is my first plugin and my problem is code chek_function

Thank you very mutch

Hello

where is the error ? the code or CheckMK?

#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2013             mk@mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk is free software;  you can redistribute it and/or modify it
# under the  terms of the  GNU General Public License  as published by
# the Free Software Foundation in version 2.  check_mk is  distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
# ails.  You should have  received  a copy of the  GNU  General Public
# License along with GNU Make; see the file  COPYING.  If  not,  write
# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
# Boston, MA 02110-1301 USA.


#.1.3.6.1.2.1.43.9.2.1.8.1.1 Brother
#.1.3.6.1.2.1.25.3.2.1.2.1 .1.3.6.1.2.1.25.3.1.5



#.1.3.6.1.2.1.25.3.2.1.3.1 Brother MFC-L6900DW series
#.1.3.6.1.2.1.25.3.2.1.2.1 .1.3.6.1.2.1.25.3.1.5
#.1.3.6.1.2.1.43.11.1.1.6.1.1 Black Toner Cartridge
#.1.3.6.1.2.1.43.11.1.1.6.1.2 Drum Unit

#.1.3.6.1.2.1.43.12.1.1.4.1.1 black
#.1.3.6.1.2.1.43.12.1.1.5.1.1 2
#.1.3.6.1.2.1.43.13.4.1.2.1.1 7
#.1.3.6.1.2.1.43.13.4.1.2.1.2 7
#.1.3.6.1.2.1.43.13.4.1.2.1.3 7
#.1.3.6.1.2.1.43.13.4.1.3.1.1 4
#.1.3.6.1.2.1.43.13.4.1.3.1.2 4
#.1.3.6.1.2.1.43.13.4.1.3.1.3 4

#.1.3.6.1.2.1.43.12.1.1.4.1.1 black
#.1.3.6.1.2.1.43.12.1.1.4.1.2 cyan
#.1.3.6.1.2.1.43.12.1.1.4.1.3 magenta
#.1.3.6.1.2.1.43.12.1.1.4.1.4 yellow

#.1.3.6.1.2.1.25.3.2.1.3.1 Brother HL-L9310CDW series
#.1.3.6.1.2.1.25.3.2.1.2.1 .1.3.6.1.2.1.25.3.1.5
#.1.3.6.1.2.1.43.11.1.1.6.1.2 Cyan Toner Cartridge
#.1.3.6.1.2.1.43.11.1.1.6.1.3 Magenta Toner Cartridge
#.1.3.6.1.2.1.43.11.1.1.6.1.4 Yellow Toner Cartridge
#.1.3.6.1.2.1.43.11.1.1.6.1.5 Waste Toner Box
#.1.3.6.1.2.1.43.11.1.1.6.1.6 Belt Unit
#.1.3.6.1.2.1.43.11.1.1.6.1.7 Drum Unit



# "SNMPv2-SMI::enterprises.2435.2.3.9.4.2.1.5.5.8.0 = Hex-STRING: 
# 63 01 04 00 00 00 01 68 01 04 00 00 00 01 55 01 
# 04 00 00 00 01 31 01 04 00 00 00 01 32 01 04 00 
# 00 00 01 33 01 04 00 00 00 01 34 01 04 00 00 00 
# 01 70 01 04 00 00 23 F0 71 01 04 00 00 18 38 72 
# 01 04 00 00 18 38 6F 01 04 00 00 05 78 41 01 04 
# 00 00 24 B8 69 01 04 00 00 25 80 11 01 04 00 00 
# 06 CF 67 01 04 00 00 00 01 6B 01 04 00 00 27 10 
# 54 01 04 00 00 00 01 66 01 04 00 00 00 01 35 01 
# 04 00 00 00 01 36 01 04 00 00 00 01 6A 01 04 00 
# 00 27 10 6C 01 04 00 00 27 10 6D 01 04 00 00 27 
# 10 6E 01 04 00 00 27 10 FF"



# "Black : 6F 01 04 00 00 05 78
# Cyan : 70 01 04 00 00 23 F0 
# Magenta : 71 01 04 00 00 18 38 
# Yellow : 72 01 04 00 00 18 38"

# "[Format : Pointer, Fixed Value, Data length, Data, Data, Data, Data]
# Black : Pointer = 6F, Data = 00000578 = 1400 (Decimal) -> 14%
# Cyan : Pointer = 70, Data = 000023F0 = 9200 (Decimal) -> 92%
# Magenta : Pointer = 71, Data = 00001838 = 6200 (Decimal) -> 62%
# Yellow : Pointer = 72, Data = 00001838 = 6200 (Decimal) -> 62%"

# "[Format : Pointer, Fixed Value, Data length, Data, Data, Data, Data]
# Pointer = 41, Data = 000024B8 = 9400 (Decimal) -> 94%"
#factory_settings["printer_supply_brother_default_levels"] = {"levels": (20.0, 10.0)}
#!/usr/bin/python3


from .agent_based_api.v1 import *
from pprint import pprint

def parse_printer_supply_brother(string_table):
    print(string_table)
    # data = {}
    # for line in string_table:
        # levelconsumabile = line[1]
        # my_string = (levelconsumabile)
        # # Extract a substring from toner black
        # start_position = 84
        # end_position = 104
        # # Extract a substring from covenrt hex to decimal
        # start_position1 = 93
        # end_position1 = 104
        # # Extract a single substring from covenrt hex to decimal
        # start_position2 = 93
        # end_position2 = 95
        # # Extract a single substring from covenrt hex to decimal
        # start_position3 = 96
        # end_position3 = 98
        # # Extract a single substring from covenrt hex to decimal
        # start_position4 = 99
        # end_position4 = 101
        # # Extract a single substring from covenrt hex to decimal
        # start_position5 = 102
        # end_position5 = 104
        # substring = my_string[start_position:end_position]
        # print (substring)
        # substring1 = my_string[start_position1:end_position1]
        # substring2 = my_string[start_position2:end_position2]
        # substring3 = my_string[start_position3:end_position3]
        # substring4 = my_string[start_position4:end_position4]
        # substring5 = my_string[start_position5:end_position5]
        # substring6 = substring2+substring3+substring4+substring5
        # sub = int(substring6) 
        # res = int(sub, 16)
        # res1 =res/100
        # status = render.percent(res1)
        # data[line[0]] = status
    return string_table


# def discover_printer_supply_brother(section):
    # for item in section:
        # yield Service(item=item[0])

    # #yield from (Serviec(item=item) for item in section)

# def my_check_function(item, section):
    # if item not in section:
        # return
    # data = section[item]
    # yield Result(
        # state=State.OK, # State.OK, State.WARN, State.CRIT, State.UNKOWN
        # summary="Message"
    # )


register.snmp_section(
    name="printer_supply_brother",
    detect=startswith(".1.3.6.1.2.1.25.3.2.1.2.1", ".1.3.6.1.2.1.25.3.1.5"),
    parse_function=parse_printer_supply_brother,
    fetch=[
        SNMPTree(
            base=".1.3.6.1",
            oids=[
                "2.1.43.12.1.1.4.1.1",
                "4.1.2435.2.3.9.4.2.1.5.5.8.0",
            ],
        ),
    ],
)


register.check_plugin(
    name="printer_supply_brother",
    # service_name="My Service %s",
    # discovery_function=discover_printer_supply_brother,
    # check_function=my_check_function,
    #cluster_check_function=my_cluster_check_function,
)

and the error

OMD[oe]:~$ cmk -I HvmLas
[[['black', 'c\x01\x04\x00\x00\x00\x01\x11\x01\x04\x00\x00\x87\x82A\x01\x04\x00\x00\x0c\x1c1\x01\x04\x00\x00\x00\x01o\x01\x04\x00\x00%\x1c\x81\x01\x04\x00\x00\x00d\x86\x01\x04\x00\x00\x00\ng\x01\x04\x00\x00\x00\x01k\x01\x04\x00\x00"`T\x01\x04\x00\x00\x00\x01f\x01\x04\x00\x00\x00\x015\x01\x04\x00\x00\x00\x01j\x01\x04\x00\x00"`l\x01\x04\x00\x00\'\x10m\x01\x04\x00\x00"Äÿ']]]

and test oid

OMD[oe]:~$ cmk --snmpwalk --oid .1.3.6.1.4.1.2435.2.3.9.4.2.1.5.5.8.0 -vv HvmLas
HvmLas:
Walk on ".1.3.6.1.4.1.2435.2.3.9.4.2.1.5.5.8.0"...
Running 'snmpbulkwalk -Cr10 -v3 -l authPriv -a md5 -u user1 -A password1 -x DES -X password1 -m "" -M "" -Cc -OQ -OU -On -Ot 192.168.7.50 .1.3.6.1.4.1.2435.2.3.9.4.2.1.5.5.8.0'
1 variables.
Wrote fetched data to /omd/sites/oe/var/check_mk/snmpwalks/HvmLas.
OMD[oe]:~$ nano /omd/sites/oe/var/check_mk/snmpwalks/HvmLas


.1.3.6.1.4.1.2435.2.3.9.4.2.1.5.5.8.0 "63 01 04 00 00 00 01 11 01 04 00 00 87 82 41 01 04 00 00 0C 1C 31 01 04 00 00 00 01 6F 01 04 00 00 25 1C 81 01 04 00 00 00 64 86$



Thank ypu very mutch