Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get trail status #32960

Merged
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1bb2877
"contribution update to pack "AWS - CloudTrail""
xsoar-bot Feb 8, 2024
87f7653
made requested changes
kcelovic Feb 15, 2024
2e10684
Update Packs/AWS-CloudTrail/ReleaseNotes/1_1_0.md
kcelovic Feb 19, 2024
bbd8550
Update Packs/AWS-CloudTrail/Integrations/AWS-CloudTrail/AWS-CloudTrai…
kcelovic Feb 19, 2024
1a1e551
Update Packs/AWS-CloudTrail/Integrations/AWS-CloudTrail/AWS-CloudTrai…
kcelovic Feb 19, 2024
e03fc32
Update Packs/AWS-CloudTrail/Integrations/AWS-CloudTrail/AWS-CloudTrai…
kcelovic Feb 19, 2024
27d22ff
removed try & except under get_trail_status function
kcelovic Feb 21, 2024
a6aa6a7
fixed indent
kcelovic Feb 21, 2024
eb55e69
fixed typo
kcelovic Feb 21, 2024
8d145af
fixed typo
kcelovic Feb 21, 2024
ceec7bf
made requested changes
kcelovic Feb 26, 2024
2b14ee9
updated docker version
kcelovic Feb 26, 2024
84839a8
updated docker
kcelovic Feb 26, 2024
431c3a7
fixed typos
kcelovic Feb 26, 2024
285c5ba
reverted change on package-lock.json
kcelovic Feb 28, 2024
5e6f999
reverted changes as requested
kcelovic Feb 28, 2024
f5ca883
Merge branch 'contrib/kcelovic_get-trail-status' into get-trail-status
kcelovic Feb 28, 2024
2120a52
Merge branch 'contrib/kcelovic_get-trail-status' into get-trail-status
kcelovic Feb 29, 2024
5ea4094
Merge branch 'demisto:master' into get-trail-status
kcelovic Feb 29, 2024
78e71bf
revert package-lock.json
kcelovic Feb 29, 2024
07481b1
update dockerimage
kcelovic Feb 29, 2024
08dca0a
Update 1_1_0.md
kcelovic Feb 29, 2024
ae7a7d2
Merge branch 'contrib/kcelovic_get-trail-status' into get-trail-status
kcelovic Mar 1, 2024
6ef6192
Update AWS-CloudTrail.py
kcelovic Mar 5, 2024
fa91979
Update AWS-CloudTrail.yml
kcelovic Mar 5, 2024
b7bacfb
Update 1_1_0.md
kcelovic Mar 5, 2024
f0a0b2a
Update AWS-CloudTrail.py
kcelovic Mar 5, 2024
4ecf498
Update AWS-CloudTrail.py
kcelovic Mar 5, 2024
b7ccaba
Update AWS-CloudTrail.py
kcelovic Mar 5, 2024
e0b21ce
Merge branch 'contrib/kcelovic_get-trail-status' into get-trail-status
kcelovic Mar 5, 2024
3421af0
Merge branch 'contrib/kcelovic_get-trail-status' into get-trail-status
kcelovic Mar 5, 2024
94ef568
Update AWS-CloudTrail.py
kcelovic Mar 6, 2024
1458f8f
Update Packs/AWS-CloudTrail/Integrations/AWS-CloudTrail/AWS-CloudTrai…
kcelovic Mar 7, 2024
1b47287
Merge branch 'contrib/kcelovic_get-trail-status' into get-trail-status
kcelovic Mar 7, 2024
69abe45
Merge branch 'contrib/kcelovic_get-trail-status' into get-trail-status
kcelovic Mar 8, 2024
44919a4
Update AWS-CloudTrail_test.py
kcelovic Mar 8, 2024
ff04ccf
Update 1_1_0.md
kcelovic Mar 8, 2024
dbd2b1c
Update AWS-CloudTrail.yml
kcelovic Mar 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 45 additions & 6 deletions Packs/AWS-CloudTrail/Integrations/AWS-CloudTrail/AWS-CloudTrail.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import demistomock as demisto
from CommonServerPython import *
from CommonServerUserPython import *
import demistomock as demisto # noqa: F401
from CommonServerPython import * # noqa: F401


import boto3
from botocore.config import Config
from botocore.parsers import ResponseParserError
Expand Down Expand Up @@ -102,10 +103,10 @@ def aws_session(service='cloudtrail', region=None, roleArn=None, roleSessionName
return client


def handle_returning_date_to_string(date_obj: datetime | str) -> str:
def handle_returning_date_to_string(date_obj: datetime | str | None) -> str:
"""Gets date object to string"""
kcelovic marked this conversation as resolved.
Show resolved Hide resolved
# if the returning date is a string leave it as is.
if isinstance(date_obj, str):
# if the returning date is a string or None, leave it as is.
if date_obj is None or isinstance(date_obj, str):
return date_obj
Copy link
Contributor

Choose a reason for hiding this comment

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

Something is odd about this logic, if date_obj is None and we return it then the function should support None return (in that case let's also make sure it doesn't break any b/c).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What changes do you recommend here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would remove the None option from the argument anotation.


# if event time is datetime object - convert it to string.
Expand Down Expand Up @@ -238,6 +239,40 @@ def describe_trails(args: dict) -> CommandResults:
)


def get_trail_status(args: dict) -> CommandResults:
client = aws_session(
region=args.get('region'),
roleArn=args.get('roleArn'),
roleSessionName=args.get('roleSessionName'),
roleSessionDuration=args.get('roleSessionDuration'),
)

kwargs = {'Name': args.get('name')}

response = client.get_trail_status(**kwargs)

