-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
369 additions
and
122 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
from cloud_governance.common.clouds.aws.s3.s3_operations import S3Operations | ||
from cloud_governance.common.elasticsearch.elasticsearch_operations import ElasticSearchOperations | ||
from cloud_governance.common.ldap.ldap_search import LdapSearch | ||
from cloud_governance.common.logger.init_logger import logger | ||
|
||
# https://github.com/redhat-performance/quads/blob/master/quads/tools/postman.py | ||
|
@@ -28,6 +29,8 @@ class Postfix: | |
|
||
def __init__(self): | ||
self.__environment_variables_dict = environment_variables.environment_variables_dict | ||
self.__LDAP_HOST_NAME = self.__environment_variables_dict.get('LDAP_HOST_NAME') | ||
self.__ldap_search = LdapSearch(ldap_host_name=self.__LDAP_HOST_NAME) | ||
self.reply_to = self.__environment_variables_dict.get('REPLY_TO', '[email protected]') | ||
self.__es_host = self.__environment_variables_dict.get('es_host', '') | ||
self.__policy = self.__environment_variables_dict.get('policy', '') | ||
|
@@ -36,7 +39,7 @@ def __init__(self): | |
self.__policy_output = self.__environment_variables_dict.get('policy_output', '') | ||
self.__default_admins = self.__environment_variables_dict.get('DEFAULT_ADMINS') | ||
self.__email_alert = self.__environment_variables_dict.get('EMAIL_ALERT') | ||
self.__mail_to = self.__environment_variables_dict.get('EMAIL_TO') # testing purposes | ||
self.__mail_to = self.__environment_variables_dict.get('EMAIL_TO') | ||
self.__mail_cc = self.__environment_variables_dict.get('EMAIL_CC') | ||
self.bucket_name, self.key = self.get_bucket_name() | ||
self.__es_index = 'cloud-governance-mail-messages' | ||
|
@@ -62,6 +65,8 @@ def send_email_postfix(self, subject: str, to: any, cc: list, content: str, **kw | |
to = self.__mail_to | ||
if self.__mail_cc: | ||
cc = self.__mail_cc | ||
if not self.__ldap_search.get_user_details(user_name=to): | ||
cc.append('[email protected]') | ||
cc = [cc_user for cc_user in cc if to and to not in cc_user] | ||
cc = [cc_user if '@redhat.com' in cc_user else f'{cc_user}@redhat.com' for cc_user in cc] | ||
msg = MIMEMultipart('alternative') | ||
|
@@ -115,7 +120,7 @@ def send_email_postfix(self, subject: str, to: any, cc: list, content: str, **kw | |
if kwargs.get('extra_purse'): | ||
data['extra_purse'] = round(kwargs['extra_purse'], 3) | ||
if self.__es_host: | ||
self.__es_operations.upload_to_elasticsearch(data=data, index=self.__es_index) | ||
# self.__es_operations.upload_to_elasticsearch(data=data, index=self.__es_index) | ||
logger.warn(f'Uploaded to es index: {self.__es_index}') | ||
else: | ||
logger.warn('Error missing the es_host') | ||
|
84 changes: 84 additions & 0 deletions
84
cloud_governance/common/mails/templates/policy_alert_agg_message.j2
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<html> | ||
<head> | ||
<style> | ||
header{ | ||
margin-bottom: 10px; | ||
} | ||
footer{ | ||
margin-top: 10px; | ||
color: gray; | ||
} | ||
.table-hover { | ||
font-family: Verdana, Helvetica, sans-serif; | ||
border-collapse: collapse; | ||
width: 100%; | ||
} | ||
.table-hover td, .table-hover th { | ||
border: 2px solid #000; | ||
padding: 8px; | ||
align-items: baseline; | ||
color: black; | ||
} | ||
.table-hover th { | ||
padding-top: 12px; | ||
padding-bottom: 12px; | ||
text-align: left; | ||
background-color: #04AA6D; | ||
color: white; | ||
} | ||
.bgcolor-red{ | ||
color: red; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<header> | ||
Hi {{ User }}, | ||
</header> | ||
<section> | ||
<div style="margin-bottom: 10px"> | ||
<p>You can find below your unused resources in the {{ cloud_name }} account ({{ account }}).</p> | ||
<p>If you want to keep them, please add "Policy=Not_Delete" or "Policy=skip" tag for each resource</p> | ||
</div> | ||
<table class="table-hover"> | ||
<thead> | ||
<tr> | ||
{% for col in columns %} | ||
<th>{{ col | title }}</th> | ||
{% endfor %} | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for record in records %} | ||
<tr> | ||
{% for col in columns %} | ||
{% if col == 'Action' %} | ||
{% if record['ResourceDelete'] == "True" or record['ResourceStopped'] == "True" %} | ||
<td class="bgcolor-red">{{ "Deleted" }}</td> | ||
{% else %} | ||
<td>{{ "Alert" }}</td> | ||
{% endif %} | ||
{% else %} | ||
{% if col == 'PublicCloud' %} | ||
<td>{{ record[col] or 'AWS' }}</td> | ||
{% elif col == 'RegionName' %} | ||
<td>{{ record[col] or record['region_name'] }}</td> | ||
{% elif 'kubernetes.io/cluster' in record[col] %} | ||
<td>{{ record[col].split('/')[-1] }}</td> | ||
{% else %} | ||
<td>{{ record[col] or 'NA' }}</td> | ||
{% endif %} | ||
{% endif %} | ||
{% endfor %} | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</section> | ||
<footer> | ||
Thanks, <br />Cloud GovernanceTeam | ||
</footer> | ||
</body> | ||
</html> |
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
Oops, something went wrong.