|
28 | 28 | logAnalyticsUri = 'https://' + customer_id + '.ods.opinsights.azure.com' |
29 | 29 |
|
30 | 30 | key_vault_name = os.environ.get("KeyVaultName","Commvault-Integration-KV") |
31 | | -uri = None |
32 | 31 | url = None |
33 | 32 | qsdk_token = None |
34 | 33 | headers = { |
@@ -110,13 +109,15 @@ def main(mytimer: func.TimerRequest) -> None: |
110 | 109 | credential = DefaultAzureCredential() |
111 | 110 | client = SecretClient(vault_url=f"https://{key_vault_name}.vault.azure.net", credential=credential) |
112 | 111 | secret_name = "environment-endpoint-url" |
113 | | - uri = client.get_secret(secret_name).value |
114 | | - url = "https://" + uri + "/commandcenter/api" |
| 112 | + url = client.get_secret(secret_name).value |
| 113 | + logging.error(f"URL : {url}") |
115 | 114 | secret_name = "access-token" |
116 | 115 | qsdk_token = client.get_secret(secret_name).value |
117 | 116 | headers["authtoken"] = "QSDK " + qsdk_token |
118 | 117 |
|
119 | 118 | companyId_url = f"{url}/v2/WhoAmI" |
| 119 | + |
| 120 | + logging.error(f"Trying to fetch company details {companyId_url}") |
120 | 121 | company_response = requests.get(companyId_url, headers=headers) |
121 | 122 | if company_response.status_code == 200: |
122 | 123 | company_data_json = company_response.json() |
@@ -169,18 +170,20 @@ def main(mytimer: func.TimerRequest) -> None: |
169 | 170 | post_data = [] |
170 | 171 | if data: |
171 | 172 | for event in data: |
172 | | - temp = get_incident_details(event["description"]) |
173 | | - if temp: |
174 | | - post_data.append(temp) |
| 173 | + try : |
| 174 | + temp = get_incident_details(event["description"]) |
| 175 | + if temp: |
| 176 | + post_data.append(temp) |
| 177 | + except Exception as e: |
| 178 | + logging.error("Error while processing event : "+str(e)) |
175 | 179 | logging.info("Trying Post Data") |
176 | 180 | gen_chunks(post_data) |
177 | 181 | logging.info("Job Succeeded") |
178 | 182 | print("***Job Succeeded*****") |
179 | | - upload_timestamp_blob(cs, container_name, blob_name, to_time+1) |
180 | 183 | logging.info("Function App Executed") |
181 | 184 | else: |
182 | 185 | print("No new events found.") |
183 | | - |
| 186 | + upload_timestamp_blob(cs, container_name, blob_name, to_time+1) |
184 | 187 | else: |
185 | 188 | logging.error("Failed to get events with status code : "+str(response.status_code)) |
186 | 189 | except Exception as e: |
@@ -411,8 +414,8 @@ def get_user_details(client_name): |
411 | 414 |
|
412 | 415 | f_url = f"{url}/Client/byName(clientName='{client_name}')" |
413 | 416 | response = requests.get(f_url, headers=headers).json() |
414 | | - user_id = response.get('clientProperties', [{}])[0].get('clientProps', {}).get('securityAssociations', {}).get('associations', [{}])[0].get('userOrGroup', [{}])[0].get('userId') |
415 | | - user_name = response.get('clientProperties', [{}])[0].get('clientProps', {}).get('securityAssociations', {}).get('associations', [{}])[0].get('userOrGroup', [{}])[0].get('userName') |
| 417 | + user_id = response['clientProperties'][0]['clientProps']['securityAssociations']['associations'][0]['userOrGroup'][0]['userId'] |
| 418 | + user_name = response['clientProperties'][0]['clientProps']['securityAssociations']['associations'][0]['userOrGroup'][0]['userName'] |
416 | 419 | return user_id, user_name |
417 | 420 |
|
418 | 421 |
|
@@ -529,7 +532,7 @@ def get_incident_details(message: str) -> dict | None: |
529 | 532 | "description": description, |
530 | 533 | } |
531 | 534 | return details |
532 | | - except: |
| 535 | + except Exception as e: |
533 | 536 | logging.error(f"An error occurred") |
534 | 537 | return None |
535 | 538 |
|
@@ -592,7 +595,7 @@ def post_data(body, chunk_count): |
592 | 595 | logging.info(f"Data :- {body}") |
593 | 596 | response = requests.post(uri, data=body, headers=headers) |
594 | 597 | if (response.status_code >= 200 and response.status_code <= 299): |
595 | | - logging.info("Chunk was processed{} events".format(chunk_count)) |
| 598 | + logging.info("Chunk was processed {} events with status : {}".format(chunk_count, response.content)) |
596 | 599 | else: |
597 | 600 | logging.error("Error during sending events to Microsoft Sentinel. Response code:{}".format(response.status_code)) |
598 | 601 |
|
|
0 commit comments