# PYTHON ALERT FOR DOWNED SITES ## PRE-REQUIS - Python3 - time, requests, csv ```bash python3 -m pip install -r requirements ``` ## INSTALLATION ```bash 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: ```bash 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) ```bash 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: ```bash # 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): ```bash crontab -e 00 10 * * mon /usr/bin/python3 /workspace/python-alert-stack/logs-sender.py ```