Welcome to email_notification’s documentation!

Simple package to send email, if log file has error or if healthcheck endpoint is down.

Details:

email_notification

email_notification.main

email_notification.main.checkhealth_send_email(server_logfile, email_logfile, healthcheck_url, config)[source]

Check the health and send the log file as error message if server is down

Args:
server_logfile:str
path of file where log of server is stored
email_logfile:str
path of file where log of this email is stored
healthcheck_url:str
url for health checkhealth
config:dict

dict of config file

{
    "TO":"example@gmail.com",
    "FROM":"example@gmail.com",
    "SMTP_SERVER":"smtp.gmail.com", # for gmail
    "PORT":"587",
    "PASSWORD": "password"

}
Return:
send email if server is down and email is not already send
email_notification.main.healthcheck(url)[source]

check the health of server

Args:
url:str
url of healthcheck endpoint
Return:
if live True else False
email_notification.main.send_email(error_msd, filename, config)[source]

send email with error message from log file

Args:
error_msg:list
Error message, each sentence as list
filename:str
filename of log file
config:dict

dict of config file

{
    "TO":"example@gmail.com",
    "FROM":"example@gmail.com",
    "SMTP_SERVER":"smtp.gmail.com", # for gmail
    "PORT":"587",
    "PASSWORD": "password"

}
Return:
True if success else log error message
Raise:
socket.error if error while sending message.
email_notification.main.tail(filename, n)[source]

Get last n lines from file as string

Args:
filename:str
filename of log file
n:int
number of lines
Return:
lines form file as string

email_notification.utils

email_notification.utils.utils module

email_notification.utils.utils.logger(logger_name='email_notification.utils.utils', filename='log.log', level=10)[source]

logger for logging

Args:
logger_name:str
name of logger
filename:str
path and file name
level:str
logging level
Return:
logger funcation for logging:logger
email_notification.utils.utils.read_config(filename)[source]

Parse config yaml file

Args:
filename:str
path of config file
email_notification.utils.utils.walk_directory(dir_path, files_only=True)[source]

Get list of all file in directory recursive

Args:
dir_path:str
parent directory to start
files_only:bool
get list of files only other
Return:
If file only than list of all files otherwise files and list of directories

Indices and tables