Skip to content

Commit

Permalink
[New Feature] send logs with email
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaelVallenet committed Jul 30, 2021
1 parent ed5636d commit 6baad4a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,4 @@ dmypy.json

Datasets/output_http_csic_2010_weka_with_duplications_RAW-RFC2616_escd_v02_full.csv
Execution/Dataset_test.csv
.github
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

5 changes: 5 additions & 0 deletions src/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"fromAddr": "sender",
"passwordAddr": "password of sender",
"toAddr": "receiver"
}
42 changes: 41 additions & 1 deletion src/software/logsManager.py
Original file line number Diff line number Diff line change
@@ -1 +1,41 @@
import json
import json
from datetime import datetime
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders

def logsManager(self):
def __init__(self, path: str) -> None:
self.__path = path
with open(self.__path, "r").read() as config:
config = json.load(config)
self.__from_addr = config['fromAddr']
self.__password_addr = config['passwordAddr']
self.__to_addr = config['toAddr']

def send_mail(self, msg: str) -> None:
now = datetime.now()
current_time = now.strftime("%d-%m-%Y %Hh%Mm%Ss%f")[:-3]
subject = "Sharkticon anomaly detected"
body = "Date : " + current_time + "ms\nLog : " + msg + "\n\nUne anomalie nécessite une " \
"verification\n"
msg = MIMEMultipart()
msg['From'] = self.__from_addr
msg['To'] = self.__to_addr
msg['Subject'] = subject
msg.attach(MIMEText(body, 'plain'))
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
try:
s.login(self.__from_addr, self.__password_addr)
except:
print("Error : your mail config isn't valid")
return
text = msg.as_string()
s.sendmail(self.__from_addr, self.__to_addr, text)
s.quit()



0 comments on commit 6baad4a

Please sign in to comment.