-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
355 lines (264 loc) · 26.3 KB
/
test.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
# # from bson import ObjectId
import datetime
# # current_utc_time = datetime.datetime.utcnow()
# # application_id = "653f482a0d2e4b5f289727ff"
# # # logins = ['sahilp', 'sahil123', '74681']
# # # app_overdue = []
# # # l1 = [{'_id': ObjectId('6507e57052cf0e453e97303c'), 'displayName': 'sahil prabhune', 'firstName': 'sahil', 'lastName': 'prabhune', 'country': 'India', 'mobile': '', 'email': '[email protected]', 'userType': 'Employee', 'orgUnitId': '', 'department': '', 'designation': 'Data Scientist', 'status': 'DELETE', 'created': datetime.datetime(2023, 9, 18, 5, 51, 44, 662000), 'updated': datetime.datetime(2023, 12, 12, 18, 45, 10, 977000), 'created_by': 'shreyasp', 'updated_by': 'sahilp', 'assignedGroups': [], 'provisionedApps': {'CYMMETRI': {'appId': 'CYMMETRI', 'assignedRoles': ['USER'], 'login': {'login': 'sahilp', 'password': 'PbDToGcVwR0f9NlaNzgL71ugbzr1ssLtZ1YdL4/fH8nuG5ncLM0tGLHx5UKjNZhYeDd4Xwzl5pqu5od6/knayLex+FZIdUURqZw8UxOkL/I=', 'status': 'ACTIVE', 'pwdChangeCount': 0, 'authFailCount': 0, 'isForceChangePassword': False, 'neverExpiryPassword': False, 'isInitialLogin': False, 'createdTimeStamp': datetime.datetime(2023, 9, 18, 5, 51, 44, 656000), 'modifiedTimeStamp': datetime.datetime(2023, 9, 18, 5, 52, 24, 846000), 'lastLoginTime': datetime.datetime(2023, 11, 9, 6, 45, 54, 350000), 'lastPasswordChange': datetime.datetime(2023, 9, 18, 5, 52, 24, 846000), 'passwordExpiredAfter': datetime.datetime(2023, 12, 17, 5, 52, 24, 846000), 'passwordExpiryNotification': datetime.datetime(2023, 12, 7, 5, 52, 24, 734000)}}, '653f482a0d2e4b5f289727ff': {'appId': '653f482a0d2e4b5f289727ff', 'assignedRoles': [], 'login': {'status': 'DELETE_SSO', 'pwdChangeCount': 0, 'authFailCount': 0, 'isForceChangePassword': False, 'neverExpiryPassword': False, 'isInitialLogin': False, 'createdTimeStamp': datetime.datetime(2023, 11, 8, 10, 11, 19, 738000), 'formInstanceId': '', 'login': 'sahilp'}}}, 'attributes': [], 'version': 254, 'secondaryStatus': 'FINISHED', '_class': 'com.cymmetri.user.entity.User'}, {'_id': ObjectId('65e5a63beb282a4bc9bb0f0e'), 'displayName': 'Sahil Prabhu Prabhu', 'firstName': 'Sahil Prabhu', 'lastName': 'Prabhu', 'userType': 'Employee', 'orgUnitId': '', 'department': '', 'designation': '', 'status': 'ACTIVE', 'created': datetime.datetime(2024, 3, 4, 10, 45, 15, 510000), 'updated': datetime.datetime(2024, 3, 4, 10, 45, 15, 796000), 'created_by': 'prabhunesahil', 'updated_by': 'prabhunesahil', 'assignedGroups': [], 'provisionedApps': {'653f482a0d2e4b5f289727ff': {'appId': '653f482a0d2e4b5f289727ff', 'assignedRoles': [], 'login': {'login': 'sahil123', 'password': '', 'appUserId': 'sahil123', 'status': 'SUCCESS_CREATE', 'pwdChangeCount': 0, 'authFailCount': 0, 'isForceChangePassword': True, 'neverExpiryPassword': False, 'isInitialLogin': False, 'createdTimeStamp': datetime.datetime(2024, 3, 4, 10, 45, 15, 22000), 'modifiedTimeStamp': datetime.datetime(2024, 3, 4, 10, 45, 15, 22000), 'groupLink': 'CN=Sahil Prabhu,OU=SahilPrabhOU,DC=cymmetri,DC=in'}}, 'CYMMETRI': {'appId': 'CYMMETRI', 'assignedRoles': ['USER'], 'login': {'login': 'sahil123', 'password': 'tyMsMWSWgpPr49HLEkxGHIS93qSSzNvdoU7SuRi4zX0sMmjUoI7xmMWicb5edvBRU3xt29vdPwqs41irKUiWQY4dXMLDqbqr4RXtzK7CcEc=', 'pwdChangeCount': 0, 'authFailCount': 0, 'isForceChangePassword': True, 'neverExpiryPassword': False, 'isInitialLogin': True, 'createdTimeStamp': datetime.datetime(2024, 3, 4, 10, 45, 15, 498000), 'passwordExpiredAfter': datetime.datetime(2024, 6, 2, 10, 45, 15, 498000), 'passwordExpiryNotification': datetime.datetime(2024, 5, 23, 10, 45, 15, 498000)}}}, 'attributes': [], 'metaAttributes': {'createdBy': '653f482a0d2e4b5f289727ff', 'createdByRefType': 'APPLICATION', 'created': datetime.datetime(2024, 3, 4, 10, 45, 15, 796000)}, 'version': 1, '_class': 'com.cymmetri.user.entity.User', 'end_date': datetime.datetime(2023, 3, 4, 10, 45, 15, 510000)}, {'_id': ObjectId('65e5ce1e6d41db844e6916a0'), 'displayName': 'Ram Sreepada', 'firstName': 'Ram', 'lastName': 'Sreepada', 'country': 'India', 'email': '[email protected]', 'userType': 'Employee', 'orgUnitId': '', 'employeeId': '22839', 'department': 'Sales', 'designation': '', 'status': 'ACTIVE', 'start_date': {'$date': '2017-08-16T00:00:00.000Z'}, 'created': {'$date': '2023-12-23T11:55:06.061Z'}, 'updated': {'$date': '2023-12-26T07:19:27.968Z'}, 'created_by': 'admin', 'updated_by': 'admin', 'assignedGroups': [], 'provisionedApps': {'CYMMETRI': {'appId': 'CYMMETRI', 'assignedRoles': ['USER'], 'login': {'login': '74681', 'password': 'txMJSE1R0dq8+OktLgLMYwdTNyepfzxck86TmrNCi9z/P7UbPSyhBF20tKFrJPE2bSM6dK5W+mTulBPsnYFpcCWj9MoPKBuKTjdQjzZ/7cU=', 'pwdChangeCount': 0, 'authFailCount': 0, 'isForceChangePassword': True, 'neverExpiryPassword': False, 'isInitialLogin': True, 'createdTimeStamp': {'$date': '2023-12-23T11:55:06.054Z'}, 'passwordExpiredAfter': {'$date': '2024-03-22T11:55:06.054Z'}, 'passwordExpiryNotification': {'$date': '2024-03-12T11:55:06.054Z'}}}, '653f482a0d2e4b5f289727ff': {'appId': '653f482a0d2e4b5f289727ff', 'assignedRoles': [], 'login': {'login': '74681', 'password': '', 'appUserId': '74681', 'status': 'SUCCESS_CREATE', 'pwdChangeCount': 0, 'authFailCount': 0, 'isForceChangePassword': True, 'neverExpiryPassword': False, 'isInitialLogin': False, 'createdTimeStamp': {'$date': '2023-12-23T11:55:05.479Z'}, 'modifiedTimeStamp': {'$date': '2023-12-23T11:55:05.479Z'}, 'groupLink': '74681'}}}, 'attributes': [{'name': 'Employee type', 'value': 'Employee', 'converterType': 'STRING'}, {'name': 'Office Address', 'value': '3-1-273 Hanamkonda Kakatiya colony, 506001', 'converterType': 'STRING'}, {'name': 'Middle name', 'value': 'Mohan', 'converterType': 'STRING'}, {'name': 'Reporting manager id', 'value': '22456', 'converterType': 'STRING'}], 'metaAttributes': {'createdBy': '658574b7efe7224ee74ba6f2', 'updatedBy': '658574b7efe7224ee74ba6f2', 'createdByRefType': 'APPLICATION', 'updatedByRefType': 'APPLICATION', 'created': {'$date': '2023-12-23T11:55:06.280Z'}, 'updated': {'$date': '2023-12-26T07:19:27.968Z'}}, 'version': {'$numberLong': '7'}, '_class': 'com.cymmetri.user.entity.User', 'end_date': datetime.datetime(2024, 1, 22, 11, 55, 6, 61000)}]
# # # for user in l1:
# # # # Check if user["provisionedApps"] is a dictionary
# # # if isinstance(user["provisionedApps"], dict):
# # # # Check if applicationId exists in provisionedApps
# # # if applicationId in user["provisionedApps"]:
# # # # Check the conditions for the user
# # # if "end_date" in user and user["end_date"] < current_utc_time and \
# # # user["status"] == "ACTIVE" and \
# # # user["provisionedApps"][applicationId]["login"]["status"] not in ["SUCCESS_DELETE", "SUCCESS_UPDATE"]:
# # # app_overdue.append(user)
# # # # Printing the result
# # # # #print("Users matching the conditions:")
# # # # for user in app_overdue:
# # # # #print(user)
# # # #print(len(app_overdue))
# # app_overdue = [{'_id': ObjectId('65e5a63beb282a4bc9bb0f0e'), 'displayName': 'Sahil Prabhu Prabhu', 'firstName': 'Sahil Prabhu', 'lastName': 'Prabhu', 'userType': 'Employee', 'orgUnitId': '', 'department': '', 'designation': '', 'status': 'ACTIVE', 'created': datetime.datetime(2024, 3, 4, 10, 45, 15, 510000), 'updated': datetime.datetime(2024, 3, 4, 10, 45, 15, 796000), 'created_by': 'prabhunesahil', 'updated_by': 'prabhunesahil', 'assignedGroups': [], 'provisionedApps': {'653f482a0d2e4b5f289727ff': {'appId': '653f482a0d2e4b5f289727ff', 'assignedRoles': [], 'login': {'login': 'sahil123', 'password': '', 'appUserId': 'sahil123', 'status': 'SUCCESS_CREATE', 'pwdChangeCount': 0, 'authFailCount': 0, 'isForceChangePassword': True, 'neverExpiryPassword': False, 'isInitialLogin': False, 'createdTimeStamp': datetime.datetime(2024, 3, 4, 10, 45, 15, 22000), 'modifiedTimeStamp': datetime.datetime(2024, 3, 4, 10, 45, 15, 22000), 'groupLink': 'CN=Sahil Prabhu,OU=SahilPrabhOU,DC=cymmetri,DC=in'}}, 'CYMMETRI': {'appId': 'CYMMETRI', 'assignedRoles': ['USER'], 'login': {'login': 'sahil123', 'password': 'tyMsMWSWgpPr49HLEkxGHIS93qSSzNvdoU7SuRi4zX0sMmjUoI7xmMWicb5edvBRU3xt29vdPwqs41irKUiWQY4dXMLDqbqr4RXtzK7CcEc=', 'pwdChangeCount': 0, 'authFailCount': 0, 'isForceChangePassword': True, 'neverExpiryPassword': False, 'isInitialLogin': True, 'createdTimeStamp': datetime.datetime(2024, 3, 4, 10, 45, 15, 498000), 'passwordExpiredAfter': datetime.datetime(2024, 6, 2, 10, 45, 15, 498000), 'passwordExpiryNotification': datetime.datetime(2024, 5, 23, 10, 45, 15, 498000)}}}, 'attributes': [], 'metaAttributes': {'createdBy': '653f482a0d2e4b5f289727ff', 'createdByRefType': 'APPLICATION', 'created': datetime.datetime(2024, 3, 4, 10, 45, 15, 796000)}, 'version': 1, '_class': 'com.cymmetri.user.entity.User', 'end_date': datetime.datetime(2023, 3, 4, 10, 45, 15, 510000)}, {'_id': ObjectId('65e5ce1e6d41db844e6916a0'), 'displayName': 'Ram Sreepada', 'firstName': 'Ram', 'lastName': 'Sreepada', 'country': 'India', 'email': '[email protected]', 'userType': 'Employee', 'orgUnitId': '', 'employeeId': '22839', 'department': 'Sales', 'designation': '', 'status': 'ACTIVE', 'start_date': {'$date': '2017-08-16T00:00:00.000Z'}, 'created': {'$date': '2023-12-23T11:55:06.061Z'}, 'updated': {'$date': '2023-12-26T07:19:27.968Z'}, 'created_by': 'admin', 'updated_by': 'admin', 'assignedGroups': [], 'provisionedApps': {'CYMMETRI': {'appId': 'CYMMETRI', 'assignedRoles': ['USER'], 'login': {'login': '74681', 'password': 'txMJSE1R0dq8+OktLgLMYwdTNyepfzxck86TmrNCi9z/P7UbPSyhBF20tKFrJPE2bSM6dK5W+mTulBPsnYFpcCWj9MoPKBuKTjdQjzZ/7cU=', 'pwdChangeCount': 0, 'authFailCount': 0, 'isForceChangePassword': True, 'neverExpiryPassword': False, 'isInitialLogin': True, 'createdTimeStamp': {'$date': '2023-12-23T11:55:06.054Z'}, 'passwordExpiredAfter': {'$date': '2024-03-22T11:55:06.054Z'}, 'passwordExpiryNotification': {'$date': '2024-03-12T11:55:06.054Z'}}}, '653f482a0d2e4b5f289727ff': {'appId': '653f482a0d2e4b5f289727ff', 'assignedRoles': [], 'login': {'login': '74681', 'password': '', 'appUserId': '74681', 'status': 'SUCCESS_CREATE', 'pwdChangeCount': 0, 'authFailCount': 0, 'isForceChangePassword': True, 'neverExpiryPassword': False, 'isInitialLogin': False, 'createdTimeStamp': {'$date': '2023-12-23T11:55:05.479Z'}, 'modifiedTimeStamp': {'$date': '2023-12-23T11:55:05.479Z'}, 'groupLink': '74681'}}}, 'attributes': [{'name': 'Employee type', 'value': 'Employee', 'converterType': 'STRING'}, {'name': 'Office Address', 'value': '3-1-273 Hanamkonda Kakatiya colony, 506001', 'converterType': 'STRING'}, {'name': 'Middle name', 'value': 'Mohan', 'converterType': 'STRING'}, {'name': 'Reporting manager id', 'value': '22456', 'converterType': 'STRING'}], 'metaAttributes': {'createdBy': '658574b7efe7224ee74ba6f2', 'updatedBy': '658574b7efe7224ee74ba6f2', 'createdByRefType': 'APPLICATION', 'updatedByRefType': 'APPLICATION', 'created': {'$date': '2023-12-23T11:55:06.280Z'}, 'updated': {'$date': '2023-12-26T07:19:27.968Z'}}, 'version': {'$numberLong': '7'}, '_class': 'com.cymmetri.user.entity.User', 'end_date': datetime.datetime(2024, 1, 22, 11, 55, 6, 61000)}]
# # final_app_overdue = []
# # for user in app_overdue:
# # # Extracting desired attributes from each user
# # user_data = {
# # "cymmetriLogin": user["provisionedApps"]["CYMMETRI"]["login"]["login"],
# # "appLogin": user["provisionedApps"][application_id]["login"]["login"],
# # "status": user["status"],
# # "appStatus": user["provisionedApps"][application_id]["login"]["status"],
# # "end_date": user.get("end_date", None)
# # }
# # final_app_overdue.append(user_data)
# # # Printing the final list
# # #print("final_app_overdue:", final_app_overdue)
# from pymongo import MongoClient
# from datetime import datetime
# import redis
# import json
# # Key for Redis hash
# redis_key = 'cymmetri-datascience_sh_recon_65f16ea71eea4028c1fa4c32_f595e9a3-77dd-476a-a424-3336552e3bac'
# # 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
# hash_data = redis_client.hgetall(redis_key)
# # Extract required fields
# cymmetri_logins = json.loads(hash_data.get("Cymmetri_logins", "[]"))
# final_app_overdue = json.loads(hash_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_app_overdue)
# # def find_break_types(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)
# # return break_type_in_target_only, break_type_in_cymmetri_only, break_type_overdue
# # # Call the function with the required inputs
# # break_type_in_target_only, break_type_in_cymmetri_only, break_type_overdue = find_break_types(Target_logins, Cymmetri_Logins, Final_Overdue)
# # # Print the results
# # #print("break_type_in_target_only:", break_type_in_target_only)
# # #print("break_type_in_cymmetri_only:", break_type_in_cymmetri_only)
# # #print("break_type_overdue:", break_type_overdue)
# Target_logins = {'Padma.Begum', '18099', 'niyra', '18105', '32802', '17036', '34386', '17038', '34407', '17972', '33917', 'Cymmetri', 'LTB150012', '34329', '33336', 'Arjun.Patil', 'devbramhma', '16506', 'Parminder.Kaur', 'test.pod', 'rohit', "Sankar.D'Cruze", '34544', '32927', '16386', 'Reshmi.Narang', '33018', 'Amandeep.Chaudhri', 'guru.test', '18156', '33371', 'narin', '16587', '33474', '34543', 'dhirav1', '33378', '33453', 'Reshma.Begum', '32965', 'Rameshwar.Patil', 'Hardeep.Choudhary', '33521', 'Jyothi.Ahmad', '17113', '32887', '34315', '34009', '34007', '33450', '16905', '33962', 'Ninad.Ahmed', '16617', 'ramakrishna', '34471', 'akruti.akruti', '34451', 'Harshada.Rao', '32839', '16515', '34322', 'LTB150002', 'LTB150011', '33340', 'ankush018', '33528', "Amitabh.D'Cruz", '34365', 'Dhaval.Nibhanupudi', '34348', '99999', '34401', '34465', '33526', '34325', '34547', '16577', '32896', '34519', 'ani1', '17980', '33844', '33800', '34501', 'raka', '33360', '33302', 'aa123', 'Nila.Chaudhri', 'converter11', 'Sandeep.Patil', 'Gurdeep.Nagarkar', '33532', 'ron', '33427', '33818', 'Harpreet.Nibhanupudi', '32899', '33520', '34433', '34469', 'Meena.Rao', 'Harish.Anand', '34439', 'Sameera.Tirrell', 'Jayanti12345', '34397', 'Padmini.Chaudhary', '33529', '34464', '32894', '34402', '33860', 'LTB150009', 'Talia.Adamson', '18145', '33339', '34483', 'devbramhmadevbramhma', 'ishal887', '34510', '32778', '16395', '33386', '34453', '34012', '33533', '32824', '34317', '16897', '34511', 'Vipul.Kaur', 'Minali.Gadhavi', '34456', 'Jyothi.Rao', 'Jaidev.Chaudhari', '33451', 'Anushka.Das', '32919', '33328', '34363', '34549', 'Lakshmi.Joshi', '34505', '66666', 'Don', 'chimur.chokra', 'Jennica.Ross', '33343', '33913', 'duke', 'dfsdfsdf', '34448', '34321', '33379', 'Tejas6253', 'Dip.Ahmed', '32883', '32893', '16971', '32840', '32938', 'Ratnam.Jain', '33801', 'Nilam.Korrapati', 'Saral.Singh', '34333', '33500', 'Natasha', '33975', '32889', 'usercristfure', '34029', 'Samira.Narang', 'Amandeep.Jain', '33341', '34496', 'LTB150050', '34313', 'Nitin.Mishra', '34523', '33901', '17037', '33364', 'Rajeshk23', 'Pawan736', '33362', 'Deepika.Kulkarni', '33330', '32843', 'Mohinder.Patel', '34398', 'Sanjana.Misra', '18068', '33383', '16970', '34356', 'Kasi.Gupta', '34534', '34556', 'Padma.Jain', 'rant44', '34466', '33398', 'converter12', 'Dipali.Tamboli', 'Mohandas.Joshi', 'Gurpreet.Tamboli', 'vrush1', 'Sri.Singh', '33506', '33531', 'LTB150010', '33281', 'Nikhil.Ahmed', 'ganesh33', '34450', '33998', '33489', '16430', '34498', 'Suman.Vemulakonda', '18001', 'Rina.Ahmad', '34472', '33996', '18162', 'kumar1', '33462', '33470', '16949', '33321', 'Indra.Narang', "Siva.D'Cruze", '34507', '18135', 'Radha.Mishra', 'Ramkrishna.Devi', 'Amarjeet.Vemulakonda', 'QuintondeKock', 'Kamini.Kaur', 'Girish735', '34316', 'Durga.Chaudhari', 'Suman.Singh', 'Khushi.Bachchan', 'Vasuda.Gupta', '17041', 'Kenton.Pitt', 'Ajit.Shrivatsa', '33488', '16903', '16618', 'Laksh', '34446', '34013', 'LTB150004', '32831', '34380', '34334', '18016', 'Puneet.Mishra', 'tansan656', 'Mina.Bachchan', '32805', '17004', '32932', 'Nanda.Kumar', '18153', 'Kanta.Jain', '32872', '16535', 'Priyanka.Mishra', 'eurodoller', '34394', '18175', 'Vihaan.Narang', '32845', 'yash12', 'Gopal.Kaur', '33983', '34535', '16455', "Govinda.D'Cruz", '17927', '33960', '33517', '34499', 'Tushar.Anand', 'Prathmesh11', '33876', 'Amrita.Rao', 'HarshadaRao', 'LTB150013', '32986'}
# Cymmetri_logins = ['sahilp', 'sahil123', '74681']
# 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 = '65f8430941fd647553ffbcea'
# 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_2c7347f6-9c9a-441b-b478-37b1bb936cac'
# 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)
# target_logins_json = json.dumps(target_logins_list, ensure_ascii=False)
# # Store serialized JSON in Redis
# redis_client.set(redis_key, target_logins_json)
# for login in target_logins_list:
# existing_document = shRecordCymmetriAppLogins.find_one({"Target_logins": login})
# if existing_document:
# # Check if reconciliation_ids is an array, if not, convert it to a set
# 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"))
# # Add the new reconciliationId if it's not already present
# if reconciliationId not in reconciliation_ids:
# reconciliation_ids.add(reconciliationId)
# # Update the existing document
# # Convert the set to a comma-separated string
# reconciliation_ids_str = ','.join(reconciliation_ids)
# shRecordCymmetriAppLogins.update_one({"_id": existing_document["_id"]}, {"$set": {"reconciliation_ids": reconciliation_ids_str}})
# else:
# # Insert a new document
# data_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()
# }
# shRecordCymmetriAppLogins.insert_one(data_to_insert)
# from fastapi import FastAPI
# from pymongo import MongoClient
# from fastapi.responses import JSONResponse
# # 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'] # Replace 'your_database_name' with your actual database name
# # Get the collection instances
# shReconBreakRecords = db['shReconBreakRecords']
# syncDataForRecon = db['syncDataForRecon']
# app = FastAPI()
# @app.get("/get_data")
# async def get_data():
# result = []
# # Find records in shReconBreakRecords where breakType is "present_in_target_only"
# sh_recon_break_records_cursor = shReconBreakRecords.find({"breakType": "present_in_target_only"})
# # Iterate through each record
# for record in sh_recon_break_records_cursor:
# # Get reconciliationId from shReconBreakRecords
# reconciliation_id = record.get("reconciliationId")
# # Get targetAppLogin from shReconBreakRecords
# target_app_login = record.get("targetAppLogin")
# # Find records in syncDataForRecon where reconciliationId matches and data.login matches targetAppLogin
# sync_data_cursor = syncDataForRecon.find({"reconciliationId": reconciliation_id, "data.login": target_app_login})
# # Iterate through matching records in syncDataForRecon
# for sync_record in sync_data_cursor:
# # Fetch required attributes from syncDataForRecon
# login = sync_record.get("data", {}).get("login")
# display_name = sync_record.get("displayName")
# first_name = sync_record.get("data", {}).get("firstName")
# last_name = sync_record.get("data", {}).get("lastName")
# email = sync_record.get("data", {}).get("email")
# created_date_time = sync_record.get("createdDateTime")
# # Construct a dictionary with the fetched attributes
# user_data = {
# "Login": login,
# "Display Name": display_name,
# "First Name": first_name,
# "Last Name": last_name,
# "Email": email,
# "Created Date": created_date_time
# }
# result.append(user_data)
# return JSONResponse(content=result)
# if __name__ == "__main__":
# import uvicorn
# uvicorn.run(app, host="127.0.0.1", port=8000)
from bson import ObjectId
from pymongo import MongoClient
import datetime
import redis
import json
from config.loader import Configuration
import platform
import time
import json
import pymongo
import redis
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["user"]
logins = []
# for document in collection.find({}, {"provisionedApps.CYMMETRI.login.login": 1, "_id": 0}):
# login_info = document.get("provisionedApps", {}).get("CYMMETRI", {}).get("login", {}).get("login")
# if login_info:
# logins.append(login_info)
for document in collection.find({}, {"provisionedApps.653f482a0d2e4b5f289727ff.login.login": 1, "_id": 0}):
login_info = document.get("provisionedApps", {}).get("CYMMETRI", {}).get("login", {}).get("login")
if login_info:
logins.append(login_info)
# Print logins
#print(logins)