This file is indexed.

/usr/share/check_mk/checks/md 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
#!/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.


# Example for output from agent (contents of /proc/mdstat):
# ---------------------------------------------------------
#    Personalities : [raid1]
#    md1 : active raid1 dm-19[0] dm-9[1]
#          20971456 blocks [2/2] [UU]
#          20971456 blocks super 1.2 [2/2] [UU]
#
#    md2 : active (auto-read-only) raid1 sda6[0] sdb6[1]
#          4200952 blocks super 1.0 [2/2] [UU]
#          bitmap: 0/9 pages [0KB], 256KB chunk
#
#          unused devices: <none>
# ---------------------------------------------------------

# Another example (with RAID 5 and spare disk (md2) and a RAID-0
# device (md3)
# ---------------------------------------------------------
# Personalities : [raid1] [raid6] [raid5] [raid4]
# md2 : active raid5 sde1[3](S) sdd1[0] sdg1[2] sdf1[1]
#       976767872 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]
#
# md0 : active raid1 sdb1[1] sda1[0]
#       104320 blocks [2/2] [UU]
#
# md1 : active raid1 sdb3[1] sda3[0]
#       486239232 blocks [2/2] [UU]
#
# md4 : active (auto-read-only) raid1 sda6[0] sdb6[1]
#       4200952 blocks super 1.0 [2/2] [UU]
#         resync=PENDING
#       bitmap: 9/9 pages [36KB], 256KB chunk
#
# md3 : active raid0 sdb3[0] sda3[1]
#       16386048 blocks 64k chunks
#
# unused devices: <none>
# ---------------------------------------------------------

def inventory_md(info):
    inventory = []
    for line in info:
        if len(line) < 3:
            continue
        if line[0].startswith("md") and line[1] == ':':
            device = line[0]
            raid_state = line[2]
        elif line[1] == 'blocks':
            if line[-1] != "chunks": # ignore RAID 0 devices
                disk_state = line[-1][1:-1]
                inventory.append( (device, '%s / %s' % (raid_state, disk_state), None) )
    return inventory

def check_md(item, params, info):
    raid_state = ''
    its_next = False
    for line in info:
        if line[0] == item and line[1] == ':':
            raid_state = line[2]
            if raid_state != 'active' and raid_state != 'active(auto-read-only)':
                return (2, "CRIT - raid state is '%s' (should be 'active')" % (raid_state,))
            # Usually (auto-read-only) sticks to active without a space.
            # But on some kernels it appears separated by a space
            if line[3] == '(auto-read-only)':
                del line[3]
            num_disks = len([x for x in line[4:] if not x.endswith("(S)") ]) # omit spare disks
            its_next = True
        elif its_next:
            disk_state_1 = line[-2]
            disk_state_2 = line[-1]
            if disk_state_1 != '[%d/%d]' % (num_disks, num_disks) or \
               disk_state_2 != '[' + ("U"*num_disks) + ']':
                return (2, 'CRIT - disk state is %s %s (expected %d disks to be up)' %
                        (disk_state_1, disk_state_2, num_disks))
            else:
                return (0, 'OK - raid active, disk state is %s %s' % (disk_state_1, disk_state_2))
    return (2, 'CRIT - no raid device %s' % item)


check_info['md'] = (check_md, "MD Softraid %s", 0, inventory_md)