This file is indexed.

/usr/share/check_mk/checks/fileinfo is in check-mk-server 1.2.2p3-1.

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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/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.

# Example output:
# <<<fileinfo:sep(124)>>>
# 12968175080
# M:\check_mk.ini|missing
# M:\check_mk.ini|1390|12968174867
# M:\check_mk_agent.cc|86277|12968174554
# M:\Makefile|1820|12964010975
# M:\check_mk_agent.exe|102912|12968174364
# M:\crash.cc|1672|12964010975
# M:\crash.exe|20024|12968154426

# Parameters
# "minsize" : ( 5000,  4000 ),  in bytes
# "maxsize" : ( 8000,  9000 ),  in bytes
# "minage"  : ( 600,  1200 ),  in seconds
# "maxage"  : ( 6000, 12000 ), in seconds
fileinfo_groups = []

def inventory_fileinfo(info, case):
    inventory = []
    added_groups = []
    for line in info:
        if len(line) >= 3:
            if line[1] == "missing":
                continue
            groups = fileinfo_groups_of_file(line[0])
            if case == 'single' and len(groups) == 0:
                inventory.append((line[0], {}));
            if case == 'group' and len(groups) > 0:
                for group in groups:
                    if group not in added_groups:
                        added_groups.append(group)
                        inventory.append((group, \
                        { "patterns" : fileinfo_patterns_of_group(group) }))
    return inventory

def fileinfo_groups_of_file(check_filename):
    import fnmatch
    groups = []
    for line in host_extra_conf(g_hostname, fileinfo_groups):
        for group_name, pattern in line:
            if fnmatch.fnmatch(check_filename, pattern):
                groups.append(group_name)
    return groups

def fileinfo_patterns_of_group(group):
    patterns = []
    for line in host_extra_conf(g_hostname, fileinfo_groups):
        for group_name, pattern in line:
            if group_name == group:
                patterns.append(pattern)
    return patterns

def check_fileinfo(item, params, info):
    if len(info) == 0:
        return (3, "UNKNOWN - no information sent by agent")

    reftime = int(info[0][0])
    check_definition = False
    for line in info[1:]:
        if item == line[0]:
            if line[1] == "missing":
                return (3, "UNKNOWN - File not found")
            state = 0
            size = int(line[1])
            age = reftime - int(line[2])

            check_definition = [
                ("size", size, get_filesize_human_readable),
                ("age",  age,  get_age_human_readable) ]
    if check_definition == False:
        return (3, "UNKNOWN - File not found")
    return fileinfo_check_function(check_definition, params)

def check_fileinfogroups(item, params, info):
    if len(info) == 0:
        return (3, "UNKNOWN - no information sent by agent")
    import fnmatch
    reftime = int(info[0][0])

    count_all = 0
    age_oldest = None
    age_newest = 0
    size_all = 0
    #Start counting all values
    for line in info[1:]:
        for pattern in params.get('patterns',[]):
            if fnmatch.fnmatch(line[0], pattern) and str(line[1]) != 'missing':
                size_all += int(line[1])
                age = reftime - int(line[2])
                if age_oldest == None: # very first match
                    age_oldest = age
                    age_newest = age
                else:
                    age_oldest = max(age_oldest, age)
                    age_newest = min(age_newest, age)
                count_all += 1
    if age_oldest == None:
        age_oldest =0
    #Start Checking
    check_definition = [
        ("age_oldest", age_oldest, get_age_human_readable),
        ("age_newest",  age_newest,  get_age_human_readable),
        ("count", count_all, saveint),
        ("size", size_all, get_filesize_human_readable)]

    return fileinfo_check_function(check_definition, params)

def fileinfo_check_function(check_definition, params):
    state = 0
    infos = []
    perfdata = []
    for what, val, verbfunc in check_definition:
        infos.append("%s is %s" % (what, verbfunc(val)))
        warn, crit = "", ""
        for how, comp in [ ("min", "<" ), ("max", ">") ]:
            p = params.get(how + what)
            if p:
                warn, crit = p
                cfunc = eval("lambda a,b: a %s b" % comp)
                if cfunc(val, crit):
                    state = 2
                    infos[-1] += " (%s %s)(!!)" % (comp, verbfunc(crit))
                elif cfunc(val, warn):
                    state = max(state, 1)
                    infos[-1] += " (%s %s)(!)" % (comp, verbfunc(warn))
        perfdata.append((what, val, warn, crit))
    infotext = nagios_state_names[state] + " - " + ", ".join(infos)
    return (state, infotext, perfdata)


check_info["fileinfo"] = {
    "check_function"          : check_fileinfo,
    "inventory_function"      : lambda info: inventory_fileinfo(info, 'single'),
    "service_description"     : "File %s",
    "has_perfdata"            : True,
    "group"                   : "fileinfo",
}

check_info['fileinfo.groups'] = {
    "check_function"          : check_fileinfogroups,
    "inventory_function"      : lambda info: inventory_fileinfo(info, 'group'),
    "service_description"     : "File group %s",
    "has_perfdata"            : True,
    "group"                   : "fileinfo-groups",
}