Skip to content

New Command - Tenant Audit Log Report. Closes #1739#2001

Closed
arjunumenon wants to merge 5 commits intopnp:masterfrom
arjunumenon:1739-new-tenantauditlog
Closed

New Command - Tenant Audit Log Report. Closes #1739#2001
arjunumenon wants to merge 5 commits intopnp:masterfrom
arjunumenon:1739-new-tenantauditlog

Conversation

@arjunumenon
Copy link
Copy Markdown
Member

@arjunumenon arjunumenon commented Dec 11, 2020

New Command - 'tenant auditlog report'. Closes #1739

Linked Issue

Closes #1739

Copy link
Copy Markdown
Member Author

@arjunumenon arjunumenon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @waldekmastykarz / @rabwill -
Currently I am kind of in a deadlock situation and my thoughts are clouded in a finding an approach for a case.

  • I am trying to get a result by using Promises.all for generating the audit log.

  • Since we cannot execute everything in a single Promises.all (We will have around 200 REST API call), we may have to batch that and have execute Promises.all for each batches pf 10.

  • It will be great if you can have a quick look and let me know how can I take it forward.

  • Had been struggling with that for couple of days and it seems my thoughts have become clouded 💭unfortunately.

It will be super helpful if you can have a quick look and let me know the direction on that please. 🤞

Comment thread src/m365/tenant/commands/auditlog/auditlog-report.ts Outdated
Comment thread src/m365/tenant/commands/auditlog/auditlog-report.ts Outdated
@arjunumenon arjunumenon force-pushed the 1739-new-tenantauditlog branch 20 times, most recently from d8bed05 to b810ded Compare December 17, 2020 10:40
@arjunumenon arjunumenon marked this pull request as ready for review December 17, 2020 10:43
@arjunumenon
Copy link
Copy Markdown
Member Author

Hey @waldekmastykarz / @rabwill - I have initiated the PR finally. Since the implementation is complicated, I am expecting it to have large number of review comments. Have tried my best to follow the guidelines.

Thanks for all the guidance so far. Looking forward for the comments 🤞.

@waldekmastykarz
Copy link
Copy Markdown
Member

I appreciate your effort! We'll review it shortly 👍

@plamber plamber self-assigned this Dec 21, 2020
Copy link
Copy Markdown
Contributor

@plamber plamber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @arjunumenon,
thank you very much for your valuable work. I tested the command and have some minor suggestions on how to improve the current PR.

Let me know if you have any questions.

Wish you a great 2021.

Comment on lines +251 to +285
if (StartEndDateDifference != 1 || StartdateTodayDifference > 7) {
return `startTime and endTime must be less than or equal to 24 hours apart, with the start time prior to end time and start time no more than 7 days in the past`;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand the API correctly we want to allow persons to search within a day. With this limitation we can't do it.

I cannot perform for example such a search: 2020-12-29T15:00:00 and 2020-12-29T16:00:00.

I think this part should be changed to ((StartEndDateDifference > 0 && StartEndDateDifference <= 1) || StartdateTodayDifference > 7)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is totally correct @plamber . So silly mistake from my end.. My Bad... 🤦. Thanks for the find.

I had not even thought about the time details, since I was focusing only on dates and their difference. I will modify the code and will push it again..

Comment on lines +226 to +254
if ((args.options.startTime && !(args.options.endTime)) || (!(args.options.startTime) && args.options.endTime)) {
return `startTime and endTime must both be specified (or both omitted)`;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we simplify this? If we omit the endtime and provide a starttime, just add 24h to the endtime.

This might be useful if we search back 5 days for example. I do not see any reason of specifying the enddate if I just want to see what happened 5 days ago

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a brilliant suggestion. I was being a robot developer and was blindly following the specs without thinking from the user's shoes. Your suggestion is amazing and definitely increases the usability for the users sticking on to the recommended specs.

Another question If I may @plamber , how about a case where the user enters, endTime alone? just thinking out wild here. Do you think we can generate startTime automatically which is 24 hours before the entered endTime? Or do you think it is not quite needed and don't see that situation coming into picture?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this use case. I am seeing it more with the startTime variable.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @plamber for the suggestion. Will stick on with your approach in that case. We can always update it in future if similar use case comes up.

Another question, do you think we need to update the specs since it is mentioned that Start time and end time must both be specified (or both omitted) for startTime and endTime parameters.

Sorry for bombarding with questions..

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please update the specs too

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @plamber for the confirmation. Guess I do not have permission to update the specs from my end.
image

Do you think you will be able to update it from your end? Thanks for all the guidance.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arjunumenon: just send me the exact wording and I will update the specs

Copy link
Copy Markdown
Member Author

@arjunumenon arjunumenon Jan 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arjunumenon: just send me the exact wording and I will update the specs

Hello @plamber - Below is command specs which I thought could be given. Please free to update the specs if needed from your end if that makes more sense. I would be totally fine with that. 🙂

Option Description
-c, --contentType Audit content type of logs to be retrieved, should be one of the following: AzureActiveDirectory, Exchange, SharePoint, General, DLP.
-s, --startTime [startTime] Start time of logs to be retrieved. Start time and end time must be less than or equal to 24 hours apart. Start time is mandatory if End time is specified.
-e, --endTime [endTime] End time of logs to be retrieved. Start time and end time must be less than or equal to 24 hours apart. If End time is not specified, command will assume the End time to be 24 hours from the specified Start time.
-o, --output [output] Output type. json,text. Default text
--verbose Runs command with verbose logging
--debug Runs command with debug logging

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the spects

Comment on lines +65 to +66
telemetryProps.startTime = args.options.startTime;
telemetryProps.endTime = args.options.endTime;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The starttime and endtime value might not be interesting in our telemetry but if these parameters have been used. You can use this syntax to do it

telemetryProps.startTime= typeof args.options.startTime !== 'undefined';
telemetryProps.endTime= typeof args.options.endTime !== 'undefined';

On the other hand it would be interesting to see which type of audit is used. Therefore, I would add the option to collect the value for the contenttype

telemetryProps.contentType = args.options.contentType;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Secret between you and me. (That is a copy-paste mistake. Promise me you won't tell to anyone.✋)

Will definitely add the contentType filter to the telemetry since it will benefit us. Thanks for pointing that out.

Comment on lines +40 to +45
```sh
m365 tenant auditlog report --contentType "Exchange" --startTime "2020-12-13" --endTime "2020-12-14"
```
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to add some examples on how to search within a day (between specific hours)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I will add the examples to show the usage of the command for a certain time period, especially time period within a day.

Comment on lines +16 to +20
`-s, --startTime [startTime]`
: Start time of logs to be retrieved. Start time and end time must both be specified (or both omitted) and must be less than or equal to 24 hours apart.

`-e, --endTime [endTime]`
: End time of logs to be retrieved. Start time and end time must both be specified (or both omitted) and must be less than or equal to 24 hours apart.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check my comments regarding the endTime omission if you specify a starttime

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I am thinking is to give our explanation accordingly. Something around these lines -

If you haven't entered the endTime, command will automatically consider the endTime as 24 hours after the startTime and will generate the report accordingly.

As per this question, can I give the explanation for the case where they have not entered startTime as well.?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

@waldekmastykarz waldekmastykarz marked this pull request as draft January 10, 2021 11:11
@arjunumenon
Copy link
Copy Markdown
Member Author

Thanks a lot for the comments. I will have a look into that and will start modifying it..

Totally appreciate your patience in the review since there were quite a large number of changes 🙏..

@waldekmastykarz
Copy link
Copy Markdown
Member

Likewise: appreciate your effort to get it in 👏

@arjunumenon arjunumenon force-pushed the 1739-new-tenantauditlog branch 3 times, most recently from 5018b6b to e99ff55 Compare January 12, 2021 16:04
@arjunumenon
Copy link
Copy Markdown
Member Author

Hello @waldekmastykarz - I have updated the code which will handle the review comments. Along with the changes, I had also identified a flaw in the logic which was - endTime was auto calculated even if the user enters a valid endTime. I have given the fix for the same. Line # 151 - Line # 158.

Sorry that I had missed in the initial implementation.

@arjunumenon arjunumenon marked this pull request as ready for review January 12, 2021 16:13
@waldekmastykarz
Copy link
Copy Markdown
Member

Awesome! Thank you for such a quick turnaround 👏

Comment thread src/m365/tenant/commands/auditlog/auditlog-report.ts Outdated
}, err => { return Promise.reject(err) });
}

