Created
January 8, 2020 09:48
-
-
Save pmatthews05/07d8a4078ce579947d47d2efc895e40d to your computer and use it in GitHub Desktop.
Audit O365 Webhook handling the Audit Log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
log.LogInformation($"Audit Logs triggered the webhook"); | |
string content = await req.Content.ReadAsStringAsync(); | |
log.LogInformation($"Received following payload: {content}"); | |
List<AuditContentEntity> auditContents = JsonConvert.DeserializeObject<List<AuditContentEntity>>(content); | |
foreach (var auditcontent in auditContents) | |
{ | |
if (AuditContentUriQueue == null) | |
{ | |
string cloudStorageAccountConnectionString = System.Environment.GetEnvironmentVariable("AzureWebJobsStorage", EnvironmentVariableTarget.Process); | |
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(cloudStorageAccountConnectionString); | |
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); | |
AuditContentUriQueue = queueClient.GetQueueReference("auditcontenturi"); | |
await AuditContentUriQueue.CreateIfNotExistsAsync(); | |
} | |
log.LogInformation($"Content Queue Message: {auditcontent.ContentUri}"); | |
AuditContentQueue acq = new AuditContentQueue | |
{ | |
ContentType = auditcontent.ContentType, | |
ContentUri = auditcontent.ContentUri, | |
TenantID = auditcontent.TenantId | |
}; | |
string message = JsonConvert.SerializeObject(acq); | |
log.LogInformation($"Adding a message to the queue. Message content: {message}"); | |
await AuditContentUriQueue.AddMessageAsync(new CloudQueueMessage(message)); | |
log.LogInformation($"Message added") | |
} | |
return new HttpResponseMessage(HttpStatusCode.OK); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment