This file is indexed.

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

# <<<ad_replication>>>
# showrepl_COLUMNS,Destination DC Site,Destination DC,Naming Context,Source DC Site,Source DC,\
#Transport Type,Number of Failures,Last Failure Time,Last Success Time,Last Failure Status
# showrepl_INFO,Standardname-des-ersten-Standorts,WIN2003,"DC=corp,DC=de",Standardname-des-ers\
#ten-Standorts,WIN2003-DC2,RPC,0,0,2010-07-02 13:33:27,0
# showrepl_INFO,Standardname-des-ersten-Standorts,WIN2003,"CN=Configuration,DC=corp,DC=de",Sta\
#ndardname-des-ersten-Standorts,WIN2003-DC2,RPC,0,0,2010-07-02 12:54:08,0
# showrepl_INFO,Standardname-des-ersten-Standorts,WIN2003,"CN=Schema,CN=Configuration,DC=corp,\
#DC=de",Standardname-des-ersten-Standorts,WIN2003-DC2,RPC,0,0,2010-07-02 12:46:28,0

import datetime, time

ad_replication_default_params = (20,)

def parse_ad_replication_dates(s):
    if s == '0' or s == '(never)':
        return None
    else:
        return datetime.datetime(*time.strptime(s, '%Y-%m-%d %H:%M:%S')[0:5])

def parse_ad_replication_info(info):
    lines = []
    for l in [ ' '.join(line).replace(',CN=', ';CN=').replace(',DC=', ';DC=') for line in info ]:
        lines.append(l.split(','))
    return lines

def inventory_ad_replication(info):
    inv = []
    for line in parse_ad_replication_info(info):
        item = ('%s/%s' % (line[4], line[5]), 'ad_replication_default_params')
        if line[0] == 'showrepl_INFO' and item not in inv:
            inv.append(item)
    return inv

def check_ad_replication(item, params, info):
    status    = 0
    output    = ''
    now       = datetime.datetime.now()
    foundLine = False

    for l in parse_ad_replication_info(info):
        (lineType, destSite, destDC, namingContext, sourceSite, sourceDC,
         transport, numFailures, timeLastFailure, timeLastSuccess,
         statusLastFailure ) = l

        if lineType == 'showrepl_INFO' and sourceSite+'/'+sourceDC == item:
            foundLine = True
            timeLastFailure = parse_ad_replication_dates(timeLastFailure)
            timeLastSuccess = parse_ad_replication_dates(timeLastSuccess)

            if int(numFailures) > params[0]:
                status = 2
                output += 'CRITICAL: %s/%s replication of context %s reached ' \
                          ' the threshold of maxmimum failures (%s) (Last Success: %s, ' \
                          'LastFailure: %s NumFailures: %s Status: %s), ' % \
                         (sourceSite, sourceDC, namingContext, params[0], timeLastFailure,
                          timeLastSuccess, numFailures, statusLastFailure)

            if timeLastFailure is not None and timeLastSuccess is not None \
               and timeLastFailure > timeLastSuccess:
                status = 2
                output += 'CRITICAL: %s/%s replication of context %s failed ' \
                         '(Last Success: %s, LastFailure: %s NumFailures: %s Status: %s), ' % \
                         (sourceSite, sourceDC, namingContext, timeLastFailure,
                          timeLastSuccess, numFailures, statusLastFailure)
    if not foundLine:
        return (3, 'UNKNOWN - Replication information for %s not found' % item)

    if status != 0:
        return (status, output.rstrip(', '))
    else:
        return (status, 'OK - All replications are OK.')

check_info['ad_replication'] = (check_ad_replication, "AD Replication %s",  0, inventory_ad_replication)