private getAuditLogReportforSingleContentURL(auditURL: string): Promise<AuditlogReport[]> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be still unchanged

Copy link
Copy Markdown
Member

@waldekmastykarz waldekmastykarz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done! We're almost done. Would you mind having one last look at the unresolved comments?

@waldekmastykarz waldekmastykarz marked this pull request as draft January 13, 2021 19:07
@arjunumenon arjunumenon force-pushed the 1739-new-tenantauditlog branch from e99ff55 to 7f4b142 Compare January 18, 2021 07:38
@coveralls
Copy link
Copy Markdown

coveralls commented Jan 18, 2021

Coverage Status

Coverage remained the same at 100.0% when pulling 18c5824 on arjunumenon:1739-new-tenantauditlog into ed5be30 on pnp:master.

@arjunumenon arjunumenon force-pushed the 1739-new-tenantauditlog branch from 9b36ce2 to 4f5bc3d Compare January 19, 2021 03:30
@arjunumenon arjunumenon force-pushed the 1739-new-tenantauditlog branch from 4f5bc3d to 18c5824 Compare January 19, 2021 03:35
@arjunumenon
Copy link
Copy Markdown
Member Author

Nicely done! We're almost done. Would you mind having one last look at the unresolved comments?

Hello @waldekmastykarz - I have made the changes based on your recommendation. Can you have a quick look into that and let me know if anything else needs to be changed from my end.

Thanks a lot for the patiently reviewing all the changes ❤. I am sorry that I had missed some of the points which you had told in the initial review process which made you spend time twice.

PS : I have not changed the status to Ready for Review yet. I have not made the commits clean yet. Once we are good with the code, I will clean the commit history and will make the status as Ready for Review. Kindly let me know if you don't agree with this approach so that I will mark is as Ready for Review right away.

@waldekmastykarz
Copy link
Copy Markdown
Member

Appreciate your patience and sticking with us as well. I'll mark it as ready for review. Don't worry about the commits. As long as there are no merge conflicts, we can take care of them ❤️

@waldekmastykarz waldekmastykarz marked this pull request as ready for review January 19, 2021 18:41
@waldekmastykarz waldekmastykarz self-assigned this Jan 20, 2021
Copy link
Copy Markdown
Member

@waldekmastykarz waldekmastykarz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nicely done. I've done a few small alignment changes when merging the PR but other than that 👍

@waldekmastykarz
Copy link
Copy Markdown
Member

Merged manually. Thank you! 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New command: tenant auditlog report

4 participants