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

Add TicketId to the Email #754

Merged
merged 4 commits into from
Apr 17, 2024
Merged
Changes from 2 commits
Commits
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
18 changes: 11 additions & 7 deletions cloudsensei/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,18 @@ def get_resources(self):
break
if tag_key == 'user':
user = tag.get('Value')
if tag_key == 'ticketid':
ticket_tags = tag.get('Value')
elif tag_key == 'name':
name = tag.get('Value')
if not skip and user:
long_running_instances_by_user.setdefault(user.lower(), {}).setdefault(region_name, []).append(
{'InstanceId': resource.get('InstanceId'),
'Name': name, 'LaunchDate': str(launch_time),
'RunningDays': f"{days} days", 'State': resource.get('State', {}).get('Name'),
'InstanceType': resource.get('InstanceType')})
instance_details = {'InstanceId': resource.get('InstanceId'),
'Name': name, 'LaunchDate': str(launch_time),
'RunningDays': f"{days} days", 'State': resource.get('State', {}).get('Name'),
'InstanceType': resource.get('InstanceType')}
if ticket_tags: # Add TicketId tags if available
instance_details['TicketId'] = ticket_tags
long_running_instances_by_user.setdefault(user.lower(), {}).setdefault(region_name, []).append(instance_details)
Copy link
Collaborator

Choose a reason for hiding this comment

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

move one tab to this one as well. All should be under the if not skip and user: block

return long_running_instances_by_user

def get_account_alias_name(self):
Expand All @@ -98,7 +102,7 @@ def organize_message_to_send_slack(self, resources_list: dict):
"""

divider = {"type": "divider"}
keys_list = ['User', 'Region', 'Name', 'InstanceType', 'InstanceId', 'LaunchDate', 'RunningDays']
keys_list = ['User', 'Region', 'Name', 'InstanceType', 'InstanceId', 'LaunchDate', 'RunningDays', 'TicketId']
rows = []
for user, region_list in resources_list.items():
for region_name, resources_list in region_list.items():
Expand All @@ -122,7 +126,7 @@ def organize_message_to_seng_mail(self, resources_list: dict):
:param resources_list:
:return:
"""
keys_list = ['User', 'Region', 'Name', 'InstanceType', 'InstanceId', 'LaunchDate', 'State', 'RunningDays']
keys_list = ['User', 'Region', 'Name', 'InstanceType', 'InstanceId', 'LaunchDate', 'State', 'RunningDays', 'TicketId']
with open('email_template.j2') as template:
template = Template(template.read())
body = template.render({'resources_list': resources_list, 'keys_list': keys_list})
Expand Down
Loading