# This is a sample Python script.
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import requests
"""
O365_SMTP_COUNT_password = 'Sod78!526+'
O365_SMTP_COUNT_smtpsrv = "smtp.office365.com"
O365_SMTP_COUNT_user = "communication@mysytraining.fr"
O365_SMTP_COUNT_From_User = "communication@mysytraining.fr"
O365_SMTP_COUNT_port = 587
"""
O365_SMTP_COUNT_password = 'cherif'
O365_SMTP_COUNT_smtpsrv = "srvdmz.iexercice.com"
O365_SMTP_COUNT_user = "clientmail-vm2@iexercice.com"
O365_SMTP_COUNT_From_User = "clientmail-vm2@iexercice.com"
O365_SMTP_COUNT_port = 587
# Press Maj+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
"""
Cette fonction monitore un siteweb.
si Ko, alors il envoie un email
à cherif.
c'est une version degradée
"""
def check_if_site_is_up(diction):
try:
print(" Infonction : diction = ", diction)
URL = "https://www.mysy-training.com/"
site_status = False
try:
response = requests.head(URL)
except Exception as e:
print(f"WEB SITE NOT OK: {str(e)}")
site_status = False
else:
if response.status_code == 200:
print("WEBSITE IS OK")
site_status = True
else:
print(f"NOT OK: HTTP response code {response.status_code}")
site_status = False
"""
if (site_status is True):
return site_status, " Site OKKK"
else:
" "" Envoyer un email "" "
"""
html = '''
|
|
MySy Training, Notification Technique
|
|
Siteweb
mysy-training.com : KO
|
|
|
|
Téléphone : +331 01 77 00 38 57
Mobile: +33 07 69 20 39 45
Email :
contact@mysy-training.com Site : https://www.mysy-training.com
|
|
|
'''
html_mime = MIMEText(html, 'html')
msg = MIMEMultipart("alternative")
smtpserver = smtplib.SMTP(diction['smtpsrv'], diction['port'])
msg.attach(html_mime)
msg['From'] = diction['from']
msg['Bcc'] = 'contact@mysy-training.com'
msg['Subject'] = " IMPORTANT : Votre site mysy-training.com est KO"
msg['To'] = "cherif.balde@yahoo.fr, cbalde@mysy-training.com"
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.login( diction['user'], diction['password'])
val = smtpserver.send_message(msg)
smtpserver.close()
print(" Email envoyé " + str(val))
return site_status, " Site KOOO"
except Exception as e:
return False, " Impossible de controler l'etat du site"
"""
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
check_if_site_is_up()
print_hi('PyCharm')
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
"""