2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
10 # | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
11 # +------------------------------------------------------------------+
13 # This file is part of Check_MK.
14 # The official homepage is at http://mathias-kettner.de/check_mk.
16 # check_mk is free software; you can redistribute it and/or modify it
17 # under the terms of the GNU General Public License as published by
18 # the Free Software Foundation in version 2. check_mk is distributed
19 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
20 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
21 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
22 # tails. You should have received a copy of the GNU General Public
23 # License along with GNU Make; see the file COPYING. If not, write
24 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
25 # Boston, MA 02110-1301 USA.
27 # <<<ad_replication>>>
28 # showrepl_COLUMNS,Destination DC Site,Destination DC,Naming Context,Source DC Site,Source DC,\
29 #Transport Type,Number of Failures,Last Failure Time,Last Success Time,Last Failure Status
30 # showrepl_INFO,Standardname-des-ersten-Standorts,WIN2003,"DC=corp,DC=de",Standardname-des-ers\
31 #ten-Standorts,WIN2003-DC2,RPC,0,0,2010-07-02 13:33:27,0
32 # showrepl_INFO,Standardname-des-ersten-Standorts,WIN2003,"CN=Configuration,DC=corp,DC=de",Sta\
33 #ndardname-des-ersten-Standorts,WIN2003-DC2,RPC,0,0,2010-07-02 12:54:08,0
34 # showrepl_INFO,Standardname-des-ersten-Standorts,WIN2003,"CN=Schema,CN=Configuration,DC=corp,\
35 #DC=de",Standardname-des-ersten-Standorts,WIN2003-DC2,RPC,0,0,2010-07-02 12:46:28,0
37 ad_replication_default_params
= (15, 20)
40 def parse_ad_replication_dates(s
):
41 if s
== '0' or s
== '(never)':
42 return None, "unknown"
44 s_val
= time
.mktime(time
.strptime(s
, '%Y-%m-%d %H:%M:%S'))
45 s_txt
= get_relative_date_human_readable(s_val
)
49 def parse_ad_replication_info(info
):
51 for line_parts
in info
:
52 # Make lines split by , instead of spaces
53 line_txt
= ' '.join(line_parts
).replace(',CN=', ';CN=').replace(',DC=', ';DC=')
54 line_parts
= line_txt
.split(',')
55 if len(line_parts
) in [11, 10]:
56 lines
.append(line_parts
)
60 def inventory_ad_replication(info
):
62 for line
in parse_ad_replication_info(info
):
70 break # unhandled data
71 entry
= ('%s/%s' % (source_site
, source_dc
), 'ad_replication_default_params')
72 if line
[0] == 'showrepl_INFO' and entry
not in inv
:
77 def check_ad_replication(item
, params
, info
):
82 for l
in parse_ad_replication_info(info
):
84 (lineType
, _destSite
, _destDC
, naming_context
, source_site
, source_dc
, _transport
,
85 num_failures
, time_last_failure
, time_last_success
, statusLastFailure
) = l
87 (lineType
, _destSite
, naming_context
, source_site
, source_dc
, _transport
, num_failures
,
88 time_last_failure
, time_last_success
, statusLastFailure
) = l
90 break # unhandled data
92 if lineType
== 'showrepl_INFO' and source_site
+ '/' + source_dc
== item
:
94 time_last_failure
, time_last_failure_txt
= parse_ad_replication_dates(time_last_failure
)
95 time_last_success
, time_last_success_txt
= parse_ad_replication_dates(time_last_success
)
97 max_failures_warn
= params
[0]
98 max_failures_crit
= params
[1]
100 if int(num_failures
) > max_failures_warn
:
102 output
+= '(!) %s/%s replication of context %s reached ' \
103 ' the threshold of maximum failures (%s) (Last success: %s, ' \
104 'Last failure: %s, Num failures: %s, Status: %s), ' % \
105 (source_site
, source_dc
, naming_context
, max_failures_warn
,
106 time_last_success_txt
, time_last_failure_txt
, num_failures
, statusLastFailure
)
108 if int(num_failures
) > max_failures_crit
:
110 output
+= '(!!) %s/%s replication of context %s reached ' \
111 ' the threshold of maximum failures (%s) (Last success: %s, ' \
112 'Last failure: %s, Num failures: %s, Status: %s), ' % \
113 (source_site
, source_dc
, naming_context
, max_failures_crit
,
114 time_last_success_txt
, time_last_failure_txt
, num_failures
, statusLastFailure
)
116 if time_last_failure
is not None and time_last_success
is not None \
117 and time_last_failure
> time_last_success
:
119 output
+= '(!!) %s/%s replication of context %s failed ' \
120 '(Last success: %s, Last failure: %s, Num failures: %s, Status: %s), ' % \
121 (source_site
, source_dc
, naming_context
,
122 time_last_success_txt
, time_last_failure_txt
, num_failures
, statusLastFailure
)
125 return (3, 'Replication information for %s not found' % item
)
128 return (status
, output
.rstrip(', '))
129 return (status
, 'All replications are OK.')
132 check_info
["ad_replication"] = {
133 'check_function': check_ad_replication
,
134 'inventory_function': inventory_ad_replication
,
135 'service_description': 'AD Replication %s',
136 'group': 'ad_replication',