191 lines
7.5 KiB
Python
191 lines
7.5 KiB
Python
# 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 = '''
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<body>
|
|
|
|
<table style="margin: 0 auto;" border="0" width="100%" cellspacing="0" cellpadding="0" bgcolor="#fff">
|
|
<tbody>
|
|
<tr>
|
|
<td align="center" bgcolor="#ffffff" width="600" height="100%">
|
|
<table border="0" cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr>
|
|
<td style="height: 69px;" bgcolor="#104277" width="600" height="69">
|
|
<table border="0" cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr>
|
|
<td style="height: 69px;" align="center" valign="middle" width="600"
|
|
height="69"><img style="display: block;"
|
|
src="https://img.mysy-training.com/MYSY-LOGO-WHITE.png"
|
|
alt="Mysy Training Logo" width="18%"></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="height: 30px;" bgcolor="#F9F9FF" width="600"> </td>
|
|
</tr>
|
|
<tr>
|
|
<td style="height: 30px;" bgcolor="#F9F9FF" width="600">
|
|
<p style="font-size: 14px; font-weight: 600; margin-top: 1rem; color: #232558; line-height: 1.4rem; text-align: center; font-family: Verdana, Geneva, Tahoma, sans-serif ;">
|
|
MySy Training, Notification Technique </p>
|
|
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="height: 30px;" bgcolor="#F9F9FF" width="600"> </td>
|
|
</tr>
|
|
<tr>
|
|
<td style="height: 165px;" bgcolor="#fff" width="600" height="165">
|
|
<table border="0" cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
|
|
|
|
<tr>
|
|
<td style="border: 0px transparent solid; border-radius: 3px; background: #e74c3c; padding-top: 2rem; color: #f9f9ff;"
|
|
role="presentation" align="center" valign="middle" bgcolor="#e74c3c" width="600">
|
|
|
|
<div style="height: 4rem;"><strong><span
|
|
style="font-family: DM Sans, Helvetica,sans-serif; "> Siteweb
|
|
mysy-training.com : KO</span></strong></div>
|
|
</td>
|
|
</tr>
|
|
|
|
|
|
|
|
|
|
<tr>
|
|
<td>
|
|
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="height: 30px;" bgcolor="#F9F9FF" width="600"> </td>
|
|
</tr>
|
|
<tr>
|
|
<td bgcolor="#104277" width="600">
|
|
<table border="0" cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr>
|
|
<td align="center" valign="middle" width="600">
|
|
<div style="padding: 10px 20px; margin-bottom: 1rem; color: #f9f9ff; font-size: 12px; line-height: 1.2rem;">
|
|
Téléphone : +331 01 77 00 38 57 <br/>
|
|
Mobile: +33 07 69 20 39 45 <br/>
|
|
Email :
|
|
contact@mysy-training.com <br>Site : https://www.mysy-training.com <br>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
</body>
|
|
</html>'''
|
|
|
|
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/
|
|
""" |