2022-11-29 23:53:14 +01:00
|
|
|
class implementation_notification_channel_email(interface_notification_channel):
|
|
|
|
|
|
2022-11-30 23:03:24 +01:00
|
|
|
'''
|
|
|
|
|
[implementation]
|
|
|
|
|
'''
|
|
|
|
|
def parameters_schema(self):
|
|
|
|
|
return {
|
|
|
|
|
"type": "object",
|
|
|
|
|
"additionalProperties": False,
|
|
|
|
|
"properties": {
|
|
|
|
|
"access": {
|
|
|
|
|
"type": "object",
|
|
|
|
|
"additionalProperties": False,
|
|
|
|
|
"properties": {
|
|
|
|
|
"host": {
|
|
|
|
|
"type": "string"
|
|
|
|
|
},
|
|
|
|
|
"port": {
|
|
|
|
|
"type": "integer"
|
|
|
|
|
},
|
|
|
|
|
"username": {
|
|
|
|
|
"type": "string"
|
|
|
|
|
},
|
|
|
|
|
"password": {
|
|
|
|
|
"type": "string"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"required": [
|
|
|
|
|
"host",
|
|
|
|
|
"port",
|
|
|
|
|
"username",
|
|
|
|
|
"password"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
"sender": {
|
|
|
|
|
"type": "string"
|
|
|
|
|
},
|
|
|
|
|
"receivers": {
|
|
|
|
|
"type": "array",
|
|
|
|
|
"items": {
|
|
|
|
|
"type": "string"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"tags": {
|
|
|
|
|
"description": "list of strings, which will be placed in the e-mail subject",
|
|
|
|
|
"type": "array",
|
|
|
|
|
"items": {
|
|
|
|
|
"type": "string"
|
|
|
|
|
},
|
|
|
|
|
"default": []
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"required": [
|
|
|
|
|
"access",
|
|
|
|
|
"sender",
|
|
|
|
|
"receivers"
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-11-30 10:26:27 +01:00
|
|
|
'''
|
|
|
|
|
[implementation]
|
|
|
|
|
'''
|
2023-04-28 17:30:51 +02:00
|
|
|
def normalize_order_node(self, node):
|
2022-11-30 10:26:27 +01:00
|
|
|
return dict_merge(
|
|
|
|
|
{
|
|
|
|
|
},
|
|
|
|
|
node
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2022-11-29 23:53:14 +01:00
|
|
|
'''
|
|
|
|
|
[implementation]
|
|
|
|
|
'''
|
2022-11-30 23:14:38 +01:00
|
|
|
def notify(self, parameters, name, data, state, info):
|
2023-01-19 14:03:30 +01:00
|
|
|
datetime = _datetime.datetime.utcnow()
|
2022-11-29 23:53:14 +01:00
|
|
|
smtp_connection = _smtplib.SMTP(
|
|
|
|
|
parameters["access"]["host"]
|
|
|
|
|
)
|
|
|
|
|
smtp_connection.login(
|
|
|
|
|
parameters["access"]["username"],
|
|
|
|
|
parameters["access"]["password"]
|
|
|
|
|
)
|
|
|
|
|
message = MIMEText(
|
2022-12-03 16:36:44 +01:00
|
|
|
_json.dumps(info, indent = "\t", ensure_ascii = False)
|
2022-11-29 23:53:14 +01:00
|
|
|
)
|
|
|
|
|
message["Subject"] = string_coin(
|
|
|
|
|
"{{tags}} {{title}}",
|
|
|
|
|
{
|
|
|
|
|
"tags": " ".join(
|
|
|
|
|
map(
|
|
|
|
|
lambda tag: ("[%s]" % tag.upper()),
|
|
|
|
|
(
|
|
|
|
|
parameters["tags"]
|
|
|
|
|
+
|
2022-12-03 16:36:44 +01:00
|
|
|
[condition_show(state["condition"])]
|
2022-11-29 23:53:14 +01:00
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
),
|
2023-04-01 11:33:29 +02:00
|
|
|
"title": data["name"],
|
2022-11-29 23:53:14 +01:00
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
message["From"] = parameters["sender"]
|
|
|
|
|
message["To"] = ",".join(parameters["receivers"])
|
2023-01-19 13:25:32 +01:00
|
|
|
message["Date"] = string_coin(
|
|
|
|
|
"{{day_of_week}}, {{day_of_month}} {{month}} {{year}} {{hour}}:{{minute}}:{{second}} {{time_offset}}",
|
|
|
|
|
{
|
|
|
|
|
"day_of_week": datetime.strftime("%a"),
|
|
|
|
|
"day_of_month": datetime.strftime("%d"),
|
|
|
|
|
"month": datetime.strftime("%b"),
|
|
|
|
|
"year": datetime.strftime("%Y"),
|
|
|
|
|
"hour": datetime.strftime("%H"),
|
|
|
|
|
"minute": datetime.strftime("%M"),
|
|
|
|
|
"second": datetime.strftime("%S"),
|
2023-01-19 14:03:30 +01:00
|
|
|
# "time_offset": datetime.strftime("%z"),
|
|
|
|
|
"time_offset": "+0000",
|
2023-01-19 13:25:32 +01:00
|
|
|
}
|
|
|
|
|
)
|
2022-11-29 23:53:14 +01:00
|
|
|
smtp_connection.sendmail(
|
|
|
|
|
parameters["sender"],
|
|
|
|
|
parameters["receivers"],
|
|
|
|
|
message.as_string()
|
|
|
|
|
)
|
|
|
|
|
smtp_connection.quit()
|
2022-11-30 23:14:38 +01:00
|
|
|
|