-
Notifications
You must be signed in to change notification settings - Fork 1
/
test1.py
676 lines (525 loc) · 25.9 KB
/
test1.py
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
# from fastapi import FastAPI, Header, HTTPException
# from fastapi.responses import JSONResponse
# from pymongo import MongoClient
# from bson import ObjectId
# from datetime import datetime
# import pytz
# import uvicorn
# import logging
# logging.basicConfig(filename='app.log', level=logging.INFO)
# client = MongoClient("mongodb://unoadmin:[email protected]:27019,10.0.1.6:27020,10.0.1.6:27021/?authSource=admin&replicaSet=sso-rs&retryWrites=true&w=majority")
# app = FastAPI()
# def check_app_overdue(app_ids, cymmetri_logins):
# db = client["cymmetri-datascience"]
# current_utc_time = datetime.utcnow()
# #print("current_utc_time: ",current_utc_time)
# matching_users = []
# messages = []
# for app_id in app_ids:
# #print("app_id: ",app_id)
# #print("appidsssss: ",app_ids)
# for cymmetri_login in cymmetri_logins:
# #print("cymmetri_login: ",cymmetri_login)
# users = db.user.find({
# "end_date": {"$exists": True, "$lt": current_utc_time},
# "status": "ACTIVE",
# f"provisionedApps.{app_id}.login.login": cymmetri_login
# })
# #print("jnjldnenedend")
# matching_users.extend(users)
# #print("usersssss: ",matching_users)
# #print(len(matching_users))
# for user in matching_users:
# user_id = str(user["_id"])
# display_name = user.get("displayName", "N/A")
# end_date = user.get("end_date", "N/A")
# for app_id, app_details in user.get("provisionedApps", {}).items():
# app_login = app_details.get("login", {}).get("login", "N/A")
# app_status = app_details.get("login", {}).get("status", "N/A")
# if app_status != "SUCCESS_DELETE" or "SUCCESS_UPDATE":
# message = (f"User ID: {user_id}, Display Name: {display_name}, "
# f"App ID: {app_id}, App Status: {app_status}, "
# f"Cymmetri Status: {user['status']}, "
# f"End Date: {end_date}, Current Date: {current_utc_time}")
# messages.append(message)
# # Print each message only once
# for message in messages:
# #print("Break Type:: App_Overdue")
# #print(message)
# @app.post("/missing_records")
# async def missing_records(db_name: str = Header("cymmetri-datascience")):
# # Function to connect to the MongoDB client and return the specified database
# def connect_to_db(db_name):
# client = MongoClient("mongodb://unoadmin:[email protected]:27019,10.0.1.6:27020,10.0.1.6:27021/?authSource=admin&replicaSet=sso-rs&retryWrites=true&w=majority")
# return client[db_name]
# # Function to get Indian time
# def get_indian_time():
# tz = pytz.timezone('Asia/Kolkata')
# return datetime.now(tz)
# # Function to fetch logins excluding CYMMETRI
# def fetch_logins_exclude_cymmetri(db):
# cymmetri_logins = set()
# app_ids = set()
# recon_metadata_collection = db['reconReportMetadata']
# recon_ids = [doc['reconciliationId'] for doc in recon_metadata_collection.find()]
# recon_pull_collection = db["reconciliationPull"]
# user_collection = db["user"]
# for recon_id in recon_ids:
# recon_object_id = ObjectId(recon_id)
# matching_docs = recon_pull_collection.find({"_id": recon_object_id})
# for doc in matching_docs:
# appId = doc['applicationId']
# if appId != "CYMMETRI":
# app_ids.add(appId)
# user_docs = user_collection.find({"provisionedApps." + appId + ".login.login": {"$exists": True}})
# for user_doc in user_docs:
# login_login = user_doc["provisionedApps"][appId]["login"]["login"]
# cymmetri_logins.add(login_login)
# cymmetri_logins_list = list(cymmetri_logins)
# logging.info("Cymmetri Logins: %s", cymmetri_logins_list)
# return app_ids, cymmetri_logins_list
# # Function to fetch matching records
# def fetch_matching_records(db):
# matching_records = []
# target_logins = []
# recon_metadata_collection = db['reconReportMetadata']
# sync_data_collection = db['syncDataForRecon']
# for recon_metadata_doc in recon_metadata_collection.find():
# batch_id = recon_metadata_doc.get('batchId')
# reconciliation_id = recon_metadata_doc.get('reconciliationId')
# sync_data_docs = sync_data_collection.find({
# 'batchId': batch_id,
# 'reconciliationId': reconciliation_id
# })
# for sync_data_doc in sync_data_docs:
# matching_records.append(sync_data_doc)
# target_logins.append(sync_data_doc['data']['login'])
# #print("Target Logins ", target_logins)
# return matching_records, target_logins
# # Function to insert missing logins into recon_break_type collection
# def insert_missing_logins(missing_logins,db):
# sync_data_collection = db['syncDataForRecon']
# # Accessing recon_break_type collection
# recon_break_type_collection = db['recon_break_type']
# # Accessing break_count collection
# break_count_collection = db['breakReportMetadata']
# # Update break count
# inserted_records_count = 0
# inserted_object_ids = []
# for index, missing_login in enumerate(missing_logins, start=1):
# # Find the corresponding document in syncDataForRecon collection
# sync_data_doc = sync_data_collection.find_one({'data.login': missing_login})
# if sync_data_doc:
# # Extract batchId and reconciliationId
# batch_id = sync_data_doc.get('batchId')
# reconciliation_id = sync_data_doc.get('reconciliationId')
# # Create document to insert into recon_break_type collection
# break_doc = {
# 'batchId': batch_id,
# 'reconciliationId': reconciliation_id,
# 'loginId': missing_login,
# 'breakType': 'Account created outside Cymmetri',
# 'performedAt': datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + "+00:00"
# }
# # Insert document into recon_break_type collection
# result = recon_break_type_collection.insert_one(break_doc)
# # Store the inserted object ID
# inserted_object_ids.append(result.inserted_id)
# # Increment the count of inserted records
# inserted_records_count += 1
# else:
# #print(f"No syncDataForRecon document found for login: {missing_login}")
# # Print count of total missing values and count of inserted records
# #print(f"Processed {index}/{len(missing_logins)} missing logins. {inserted_records_count} records inserted.")
# # Update break count document
# indian_time = get_indian_time()
# formatted_indian_time = indian_time.strftime('%Y-%m-%d %H:%M:%S %Z%z')
# break_count_document = {
# "status": f"{inserted_records_count} new records inserted",
# "performedAt": formatted_indian_time,
# "objectIDs": [{"$oid": str(oid)} for oid in inserted_object_ids] # Convert ObjectIDs to the desired format
# }
# break_count_collection.insert_one(break_count_document)
# db = connect_to_db(db_name)
# app_ids, cymmetri_logins = fetch_logins_exclude_cymmetri(db)
# matching_records, target_logins = fetch_matching_records(db)
# missing_logins = set(target_logins) - set(cymmetri_logins)
# check_app_overdue(app_ids, cymmetri_logins)
# insert_missing_logins(missing_logins, db)
# return JSONResponse(content={"message": "Missing records processed successfully."})
# if __name__ == "__main__":
# uvicorn.run(app, host="127.0.0.1", port=5000)
# import redis
# import json
# # Redis connection parameters
# REDIS_HOST = '10.0.1.7'
# REDIS_PORT = 6379
# REDIS_USERNAME = 'infra'
# REDIS_PASSWORD = 'infra@123'
# REDIS_DATABASE = 1
# # Connect to Redis
# try:
# r = redis.Redis(
# host=REDIS_HOST,
# port=REDIS_PORT,
# username=REDIS_USERNAME,
# password=REDIS_PASSWORD,
# db=REDIS_DATABASE,
# decode_responses=True # Decode responses to strings
# )
# # Test the connection
# #print("Connected to Redis successfully!")
# # Key of the data
# key = "65fc04ae60643f5a285a06c6"
# # Get the string value from Redis
# string_value = r.get(key)
# # Parse the string value as JSON
# if string_value:
# data_list = json.loads(string_value)
# # Count the number of elements in the list
# num_elements = len(data_list)
# #print("Number of elements in the list:", num_elements)
# else:
# #print("Key not found or value is empty.")
# except Exception as e:
# #print("Failed to connect to Redis:", e)
# import pymongo
# import json
# import redis
# from datetime import datetime
# # Redis configurations
# REDIS_HOST = '10.0.1.7'
# REDIS_PORT = 6379
# REDIS_USERNAME = 'infra'
# REDIS_PASSWORD = 'infra@123'
# REDIS_DATABASE = 1
# # Key for Redis hashmap
# redis_key = '65fc04ae60643f5a285a06c6'
# redis_client = redis.StrictRedis(host=REDIS_HOST,
# port=REDIS_PORT,
# username=REDIS_USERNAME,
# password=REDIS_PASSWORD,
# db=REDIS_DATABASE,
# decode_responses=True)
# # Connect to MongoDB
# client = pymongo.MongoClient("mongodb://unoadmin:[email protected]:27019,10.0.1.6:27020,10.0.1.6:27021/?authSource=admin&replicaSet=sso-rs&retryWrites=true&w=majority")
# db = client["cymmetri-datascience"]
# syncDataForRecon = db["syncDataForRecon"]
# shRecordCymmetriAppLogins = db["shRecordCymmetriAppLogins"]
# key = 'cymmetri-datascience_sh_recon_65fc04ae60643f5a285a06c6_fdf52a93-17a3-4b3d-b2fb-b72df8db4fc6'
# recon_report_metadata_id = redis_client.hget(key, 'reconReportMetadataId')
# reconciliationId = redis_client.hget(key, "reconciliationId")
# batch_id = redis_client.hget(key, 'batchId')
# # Print the values
# #print("reconReportMetadataId:", recon_report_metadata_id)
# #print("batchId:", batch_id)
# #print("reconciliationId", reconciliationId)
# # Initialize sets to store Reconciliation IDs and Logins
# reconciliation_ids = set()
# Target_logins = set()
# # Set reconReportMetadataId and batch_id
# reconReportMetadataId = recon_report_metadata_id
# batch_id = batch_id
# # Set up the change stream to watch for new insertions
# with syncDataForRecon.watch(full_document='updateLookup') as stream:
# for change in stream:
# if change["operationType"] == "insert":
# new_document = change["fullDocument"]
# reconciliation_id = new_document.get("reconciliationId")
# login = new_document.get("data", {}).get("login")
# if reconciliation_id and login:
# #print("New Record Inserted:")
# # Append the values to the respective sets
# reconciliation_ids.add(reconciliation_id) # Use add for sets
# Target_logins.add(login)
# #print("Reconciliation IDs:", reconciliation_ids)
# #print("Target_Logins:", Target_logins)
# # Convert Target_logins set to a list and serialize to JSON
# target_logins_list = list(Target_logins)
# ##print("target_logins_list",target_logins_list)
# target_logins_json = json.dumps(target_logins_list, ensure_ascii=False)
# # Store serialized JSON in Redis
# redis_client.set(redis_key, target_logins_json)
# reconciliation_id = str(reconciliation_ids.pop())
# # Iterate over each login in Target_logins
# for login in Target_logins:
# # Check if the document already exists for the login
# existing_document = shRecordCymmetriAppLogins.find_one({"Cymmetri_Logins": login})
# if existing_document:
# # If the document exists, update the existing document
# # Update logic goes here
# pass # Placeholder to maintain the structure
# else:
# # If the document doesn't exist, insert a new document
# # Convert set to comma-separated string
# reconciliation_ids_str = ','.join(map(str, reconciliation_ids)) if reconciliation_ids else None
# data_to_insert = {
# "reconciliation_ids": reconciliation_ids_str, # Store reconciliation_ids as a string
# "batch_id": batch_id,
# "reconReportMetadataId": recon_report_metadata_id,
# "Cymmetri_Logins": login,
# "created": datetime.now()
# }
# shRecordCymmetriAppLogins.insert_one(data_to_insert)
# import pymongo
# import json
# import redis
# from datetime import datetime
# # Redis configurations
# REDIS_HOST = '10.0.1.7'
# REDIS_PORT = 6379
# REDIS_USERNAME = 'infra'
# REDIS_PASSWORD = 'infra@123'
# REDIS_DATABASE = 1
# # Key for Redis hashmap
# redis_key = '65fc04ae60643f5a285a06c6'
# redis_client = redis.StrictRedis(host=REDIS_HOST,
# port=REDIS_PORT,
# username=REDIS_USERNAME,
# password=REDIS_PASSWORD,
# db=REDIS_DATABASE,
# decode_responses=True)
# # Connect to MongoDB
# client = pymongo.MongoClient("mongodb://unoadmin:[email protected]:27019,10.0.1.6:27020,10.0.1.6:27021/?authSource=admin&replicaSet=sso-rs&retryWrites=true&w=majority")
# db = client["cymmetri-datascience"]
# syncDataForRecon = db["syncDataForRecon"]
# shRecordCymmetriAppLogins = db["shRecordCymmetriAppLogins"]
# key = 'cymmetri-datascience_sh_recon_65fc04ae60643f5a285a06c6_8f975832-1deb-4f44-a09b-ddbfb4491eaa'
# recon_report_metadata_id = redis_client.hget(key, 'reconReportMetadataId')
# reconciliationId = redis_client.hget(key, "reconciliationId")
# batch_id = redis_client.hget(key, 'batchId')
# # Print the values
# #print("reconReportMetadataId:", recon_report_metadata_id)
# #print("batchId:", batch_id)
# #print("reconciliationId", reconciliationId)
# # Initialize sets to store Reconciliation IDs and Logins
# reconciliation_ids = set()
# Target_logins = set()
# # Set reconReportMetadataId and batch_id
# reconReportMetadataId = recon_report_metadata_id
# batch_id = batch_id
# # Function to insert records into MongoDB
# def insert_records(records):
# inserted_count = 0
# for record in records:
# try:
# shRecordCymmetriAppLogins.insert_one(record)
# inserted_count += 1
# except Exception as e:
# #print(f"Error inserting record: {e}")
# return inserted_count
# # Set up the change stream to watch for new insertions
# with syncDataForRecon.watch(full_document='updateLookup') as stream:
# for change in stream:
# if change["operationType"] == "insert":
# new_document = change["fullDocument"]
# reconciliation_id = new_document.get("reconciliationId")
# login = new_document.get("data", {}).get("login")
# if reconciliation_id and login:
# #print("New Record Inserted:")
# # Append the values to the respective sets
# reconciliation_ids.add(reconciliation_id) # Use add for sets
# Target_logins.add(login)
# #print("Reconciliation IDs:", reconciliation_ids)
# #print("Target_Logins:", Target_logins)
# # Convert Target_logins set to a list and serialize to JSON
# target_logins_list = list(Target_logins)
# target_logins_json = json.dumps(target_logins_list, ensure_ascii=False)
# # Store serialized JSON in Redis
# redis_client.set(redis_key, target_logins_json)
# # Insert records into MongoDB in batches
# batch_size = 1000
# total_records = len(target_logins_list)
# inserted_count = 0
# for i in range(0, total_records, batch_size):
# batch_records = []
# for login in target_logins_list[i:i+batch_size]:
# existing_document = shRecordCymmetriAppLogins.find_one({"Target_logins": login})
# if existing_document:
# if not isinstance(existing_document.get("reconciliation_ids"), list):
# reconciliation_ids = set(existing_document.get("reconciliation_ids"))
# else:
# reconciliation_ids = set(existing_document.get("reconciliation_ids"))
# if reconciliationId not in reconciliation_ids:
# reconciliation_ids.add(reconciliationId)
# reconciliation_ids_str = ','.join(reconciliation_ids)
# shRecordCymmetriAppLogins.update_one({"_id": existing_document["_id"]}, {"$set": {"reconciliation_ids": reconciliation_ids_str}})
# else:
# record_to_insert = {
# "reconciliation_ids": [reconciliationId], # Store reconciliationId directly as a string
# "batch_id": batch_id,
# "reconReportMetadataId": recon_report_metadata_id,
# "Target_logins": login,
# "created": datetime.now()
# }
# batch_records.append(record_to_insert)
# inserted_count += insert_records(batch_records)
# #print(f"Inserted {inserted_count} out of {total_records} records.")
from pymongo import MongoClient
from datetime import datetime
import redis
import json
from pymongo import MongoClient
from datetime import datetime
# Connect to MongoDB
client = MongoClient("mongodb://unoadmin:[email protected]:27019,10.0.1.6:27020,10.0.1.6:27021/?authSource=admin&replicaSet=sso-rs&retryWrites=true&w=majority")
db = client["cymmetri-datascience"]
shRecordCymmetriAppLogins = db["shRecordCymmetriAppLogins"]
REDIS_HOST = '10.0.1.7'
REDIS_PORT = 6379
REDIS_USERNAME = 'infra'
REDIS_PASSWORD = 'infra@123'
REDIS_DATABASE = 1
# Key for Redis hashmap
redis_key = '65fc04ae60643f5a285a06c6'
# Connect to Redis
redis_client = redis.StrictRedis(host=REDIS_HOST,
port=REDIS_PORT,
username=REDIS_USERNAME,
password=REDIS_PASSWORD,
db=REDIS_DATABASE,
decode_responses=True)
# Fetch hash data from Redis
redis_client = redis.StrictRedis(host=REDIS_HOST,
port=REDIS_PORT,
username=REDIS_USERNAME,
password=REDIS_PASSWORD,
db=REDIS_DATABASE,
decode_responses=True)
# Fetch string data from Redis
string_data = redis_client.get(redis_key)
# Convert the JSON-formatted string to a set
if string_data:
target_logins_list = json.loads(string_data)
Target_logins = set(target_logins_list)
#print("Target_logins",Target_logins)
else:
#print("No data found in Redis for the given key.")
redis_key1 = 'cymmetri-datascience_sh_recon_65fc04ae60643f5a285a06c6_f422d354-9a2f-4463-9031-e00f2394bab1'
# Connect to Redis
redis_client = redis.StrictRedis(host=REDIS_HOST,
port=REDIS_PORT,
username=REDIS_USERNAME,
password=REDIS_PASSWORD,
db=REDIS_DATABASE,
decode_responses=True)
# Fetch hash data from Redis
data = redis_client.hgetall(redis_key1)
#print("data",data)
#decoded_data = {key.decode(): value.decode() for key, value in data.items()}
reconReportMetadataId = data.get('reconReportMetadataId')
#print("reconReportMetadataId",reconReportMetadataId)
reconciliationId = data.get("reconciliationId")
#print("reconciliationId",reconciliationId)
AppName = data.get("appName")
#print("AppName",AppName)
appId = data.get("appId")
#print("appId",appId)
batchId = data.get("batchId")
#print("batchId",batchId)
#Insert records into MongoDB
try:
for login in Target_logins:
data_to_insert = {
"reconciliation_ids": reconciliationId,
"batch_id": batchId,
"reconReportMetadataId": reconReportMetadataId,
"Target_logins": login,
"created": datetime.now()
}
# Insert only if the record does not exist
shRecordCymmetriAppLogins.update_one(
{"Target_logins": login},
{"$setOnInsert": data_to_insert},
upsert=True)
#print("Data Inserted Sucessfully Into Collection shRecordCymmetriAppLogins")
except Exception as e:
#print(e)
# Extract required fields
cymmetri_logins = json.loads(data.get("Cymmetri_logins", "[]"))
Final_Overdue = json.loads(data.get("final_app_overdue", "[]"))
# Convert final_app_overdue to set
#final_app_overdue_set = {item["cymmetriLogin"] for item in final_app_overdue}
#print("Cymmetri_logins:", cymmetri_logins)
#print("Final App Overdue Set:", Final_Overdue)
# # break_type_in_cymmetri_only = False
# # break_type_in_target_only = False
# # break_type_overdue = False
# AppName = "Active Directory"
# reconReportMetadataId = "65fc35eea58da1531da9f8a9"
# appId = "653f482a0d2e4b5f289727ff"
# reconciliationId = "65fc04ae60643f5a285a06c6"
Cymmetri_Logins = set(cymmetri_logins)
# # # Find common logins between Logins set and cymmetri_logins_set
# # common_logins = Target_logins.intersection(cymmetri_logins_set)
# # break_type_in_target_only = Target_logins - cymmetri_logins_set
# # break_type_in_cymmetri_only = cymmetri_logins_set - Target_logins
# # #print("break_type_in_target_only: ",break_type_in_target_only)
# # #print("break_type_in_cymmetri_only: ",break_type_in_cymmetri_only)
#find the app_overdue
# app_overdue_logins_cymmetri = []
# for item in Final_Overdue:
# ##print("Cymmetri_Logins",item["cymmetriLogin"])
# app_overdue_logins_cymmetri.append(item['cymmetriLogin'])
# #print("app_overdue_logins_cymmetri",app_overdue_logins_cymmetri)
# app_overdue_logins_target = []
# for item in Final_Overdue:
# ##print("App_Logins",item["appLogin"])
# app_overdue_logins_target.append(item['appLogin'])
# #print("app_overdue_logins_target",app_overdue_logins_target)
# break_type_overdue = Target_logins.intersection(app_overdue_logins_cymmetri)
# #print("break_type_overdue",break_type_overdue)
def find_break_types_and_insert(target_logins, cymmetri_logins, final_overdue):
# Find break_type_in_target_only
break_type_in_target_only = target_logins - set(cymmetri_logins)
# Find break_type_in_cymmetri_only
break_type_in_cymmetri_only = set(cymmetri_logins) - target_logins
# Find app_overdue_logins_cymmetri
app_overdue_logins_cymmetri = [item['cymmetriLogin'] for item in final_overdue]
# Find app_overdue_logins_target
app_overdue_logins_target = [item['appLogin'] for item in final_overdue]
# Find break_type_overdue
break_type_overdue = set(target_logins).intersection(app_overdue_logins_cymmetri)
#print("break_type_overdue",break_type_overdue)
# Connect to MongoDB
client = MongoClient("mongodb://unoadmin:[email protected]:27019,10.0.1.6:27020,10.0.1.6:27021/?authSource=admin&replicaSet=sso-rs&retryWrites=true&w=majority")
db = client["cymmetri-datascience"]
collection = db["shReconBreakRecords"]
# Insert records for break_type_in_target_only
for login in break_type_in_target_only:
record = {
"reconciliationId": reconciliationId,
"AppName": AppName,
"appId": appId,
"targetAppLogin": login,
"breakType": "present_in_target_only",
"performedAt": datetime.utcnow(),
"reconReportMetadataId": reconReportMetadataId
}
collection.insert_one(record)
# Insert records for break_type_in_cymmetri_only
# for login in break_type_in_cymmetri_only:
# record = {
# "reconciliationId": "65f16ea71eea4028c1fa4c32",
# "AppName": "Active Directory",
# "appId": "653f482a0d2e4b5f289727ff",
# "CymmetriAppLogin": login,
# "breakType": "break_type_in_cymmetri_only",
# "performedAt": datetime.utcnow(),
# "reconReportMetadataId": "65f416c178b1347f40aabbbd"
# }
# collection.insert_one(record)
# Insert records for break_type_overdue
for login in break_type_overdue:
record = {
"reconciliationId": reconciliationId,
"AppName": AppName,
"appId": appId,
"targetAppLogin": login,
"breakType": "app_overdue",
"performedAt": datetime.utcnow(),
"reconReportMetadataId": reconReportMetadataId
}
collection.insert_one(record)
# Call the function with the required inputs
find_break_types_and_insert(Target_logins, Cymmetri_Logins, Final_Overdue)