This file is indexed.

/usr/share/check_mk/checks/printer_supply is in check-mk-server 1.1.12-1ubuntu1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2010             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.

# +------------------------------------------------------------------+
# | This file has been contributed by:                               |
# |                                                                  |
# | Peter Lauk <lauk@stuttgart-airport.com>           Copyright 2010 |
# +------------------------------------------------------------------+

# In some cases the name of the part is not uniq. e.g. for c5900
# devices. In this cases add the color from the dedicated OID to
# the item name.
#
# Example output for this case:
#
#['Toner Cartridge OKI DATA CORP', '100', '30', 'black']
#['Toner Cartridge OKI DATA CORP', '100', '10', 'cyan']
#['Toner Cartridge OKI DATA CORP', '100', '10', 'magenta']
#['Toner Cartridge OKI DATA CORP', '100', '40', 'yellow']
#['Image Drum Unit OKI DATA CORP', '20000', '-409', '']
#['Image Drum Unit OKI DATA CORP', '20000', '7969', '']
#['Image Drum Unit OKI DATA CORP', '20000', '11597', '']
#['Image Drum Unit OKI DATA CORP', '20000', '4621', '']
#['Belt Unit OKI DATA CORP', '60000', '47371', '']
#['Fuser Unit OKI DATA CORP', '60000', '26174', '']
#['Waste Toner box OKI DATA CORP', '1', '-2', '']

printer_supply_default_levels = (20, 10)

# When the printer reports -3 as fill threshold the toner
# might be empty or might have some small remaining capacities
# the exact amount is unknown. This makes the nagios state reported
# in this state configurable
printer_supply_some_remaining_status = 1

# Workaround for toners and drum units in c5900 devices
# which have equal names for the single parts.
# Add the color description to that item
def printer_supply_fix_infos(info):
    colors = []
    new_info = []
    for line in info:
        line_0 = snmp_decode_string(line[0]) # give chance for latin1->utf8 decoding
        if line_0.startswith('Toner Cartridge') \
           or line_0.startswith('Image Drum Unit'):
            if line[3]:
                colors += [ line[3] ]
                color = line[3]
            elif line[3] == '':
                color = colors[index - len(colors)]
            line_0 = '%s %s' % (color.title(), line_0)
        new_info.append([line_0] + line[1:])
    return new_info

def inventory_printer_supply(info):
    # Ignore devices which show -2 for current value and -2 for max value -> useless
    # Also fix trailing zero bytes (seen on HP Jetdirect 143)
    return [ (line[0].rstrip('\0'), "printer_supply_default_levels")
             for line in printer_supply_fix_infos(info)
             if not (line[1] == '-2' and line[2] == '-2') ] # ignore useless devices

def check_printer_supply(item, params, info):
    for line in printer_supply_fix_infos(info):
        if line[0].rstrip('\0') == item:
            maxlevel = int(line[1])
            current = saveint(line[2])
            warn, crit = params # in percent
            perfdata = [ ("pages", current, warn / 100.0 * maxlevel, crit / 100.0 * maxlevel, 0, maxlevel ) ]

            # handle cases with partial data
            if maxlevel == -2 or current in [ -3, -2, -1 ]: # no percentage possible
                if current == -1 or maxlevel == -1:
                    return (0, "OK - there are no restrictions on this supply")
                elif current == -3:
                    return (printer_supply_some_remaining_status, "%s - Some remaining" %
                            (nagios_state_names[printer_supply_some_remaining_status]), perfdata)
                elif current == -2:
                    return (3, "UNKNOWN - current level is unknown")
                elif maxlevel == -2:
                    # no percentage possible. We compare directly against levels
                    return (0, "OK - current level is %d" % current, [("pages", current)])

            leftperc = 100.0 * current / maxlevel
            infotext = "%.0f%% (levels at %.0f%% / %.0f%%)" % (leftperc, warn, crit)
            if leftperc <= crit:
                return (2, "CRIT - %s" % infotext, perfdata)
            elif leftperc <= warn:
                return (1, "WARN - %s" % infotext, perfdata)
            else:
                return (0, "OK - %s" % infotext, perfdata)

    return (3, 'UNKNOWN - not found')

check_info['printer_supply'] = (check_printer_supply, "Supply %s", 1, inventory_printer_supply)

snmp_info['printer_supply'] = ( ".1.3.6.1.2.1.43", [ '11.1.1.6', # Printer-MIB::prtMarkerSuppliesDescription
                                                     '11.1.1.8', # Printer-MIB::prtMarkerSuppliesMaxCapacity
                                                     '11.1.1.9', # Printer-MIB::prtMarkerSuppliesLevel
                                                     '12.1.1.4' ] )



check_config_variables.append("printer_supply_some_remaining_status")

snmp_scan_functions['printer_supply'] = \
    lambda oid: oid(".1.3.6.1.2.1.43.11.1.1.6.1.1") != None