def parse_neighbour(self, n): """Convert an ldb neighbour object into a python dictionary""" dsa_objectguid = str(n.source_dsa_obj_guid) d = { 'NC dn': n.naming_context_dn, "DSA objectGUID": dsa_objectguid, "last attempt time": nttime2string(n.last_attempt), "last attempt message": drs_errmsg(n.result_last_attempt), "consecutive failures": n.consecutive_sync_failures, "last success": nttime2string(n.last_success), "NTDS DN": str(n.source_dsa_obj_dn), 'is deleted': False } try: self.samdb.search(base="<GUID=%s>" % dsa_objectguid, scope=ldb.SCOPE_BASE, attrs=[]) except ldb.LdbError as e: (errno, _) = e.args if errno == ldb.ERR_NO_SUCH_OBJECT: d['is deleted'] = True else: raise try: (site, server) = drs_parse_ntds_dn(n.source_dsa_obj_dn) d["DSA"] = "%s\%s" % (site, server) except RuntimeError: pass return d
def print_neighbour(self, n): '''print one set of neighbour information''' self.message("%s" % n.naming_context_dn) try: (site, server) = drs_parse_ntds_dn(n.source_dsa_obj_dn) self.message("\t%s\%s via RPC" % (site, server)) except RuntimeError: self.message("\tNTDS DN: %s" % n.source_dsa_obj_dn) self.message("\t\tDSA object GUID: %s" % n.source_dsa_obj_guid) self.message("\t\tLast attempt @ %s %s" % (nttime2string(n.last_attempt), drs_errmsg(n.result_last_attempt))) self.message("\t\t%u consecutive failure(s)." % n.consecutive_sync_failures) self.message("\t\tLast success @ %s" % nttime2string(n.last_success)) self.message("")
def parse_neighbour(self, n): """Convert an ldb neighbour object into a python dictionary""" d = { 'NC dn': n.naming_context_dn, "DSA objectGUID": str(n.source_dsa_obj_guid), "last attempt time": nttime2string(n.last_attempt), "last attempt message": drs_errmsg(n.result_last_attempt), "consecutive failures": n.consecutive_sync_failures, "last success": nttime2string(n.last_success), "NTDS DN": str(n.source_dsa_obj_dn) } try: (site, server) = drs_parse_ntds_dn(n.source_dsa_obj_dn) d["DSA"] = "%s\%s" % (site, server) except RuntimeError: pass return d
creds.set_username("Administrator") creds.set_password("AdMatayOctober") creds.set_workstation("") creds.set_domain("") ctx = Context("ip_of_dc",lp,creds) drsuapi_connect(ctx) req = DsReplicaGetInfoRequest1() req.info_type = DRSUAPI_DS_REPLICA_INFO_NEIGHBORS (info_type,info) = ctx.drsuapi.DsReplicaGetInfo(ctx.drsuapi_handle,1,req) current_time = datetime.datetime.now() for dc in info.array: if(dc.naming_context_dn == 'DC=example,DC=com'): dictonary = {} dictonary['source'] = "ip_of_dc" dictonary['namingcontext'] = dc.naming_context_dn last_success = nttime2string(dc.last_success) difference = current_time - datetime.datetime.strptime(last_success.rsplit(' ',1)[0],'%a %B %d %H:%M:%S %Y') if(difference.total_seconds() > 0): dictonary['time_from_last_success'] = str(difference) else: dictonary['time_from_last_success'] = "0 seconds" dictonary['Destination'] = str(dc.source_dsa_obj_dn).split(",")[1].split("CN=")[1] error_code,error = dc.result_last_attempt if(error_code == 0): error = "last replication was successfull" dictonary['message'] = error else: continue print("Source: {}\nDestination: {}\nLast Replicate: {} ago\nError: {}".format(dictonary['source'],dictonary['Destination'],dictonary['time_from_last_success'],dictonary['message']))