-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
106 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
a) Un fichier de configuration avec les HOSTS | ||
|
||
b) Un script qui génère le script SH avec HOSTS et TIMEOUT only (utiliser la syntaxe python simple avec %(var_name)s), | ||
monitoring du temps, wget status, archive anciens fichier pour étudier le changement de status | ||
wget http://www.asilax.fr --no-check-certificate --timeout=5 -S -q -O - 2>&1 | awk '/^ HTTP/{print $2}' | ||
http://www.sectorfej.net/2012/03/24/simple-web-server-availability-monitoring-with-cron-bash-and-wget/ | ||
|
||
TODO : sauvegarde ancien status si nécessaire | ||
écrire nouveau status avec "$HOST;$RESPONSE;$START;$END" | ||
|
||
c) Un script python qui étudie les fichiers de log : | ||
- vérifie le code de retour | ||
- détermine le status (cf lien bash) avec le SLOW_THRESHOLD | ||
- génère un rapport texte, un rapport HTML, envoi des mails | ||
|
||
d) Documentation du README | ||
|
||
e) Post du rapport dans un Plone, via une configuration dans le fichier de configuration | ||
|
||
f) Support i18n pour les rapports, via une entrée dans le fichier de configuration | ||
|
||
g) Tests ? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# List of websites to check | ||
WEBSITE_URIS = [ | ||
'http://www.yahoo.com', | ||
'https://www.google.com', | ||
'http://www.france.fr/nous-contacter' | ||
] | ||
|
||
# Requests timeout in second (used by wget calls) | ||
TIMEOUT = 10 | ||
|
||
# If response time, in seconds, is greater than SLOW_THRESHOLD, then the website status will be SLOW | ||
SLOW_THRESHOLD = 7 | ||
|
||
# Accepted HTTP status codes | ||
OK_STATUSES = ['200'] | ||
|
||
# Reports folder, where status files and reports will be added | ||
REPORTS_PATH = "/tmp/reports" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
src/supervision/website/utils/check_host_generate_script.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import sys | ||
from supervision.website.config import * | ||
|
||
def generate_sh_script(): | ||
# Generate the sh script using our custom configuration | ||
|
||
with open('check_hosts.sh.tmpl', 'r') as f: | ||
script = f.read() | ||
|
||
script = script.replace('TO_BE_REPLACE_TIMEOUT', str(TIMEOUT)) | ||
script = script.replace('TO_BE_REPLACE_HOSTS', '\n'.join((['"%s" \\' % uri for uri in WEBSITE_URIS]))) | ||
script = script.replace('TO_BE_REPLACE_REPORTS_PATH', REPORTS_PATH) | ||
|
||
with open('check_hosts.sh', 'w') as f: | ||
f.write(script) | ||
|
||
|
||
if __name__ == '__main__': | ||
generate_sh_script() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
# Thanks to http://www.sectorfej.net/2012/03/24/simple-web-server-availability-monitoring-with-cron-bash-and-wget/ | ||
|
||
HOSTS=( \ | ||
TO_BE_REPLACE_HOSTS | ||
) | ||
|
||
TIMEOUT=TO_BE_REPLACE_TIMEOUT | ||
|
||
REPORT_DIRECTORY="TO_BE_REPLACE_REPORTS_PATH" | ||
CURRENT_STATUS_FILE="$REPORT_DIRECTORY/sitemonitor.current.status" | ||
PREVIOUS_STATUS_FILE="$REPORT_DIRECTORY/sitemonitor.previous.status" | ||
|
||
# Create files structure if needed | ||
mkdir -p $REPORT_DIRECTORY | ||
if [ ! -e $CURRENT_STATUS_FILE ]; then | ||
touch $CURRENT_STATUS_FILE | ||
fi | ||
if [ ! -e $PREVIOUS_STATUS_FILE ]; then | ||
touch $PREVIOUS_STATUS_FILE | ||
fi | ||
|
||
# Backup current status file and remove his content | ||
mv -f $CURRENT_STATUS_FILE $PREVIOUS_STATUS_FILE | ||
touch $CURRENT_STATUS_FILE | ||
|
||
for HOST in "${HOSTS[@]}" | ||
do | ||
START=$(date +%s) | ||
RESPONSE=`wget $HOST --no-check-certificate --timeout=$TIMEOUT -S -q -O - 2>&1 | \ | ||
awk '/^ HTTP/{print \$2}'` | ||
END=$(date +%s) | ||
#DIFF=$(( $END - $START )) | ||
|
||
if [ -z "$RESPONSE" ]; then | ||
# Zero-length ("null") string variable | ||
RESPONSE="0" | ||
fi | ||
|
||
echo $HOST";"$RESPONSE";"$START";"$END >> $CURRENT_STATUS_FILE | ||
|
||
done |