Python script to alert in case of site down
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
gregandev 959f917cb3 Supprimer 'env.py' 2 years ago
__pycache__ push date checker pour pas spam 2 years ago
README.md push 2 years ago
destinataires.csv push 2 years ago
logs-sender.py push 2 years ago
python-alert.py push date checker pour pas spam 2 years ago
requirements.txt push 2 years ago
url.csv push date checker pour pas spam 2 years ago

README.md

PYTHON ALERT FOR DOWNED SITES

PRE-REQUIS

  • Python3
  • time, requests, csv
python3 -m pip install -r requirements

INSTALLATION

sudo mkdir /workspace
sudo chown "$(whoami)":"$(whoami)" /workspace && cd /workspace
git clone https://gitlab.com/GregLebreton/python-alert-stack.git
cd python-alert-stack
mkdir logs

CONFIGURATION

WITH CRON (A)

  • Tâche CRON éxécutant les script toutes les 5 minutes:
crontab -e
*/5 * * * * /usr/bin/python3 /workspace/python-alert-stack/python-alert.py >> /workspace/python-alert-stack/logs/python-alert.log

WITH PYTHON TIME FUNCTION (B)

sudo nano /etc/systemd/system/python-alert-downsite.service
[Unit]
Description=Python Alert For Down Sites
[Service]
# Note: setting PYTHONUNBUFFERED is necessary to see the output of this service in the jo>
# See https://docs.python.org/2/using/cmdline.html#envvar-PYTHONUNBUFFERED
Environment=PYTHONUNBUFFERED=true

ExecStart=/usr/bin/python3 /workspace/python-alert-stack/python-alert.py

Type=oneshot
#WatchdogSec=30
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target

Note: Modifier la fin du python-alert.py script comme ceci:

# MAIN (A)
#urls = import_url()
#send_mail(urls)

# PYTHON TIME (B)
while True:
    urls = import_url()
    send_mail(urls)
# temps d'attente entre chaque éxécutions du check (en secondes)
    time.sleep(300)

LOGS SENDER

  • Tâche CRON éxécutant le script une fois par semaine (Lundi à 10h00):
crontab -e
00 10 * * mon /usr/bin/python3 /workspace/python-alert-stack/logs-sender.py