This file is indexed.

/usr/share/check_mk/checks/win_dhcp_pools 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/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.

# Author: Lars Michelsen <lm@mathias-kettner.de>

# Example outputs from agent:
#
# <<<win_dhcp_pools>>>
#
# MIB-Anzahl:
#     Entdeckungen = 0.
#     Angebote = 0.
#     Anforderungen = 0.
#     Acks = 0.
#     Naks = 0.
#     Abweisungen = 0.
#     Freigaben = 0.
#     ServerStartTime = Dienstag, 29. Juni 2010 19:08:55
#     Bereiche = 1.
#     Subnetz = 192.168.123.0.
#         Anzahl der verwendeten Adressen = 0.
#         Anzahl der freien Adressen = 239.
#         Anzahl der anstehenden Angebote = 0.
#
# MIBCounts:
#         Discovers = 0.
#         Offers = 0.
#         Requests = 0.
#         Acks = 1.
#         Naks = 0.
#         Declines = 0.
#         Releases = 0.
#         ServerStartTime = Sunday, May 25, 2008 12:38:06 PM
#         Scopes = 1.
#         Subnet = 172.16.11.0.
#                 No. of Addresses in use = 1.
#                 No. of free Addresses = 23.
#                 No. of pending offers = 0.

win_dhcp_pools_default_levels = (10, 5)

win_dhcp_pools_stats_translate = {
    'Entdeckungen': 'Discovers',
    'Angebote': 'Offers',
    'Anforderungen': 'Requests',
    'Acks': 'Acks',
    'Naks': 'Nacks',
    'Abweisungen': 'Declines',
    'Freigaben': 'Releases',
    'Subnetz': 'Subnet',
    'Bereiche': 'Scopes',
    'Anzahl der verwendeten Adressen': 'No. of Addresses in use',
    'Anzahl der freien Adressen': 'No. of free Addresses',
    'Anzahl der anstehenden Angebote': 'No. of pending offers',
}

def parse_win_dhcp_pools(info):
    return [ ' '.join(line).rstrip('.').split(' = ') for line in info ]

def inventory_win_dhcp_pools(info):
    inventory = []
    for line in parse_win_dhcp_pools(info):
        if win_dhcp_pools_stats_translate.get(line[0], line[0]) == 'Subnet':
            inventory.append((line[1], 'win_dhcp_pools_default_levels'))
    return inventory

def check_win_dhcp_pools(item, params, info):
    inBlock = False
    poolStats = []
    status = 0
    for line in parse_win_dhcp_pools(info):
        if win_dhcp_pools_stats_translate.get(line[0], line[0]) == 'Subnet' and line[1] == item:
            inBlock = True
            continue
        if inBlock:
            poolStats.append(saveint(line[1]))
        if len(poolStats) == 3:
            break

    if len(poolStats) == 3:
        used, free, pending = poolStats
        size = used + free + pending

        if free > 0:
            percFree = 100 - size / free
        else:
            percFree = 0

        if percFree < params[1]:
            status = 2
        elif percFree < params[0]:
            status = 1

        perfdata = [ ('free', free, params[0], params[1], 0, size),
                     ('used', used, None, None, 0, size),
                     ('pending', pending, None, None, 0, size) ]

        return (status, '%s - Addresses Free: %d, Used: %d, Pending: %d' %
                              (nagios_state_names[status], free, used, pending), perfdata)
    else:
        return (3, 'UNKNOWN - Pool information not found')

def inventory_win_dhcp_pools_stats(info):
    return [ (None, None) for line in info if line[0] != '' ]

def check_win_dhcp_pools_stats(item, params, info):
    output = ''
    perfdata = []
    this_time = int(time.time())
    timedif = 0

    for line in parse_win_dhcp_pools(info):
        if len(line) > 0:
            key = win_dhcp_pools_stats_translate.get(line[0], line[0])
            if key in [ 'Discovers', 'Offers', 'Requests', 'Acks',
                        'Nacks', 'Declines', 'Releases', 'Scopes' ]:
                value = saveint(line[1])
                try:
                    timedif, per_sec = get_counter("win_dhcp_stats.%s" % key, this_time, value)
                except MKCounterWrapped:
                    per_sec = 0
                    pass
                output += '%s: %.0f/s, ' % (key, per_sec)
                perfdata.append((key, per_sec))

    if output == '':
        return (3, "UNKNOWN - Information not available")
    else:
        if timedif != 0:
            output = 'In last %d secs: %s' % (timedif, output)
        return (0, "OK - %s" % (output.rstrip(', ')), perfdata)

check_info['win_dhcp_pools'] = (check_win_dhcp_pools, "DHCP Pool %s",  1, inventory_win_dhcp_pools)
check_info['win_dhcp_pools.stats'] = (check_win_dhcp_pools_stats, "DHCP Stats",  1, inventory_win_dhcp_pools_stats)