-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck
executable file
·67 lines (54 loc) · 2.3 KB
/
check
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
#!/usr/bin/env python
__copyright__ = '(c) 2016 DataNexus Inc. All Rights Reserved.'
__license__ = 'APLv2.0'
__author__ = 'ckeller@datanexus.org'
import re
import sys
def main():
"""main routine"""
# default error condition is none
ec = 0
# this checks the summary
summary = re.compile(r'(?P<host>\S+)\s+:\s+ok=(?P<okay>\d+)\s+changed=(?P<changed>\d+)\s+unreachable=(?P<unreachable>\d+)\s+failed=(?P<failed>\d+)')
# this picks up the ip address (hostname not supported)
changed = re.compile(r'^changed:\s\[(?P<changed>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\]$')
# this picks up actual changes
drift = re.compile(r'(?P<drift>^[+-].+)')
# this picks up the changed file
filename = re.compile(r'before:\s(?P<file>([^\s]+))')
drifts = 0
diffs = ""
changed_file = ""
sys.stdout.write("checking confluent data platform for drift...this will take some time\n\n")
for line in sys.stdin:
m = summary.search(line)
o = drift.search(line)
f = filename.search(line)
c = changed.search(line)
if f:
changed_file = f.group('file')
if o:
if "+++" not in o.group('drift') and "---" not in o.group('drift'):
diffs += o.group('drift') + '\n'
if c:
if len(diffs) > 0:
sys.stdout.write("%s has drifted in %s:\n" % (c.group('changed'), changed_file))
sys.stdout.write("%s" % (diffs))
diffs = ""
changed_file = ""
drifts += 1
if m:
if int(m.group('unreachable')) > 0:
sys.stdout.write("%s is unreachable...check ansible logs.\n" % m.group('host'))
ec = 1
if int(m.group('failed')) > 0:
sys.stdout.write("%s has %d failure(s)...check ansible logs.\n" % (m.group('host'), int(m.group('failed'))))
ec = 1
# summary -- can be commented out to minimize verbosity with no ill effects
if drifts == 0:
sys.stdout.write("%d drifts have been identified...platform is compliant.\n" % drifts)
else:
sys.stdout.write("\n%d drifts have been identified...platform is not compliant.\n" % drifts)
sys.exit(ec)
if __name__ == '__main__':
main()