data = {
'IsLogging': response.get('IsLogging'),
'LatestDeliveryTime': handle_returning_date_to_string(response.get('LatestDeliveryTime')),
'LatestCloudWatchLogsDeliveryError': response.get('LatestCloudWatchLogsDeliveryError'),
'LatestDeliveryErrorDetails': response.get('LatestDeliveryErrorDetails'),
'LatestNotificationError': response.get('LatestNotificationError'),
'LatestNotificationTime': handle_returning_date_to_string(response.get('LatestNotificationTime')),
'StartLoggingTime': handle_returning_date_to_string(response.get('StartLoggingTime')),
'StopLoggingTime': handle_returning_date_to_string(response.get('StopLoggingTime')),
'LatestCloudWatchLogsDeliveryTime': handle_returning_date_to_string(response.get('LatestCloudWatchLogsDeliveryTime')),
'LatestDigestDeliveryTime': handle_returning_date_to_string(response.get('LatestDigestDeliveryTime')),
'LatestDigestDeliveryError': response.get('LatestDigestDeliveryError')
}

return CommandResults(
outputs_prefix="AWS.CloudTrail.TrailStatus",
outputs_key_field="Name",
outputs=data,
readable_output=tableToMarkdown('AWS CloudTrail TrailStatus', data),
)


def update_trail(args: dict) -> CommandResults:
client = aws_session(
region=args.get('region'),
Expand Down Expand Up @@ -409,6 +444,8 @@ def main():
return_results(stop_logging(args))
if command == 'aws-cloudtrail-lookup-events':
return_results(lookup_events(args))
if command == 'aws-cloudtrail-get-trail-status':
return_results(get_trail_status(args))

except Exception as e:
err = "Error has occurred in the AWS CloudTrail Integration."
Expand All @@ -419,3 +456,5 @@ def main():

if __name__ in ["__builtin__", "builtins", "__main__"]:
main()

register_module_line('AWS - CloudTrail', 'end', __line__())
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,60 @@ script:
- contextPath: AWS.CloudTrail.Events.CloudTrailEvent
description: A JSON string that contains a representation of the event returned.
type: string
dockerimage: demisto/boto3py3:1.0.0.88114
- arguments:
- description: Specifies the names of multiple trails.
name: trailNameList
- description: Specifies the region of the trail.
name: region
required: true
- description: The The Amazon Resource Name (ARN) of the role to assume.
name: roleArn
- description: An identifier for the assumed role session.
name: roleSessionName
- description: The duration, in seconds, of the role session. The value can range from 900 seconds (15 minutes) up to the maximum session duration setting for the role.
name: roleSessionDuration
- description: Specifies the name of the trail.
name: name
required: true
description: Returns a JSON-formatted list of information about the specified trail. Fields include information on delivery errors, Amazon SNS and Amazon S3 errors, and start and stop logging times for each trail.
name: aws-cloudtrail-get-trail-status
outputs:
- contextPath: AWS.CloudTrail.TrailStatus.IsLogging
description: Whether the CloudTrail trail is currently logging Amazon Web Services API calls.
type: boolean
- contextPath: AWS.CloudTrail.TrailStatus.LatestDeliveryError
description: Displays any Amazon S3 error that CloudTrail encountered when attempting to deliver log files to the designated bucket.
type: string
- contextPath: AWS.CloudTrail.TrailStatus.LatestNotificationError
description: Displays any Amazon SNS error that CloudTrail encountered when attempting to send a notification.
type: string
- contextPath: AWS.CloudTrail.TrailStatus.LatestDeliveryTime
description: Specifies the date and time that CloudTrail last delivered log files to an account’s Amazon S3 bucket.
type: date
- contextPath: AWS.CloudTrail.TrailStatus.LatestNotificationTime
description: Specifies the date and time of the most recent Amazon SNS notification that CloudTrail has written a new log file to an account’s Amazon S3 bucket.
type: date
- contextPath: AWS.CloudTrail.TrailStatus.StartLoggingTime
description: Specifies the most recent date and time when CloudTrail started recording API calls for an Amazon Web Services account.
type: date
- contextPath: AWS.CloudTrail.TrailStatus.StopLoggingTime
description: Specifies the most recent date and time when CloudTrail stopped recording API calls for an Amazon Web Services account.
type: date
- contextPath: AWS.CloudTrail.TrailStatus.LatestCloudWatchLogsDeliveryError
description: Displays any CloudWatch Logs error that CloudTrail encountered when attempting to deliver logs to CloudWatch Logs.
type: string
- contextPath: AWS.CloudTrail.TrailStatus.LatestCloudWatchLogsDeliveryTime
description: Displays the most recent date and time when CloudTrail delivered logs to CloudWatch Logs.
type: date
- contextPath: AWS.CloudTrail.TrailStatus.LatestDigestDeliveryTime
description: Specifies the date and time that CloudTrail last delivered a digest file to an account’s Amazon S3 bucket.
type: date
- contextPath: AWS.CloudTrail.TrailStatus.LatestDigestDeliveryError
description: Displays any Amazon S3 error that CloudTrail encountered when attempting to deliver a digest file to the designated bucket.
type: string
dockerimage: demisto/boto3py3:1.0.0.89465
runonce: false
script: '-'
script: ''
subtype: python3
type: python
tests:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ on your AWS environment.
- Attach a Role to the Instance Profile.
- Configure the Necessary IAM Roles that the AWS Integration Can Assume.

For detailed instructions, see the [AWS Integrations - Authentication](https://xsoar.pan.dev/docs/reference/articles/aws-integrations---authentication).
For detailed instructions, see the [AWS Integrations - Authentication](https://xsoar.pan.dev/docs/reference/articles/aws-integrations---authentication).
Loading
Loading