Add --only-check-contextCSN parameter
This commit is contained in:
parent
9e6de5077f
commit
36f9a09a34
1 changed files with 123 additions and 105 deletions
|
@ -159,6 +159,14 @@ parser.add_argument(
|
||||||
default=False
|
default=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"--only-check-contextCSN",
|
||||||
|
dest="onlycheckcontextcsn",
|
||||||
|
action="store_true",
|
||||||
|
help="Only check servers root contextCSN (objects check disabled, default : False)",
|
||||||
|
default=False
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-a", "--attributes",
|
"-a", "--attributes",
|
||||||
dest="attrs",
|
dest="attrs",
|
||||||
|
@ -212,6 +220,12 @@ parser.add_argument(
|
||||||
|
|
||||||
options = parser.parse_args()
|
options = parser.parse_args()
|
||||||
|
|
||||||
|
if options.nocheckcontextcsn and options.onlycheckcontextcsn:
|
||||||
|
parser.error("You can't use both --no-check-contextCSN and --only-check-contextCSN parameters and the same time")
|
||||||
|
if options.nagios:
|
||||||
|
sys.exit(3)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if not options.provider or not options.consumer:
|
if not options.provider or not options.consumer:
|
||||||
parser.error("You must provide provider and customer URI")
|
parser.error("You must provide provider and customer URI")
|
||||||
if options.nagios:
|
if options.nagios:
|
||||||
|
@ -427,92 +441,94 @@ for srv in servers:
|
||||||
LdapServersCSN[srv] = LdapServers[srv].getContextCSN(options.basedn, options.serverid)
|
LdapServersCSN[srv] = LdapServers[srv].getContextCSN(options.basedn, options.serverid)
|
||||||
logging.info('ContextCSN of %s: %s', srv, LdapServersCSN[srv])
|
logging.info('ContextCSN of %s: %s', srv, LdapServersCSN[srv])
|
||||||
|
|
||||||
logging.info('List objects from %s', srv)
|
if not options.onlycheckcontextcsn:
|
||||||
LdapObjects[srv] = {}
|
logging.info('List objects from %s', srv)
|
||||||
|
LdapObjects[srv] = {}
|
||||||
|
|
||||||
|
if options.attrs:
|
||||||
|
for obj in LdapServers[srv].search(options.basedn, options.filterstr, []):
|
||||||
|
logging.debug('Found on %s: %s', srv, obj[0][0])
|
||||||
|
LdapObjects[srv][obj[0][0]] = obj[0][1]
|
||||||
|
else:
|
||||||
|
for obj in LdapServers[srv].search(options.basedn, options.filterstr, ['entryCSN']):
|
||||||
|
logging.debug(
|
||||||
|
'Found on %s: %s / %s',
|
||||||
|
srv, obj[0][0], obj[0][1]['entryCSN'][0]
|
||||||
|
)
|
||||||
|
LdapObjects[srv][obj[0][0]] = obj[0][1]['entryCSN'][0]
|
||||||
|
|
||||||
|
logging.info('%s objects founds', len(LdapObjects[srv]))
|
||||||
|
|
||||||
|
|
||||||
|
if not options.onlycheckcontextcsn:
|
||||||
|
not_found = {}
|
||||||
|
not_sync = {}
|
||||||
|
|
||||||
|
for srv in servers:
|
||||||
|
not_found[srv] = []
|
||||||
|
not_sync[srv] = []
|
||||||
|
|
||||||
if options.attrs:
|
if options.attrs:
|
||||||
for obj in LdapServers[srv].search(options.basedn, options.filterstr, []):
|
logging.info("Check if objects a are synchronized (by comparing attributes's values)")
|
||||||
logging.debug('Found on %s: %s', srv, obj[0][0])
|
|
||||||
LdapObjects[srv][obj[0][0]] = obj[0][1]
|
|
||||||
else:
|
else:
|
||||||
for obj in LdapServers[srv].search(options.basedn, options.filterstr, ['entryCSN']):
|
logging.info('Check if objets are synchronized (by comparing entryCSN)')
|
||||||
logging.debug(
|
for obj in LdapObjects[options.provider]:
|
||||||
'Found on %s: %s / %s',
|
logging.debug('Check obj %s', obj)
|
||||||
srv, obj[0][0], obj[0][1]['entryCSN'][0]
|
for srv in LdapObjects:
|
||||||
)
|
if srv == options.provider:
|
||||||
LdapObjects[srv][obj[0][0]] = obj[0][1]['entryCSN'][0]
|
continue
|
||||||
|
if obj in LdapObjects[srv]:
|
||||||
logging.info('%s objects founds', len(LdapObjects[srv]))
|
touch = False
|
||||||
|
if LdapObjects[options.provider][obj] != LdapObjects[srv][obj]:
|
||||||
|
if options.attrs:
|
||||||
not_found = {}
|
attrs_list = []
|
||||||
not_sync = {}
|
for attr in LdapObjects[options.provider][obj]:
|
||||||
|
if attr in excl_attrs:
|
||||||
for srv in servers:
|
continue
|
||||||
not_found[srv] = []
|
if attr not in LdapObjects[srv][obj]:
|
||||||
not_sync[srv] = []
|
|
||||||
|
|
||||||
if options.attrs:
|
|
||||||
logging.info("Check if objects a are synchronized (by comparing attributes's values)")
|
|
||||||
else:
|
|
||||||
logging.info('Check if objets are synchronized (by comparing entryCSN)')
|
|
||||||
for obj in LdapObjects[options.provider]:
|
|
||||||
logging.debug('Check obj %s', obj)
|
|
||||||
for srv in LdapObjects:
|
|
||||||
if srv == options.provider:
|
|
||||||
continue
|
|
||||||
if obj in LdapObjects[srv]:
|
|
||||||
touch = False
|
|
||||||
if LdapObjects[options.provider][obj] != LdapObjects[srv][obj]:
|
|
||||||
if options.attrs:
|
|
||||||
attrs_list = []
|
|
||||||
for attr in LdapObjects[options.provider][obj]:
|
|
||||||
if attr in excl_attrs:
|
|
||||||
continue
|
|
||||||
if attr not in LdapObjects[srv][obj]:
|
|
||||||
attrs_list.append(attr)
|
|
||||||
logging.debug(
|
|
||||||
"Obj %s not synchronized: %s not present on %s",
|
|
||||||
obj, ','.join(attrs_list), srv
|
|
||||||
)
|
|
||||||
touch = True
|
|
||||||
else:
|
|
||||||
LdapObjects[srv][obj][attr].sort()
|
|
||||||
LdapObjects[options.provider][obj][attr].sort()
|
|
||||||
if LdapObjects[srv][obj][attr] != LdapObjects[options.provider][obj][attr]:
|
|
||||||
attrs_list.append(attr)
|
attrs_list.append(attr)
|
||||||
logging.debug(
|
logging.debug(
|
||||||
"Obj %s not synchronized: %s not same value(s)",
|
"Obj %s not synchronized: %s not present on %s",
|
||||||
obj, ','.join(attrs_list)
|
obj, ','.join(attrs_list), srv
|
||||||
)
|
)
|
||||||
touch = True
|
touch = True
|
||||||
if attrs_list:
|
else:
|
||||||
not_sync[srv].append("%s (%s)" % (obj, ','.join(attrs_list)))
|
LdapObjects[srv][obj][attr].sort()
|
||||||
else:
|
LdapObjects[options.provider][obj][attr].sort()
|
||||||
logging.debug(
|
if LdapObjects[srv][obj][attr] != LdapObjects[options.provider][obj][attr]:
|
||||||
"Obj %s not synchronized: %s <-> %s",
|
attrs_list.append(attr)
|
||||||
obj, LdapObjects[options.provider][obj], LdapObjects[srv][obj]
|
logging.debug(
|
||||||
)
|
"Obj %s not synchronized: %s not same value(s)",
|
||||||
not_sync[srv].append(obj)
|
obj, ','.join(attrs_list)
|
||||||
if touch and options.touch:
|
)
|
||||||
orig_value = []
|
touch = True
|
||||||
if options.touch in LdapObjects[options.provider][obj]:
|
if attrs_list:
|
||||||
orig_value = LdapObjects[options.provider][obj][options.touch]
|
not_sync[srv].append("%s (%s)" % (obj, ','.join(attrs_list)))
|
||||||
LdapServers[options.provider].touch_object(obj, options.touch, orig_value)
|
else:
|
||||||
else:
|
logging.debug(
|
||||||
logging.debug('Obj %s: not found on %s', obj, srv)
|
"Obj %s not synchronized: %s <-> %s",
|
||||||
not_found[srv].append(obj)
|
obj, LdapObjects[options.provider][obj], LdapObjects[srv][obj]
|
||||||
if options.touch:
|
)
|
||||||
orig_value = []
|
not_sync[srv].append(obj)
|
||||||
if options.touch in LdapObjects[options.provider][obj]:
|
if touch and options.touch:
|
||||||
orig_value = LdapObjects[options.provider][obj][options.touch]
|
orig_value = []
|
||||||
LdapServers[options.provider].touch_object(obj, options.touch, orig_value)
|
if options.touch in LdapObjects[options.provider][obj]:
|
||||||
|
orig_value = LdapObjects[options.provider][obj][options.touch]
|
||||||
|
LdapServers[options.provider].touch_object(obj, options.touch, orig_value)
|
||||||
|
else:
|
||||||
|
logging.debug('Obj %s: not found on %s', obj, srv)
|
||||||
|
not_found[srv].append(obj)
|
||||||
|
if options.touch:
|
||||||
|
orig_value = []
|
||||||
|
if options.touch in LdapObjects[options.provider][obj]:
|
||||||
|
orig_value = LdapObjects[options.provider][obj][options.touch]
|
||||||
|
LdapServers[options.provider].touch_object(obj, options.touch, orig_value)
|
||||||
|
|
||||||
for obj in LdapObjects[options.consumer]:
|
for obj in LdapObjects[options.consumer]:
|
||||||
logging.debug('Check obj %s of consumer', obj)
|
logging.debug('Check obj %s of consumer', obj)
|
||||||
if obj not in LdapObjects[options.provider]:
|
if obj not in LdapObjects[options.provider]:
|
||||||
logging.debug('Obj %s: not found on provider', obj)
|
logging.debug('Obj %s: not found on provider', obj)
|
||||||
not_found[options.provider].append(obj)
|
not_found[options.provider].append(obj)
|
||||||
|
|
||||||
if options.nagios:
|
if options.nagios:
|
||||||
errors = []
|
errors = []
|
||||||
|
@ -532,21 +548,22 @@ if options.nagios:
|
||||||
errors.append('ContextCSN of %s not the same of provider' % srv)
|
errors.append('ContextCSN of %s not the same of provider' % srv)
|
||||||
long_output.append('ContextCSN on LDAP server %s = %s' % (srv, LdapServersCSN[srv]))
|
long_output.append('ContextCSN on LDAP server %s = %s' % (srv, LdapServersCSN[srv]))
|
||||||
|
|
||||||
if not_found[options.consumer]:
|
if not options.onlycheckcontextcsn:
|
||||||
errors.append("%s not found object(s) on consumer" % len(not_found[options.consumer]))
|
if not_found[options.consumer]:
|
||||||
long_output.append("Object(s) not found on server %s (consumer) :" % options.consumer)
|
errors.append("%s not found object(s) on consumer" % len(not_found[options.consumer]))
|
||||||
for obj in not_found[options.consumer]:
|
long_output.append("Object(s) not found on server %s (consumer) :" % options.consumer)
|
||||||
long_output.append(" - %s" % obj)
|
for obj in not_found[options.consumer]:
|
||||||
if not_found[options.provider]:
|
long_output.append(" - %s" % obj)
|
||||||
errors.append("%s not found object(s) on provider" % len(not_found[options.provider]))
|
if not_found[options.provider]:
|
||||||
long_output.append("Object(s) not found on server %s (provider) :" % options.provider)
|
errors.append("%s not found object(s) on provider" % len(not_found[options.provider]))
|
||||||
for obj in not_found[options.provider]:
|
long_output.append("Object(s) not found on server %s (provider) :" % options.provider)
|
||||||
long_output.append(" - %s" % obj)
|
for obj in not_found[options.provider]:
|
||||||
if not_sync[options.consumer]:
|
long_output.append(" - %s" % obj)
|
||||||
errors.append("%s not synchronized object(s) on consumer" % len(not_sync[options.consumer]))
|
if not_sync[options.consumer]:
|
||||||
long_output.append("Object(s) not synchronized on server %s (consumer) :" % options.consumer)
|
errors.append("%s not synchronized object(s) on consumer" % len(not_sync[options.consumer]))
|
||||||
for obj in not_sync[options.consumer]:
|
long_output.append("Object(s) not synchronized on server %s (consumer) :" % options.consumer)
|
||||||
long_output.append(" - %s" % obj)
|
for obj in not_sync[options.consumer]:
|
||||||
|
long_output.append(" - %s" % obj)
|
||||||
if errors:
|
if errors:
|
||||||
print("CRITICAL: " + ', '.join(errors) + "\n\n" + "\n".join(long_output)) # pylint: disable=print-statement
|
print("CRITICAL: " + ', '.join(errors) + "\n\n" + "\n".join(long_output)) # pylint: disable=print-statement
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
@ -571,18 +588,19 @@ else:
|
||||||
logging.warning('ContextCSN of %s not the same of provider', srv)
|
logging.warning('ContextCSN of %s not the same of provider', srv)
|
||||||
noerror = False
|
noerror = False
|
||||||
|
|
||||||
if not_found[srv]:
|
if not options.onlycheckcontextcsn:
|
||||||
logging.warning(
|
if not_found[srv]:
|
||||||
'Not found objects on %s :\n - %s',
|
logging.warning(
|
||||||
srv, '\n - '.join(not_found[srv])
|
'Not found objects on %s :\n - %s',
|
||||||
)
|
srv, '\n - '.join(not_found[srv])
|
||||||
noerror = False
|
)
|
||||||
if not_sync[srv]:
|
noerror = False
|
||||||
logging.warning(
|
if not_sync[srv]:
|
||||||
'Not sync objects on %s: %s',
|
logging.warning(
|
||||||
srv, '\n - '.join(not_sync[srv])
|
'Not sync objects on %s: %s',
|
||||||
)
|
srv, '\n - '.join(not_sync[srv])
|
||||||
noerror = False
|
)
|
||||||
|
noerror = False
|
||||||
|
|
||||||
if noerror:
|
if noerror:
|
||||||
logging.info('No sync problem detected')
|
logging.info('No sync problem detected')
|
||||||
|
|
Loading…
Reference in a new issue