commit ebc48d0f688c934635694c7713d3fe59c638549f Author: Didier Clermonté Date: Fri Jan 31 16:28:51 2020 +0100 Initialisation (#4126) diff --git a/monitoring/check_datechaprilorg_update b/monitoring/check_datechaprilorg_update new file mode 100755 index 0000000..9bc0131 --- /dev/null +++ b/monitoring/check_datechaprilorg_update @@ -0,0 +1,33 @@ +#!/bin/bash +# +# Nagios plugin to check paste version +# +# Author : Didier Clermonté +# Author : Christian Momon +# Date : 7 Dec 2019 +# + + + +function usage() { + echo "Usage : $0" +} + +# +if [ "$#" -ne 0 ]; then + usage +else + lastVersion=$(curl -s https://framagit.org/api/v4/projects/16/releases | jshon -a -e name|cut -d '"' -f2|grep -v '[\^\(alpha\)]'|head -n 1) + currentVersion=$(cd /var/www/date.chapril.org && git branch | grep '*'|cut -c 11-100 ) + + #echo $currentVersion + #echo $lastVersion + if [ $currentVersion = $lastVersion ]; then + echo "OK" + result=0 + else + echo "WARNING : new version available, current is $currentVersion, last is $lastVersion." + result=1 + fi +fi +exit $result diff --git a/rapport_activite/datechaprilorg.cron b/rapport_activite/datechaprilorg.cron new file mode 100644 index 0000000..975b5d0 --- /dev/null +++ b/rapport_activite/datechaprilorg.cron @@ -0,0 +1 @@ +1 0 1 * * root /var/www/date.chapril.org/tools/rapport_activite.sh -p >> /srv/date.chapril.org/Exploitation/rapport_date.log 2>&1 diff --git a/rapport_activite/rapport_activite.sh b/rapport_activite/rapport_activite.sh new file mode 100755 index 0000000..2bbf4f8 --- /dev/null +++ b/rapport_activite/rapport_activite.sh @@ -0,0 +1,147 @@ +#!/bin/bash +# +# Copyright (C) 2018,2019 Didier Clermonté +# Copyright (C) 2018,2019 Christian Pierre Momon +# +# This file is part of date.chapril.org. +# +# This script is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# ============================================ +help() +{ + echo "Usage:" + echo " $(basename "$0") -h display help" + echo " $(basename "$0") analyse current month" + echo " $(basename "$0") -p analyse preceding month" + echo " $(basename "$0") month_number year analyse this month" +} + +generateReport() +{ + local monthEnglish="$1" + local month="$2" + local year="$3" + echo -e "=================================================================" + echo + creationCount=$(grep "CREATE_POLL" /var/www/date.chapril.org/admin/stdout.log | grep -c "$month") + echo "Nombre de sondages créés = $creationCount" + + mailCount=$(grep "CREATE_POLL" /var/www/date.chapril.org/admin/stdout.log | grep "$month"|cut -d',' -f5|sort|uniq|wc -l) + echo "Nombre d'adresses mail différentes = $mailCount" + + deletionCount=$(grep "DELETE_POLL" /var/www/date.chapril.org/admin/stdout.log | grep -c "$month") + echo "Nombre de sondages supprimés = $deletionCount" + + pollCount=$(echo "SELECT count(*) from fd_poll;"| mysql --silent -u root date_chapril_org_db) + echo "Nombre total de sondages dans la base = $pollCount" + + purgeCount=$(grep "EXPIRATION_SUCCESS" /var/www/date.chapril.org/admin/stdout.log | grep -c "$month") + echo "Nombre de sondages purgés = $purgeCount" + + pollExpiredCount=$(echo "SELECT count(*) from fd_poll where end_date > now();"| mysql --silent -u root date_chapril_org_db) + echo "Nombre de sondages expirés = $pollExpiredCount" + + httpRequestCount=$(zgrep "$monthEnglish" /var/log/apache2/date.chapril.org/date.chapril.org-access.log*|grep -c "$year") + echo "Nombre total de requêtes http = $httpRequestCount" + + trueHttpRequestCount=$(zgrep "$monthEnglish" /var/log/apache2/date.chapril.org/date.chapril.org-access.log*|grep "$year"|grep -vi bot|grep -c -v check_http) + echo "Nombre de vraies requêtes http = $trueHttpRequestCount" + + botRequestCount=$(zgrep "$monthEnglish" /var/log/apache2/date.chapril.org/date.chapril.org-access.log*|grep "$year"|grep -i bot|grep -c -v check_http) + echo "Nombre de requêtes bot = $botRequestCount" + + errorRequestCount=$(zgrep "$monthEnglish" /var/log/apache2/date.chapril.org/date.chapril.org-error.log*|grep -c "$year") + echo "Nombre de requêtes http en erreur = $errorRequestCount" + + databaseSize=$(mysql --silent -u root date_chapril_org_db -e "SELECT round(sum(data_length+index_length)/1024/1024,3) AS 'Size (MB)' FROM information_schema.tables WHERE table_schema='date_chapril_org_db';" ) + echo "Taille de la base de données = $databaseSize MB" + + ipv4Count=$(zgrep -h "$monthEnglish" /var/log/apache2/date.chapril.org/date.chapril.org-access.log*|grep "$year"|grep -vi bot|grep -v check_http|grep '^\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\} '|cut -d' ' -f1|sort|uniq |wc -l) + echo "Nombre d'ipv4 ayant visité le service = $ipv4Count" + + ipv6Count=$(zgrep -h "$monthEnglish" /var/log/apache2/date.chapril.org/date.chapril.org-access.log*|grep "$year"|grep -vi bot|grep -v check_http|grep '^\([0-9a-f]\{0,4\}:\)\{2,7\}\([0-9a-f]\{0,4\}\)\{1\} '|cut -d' ' -f1|sort|uniq |wc -l) + echo "Nombre d'ipv6 ayant visité le service = $ipv6Count" + + echo "Nombre total d'ip ayant visité le service = $((ipv4Count+ipv6Count))" + + ipv4UserCount=$(zgrep -h "$monthEnglish" /var/log/apache2/date.chapril.org/date.chapril.org-access.log*|grep "$year"|grep -vi bot|grep -v check_http|grep '^\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\} '|grep -v "GET \(/.git/|/img/|/i18n/|/js/|/fonts/|/css/\|/images/\| /\)"|grep -v "HTTP/1.0\" 404"|grep -v "HEAD"|grep -v "GET /"|cut -d' ' -f1|sort|uniq|wc -l ) + echo "Nombre d'ipv4 utilisatrices = $ipv4UserCount" + + ipv6UserCount=$(zgrep -h "$monthEnglish" /var/log/apache2/date.chapril.org/date.chapril.org-access.log*|grep "$year"|grep -vi bot|grep -v check_http|grep '^\([0-9a-f]\{0,4\}:\)\{2,7\}\([0-9a-f]\{0,4\}\)\{1\} '|grep -v "::1 "|grep -v "GET \(/.git/|/img/|/i18n/|/js/|/fonts/|/css/\|/images/\| /\)"|grep -v "HTTP/1.0\" 404"|grep -v "HEAD"|grep -v "GET /"|cut -d' ' -f1|sort|uniq|wc -l ) + echo "Nombre d'ipv6 utilisatrices = $ipv6UserCount" + + echo "Nombre total d'ip ayant utilisées le service = $((ipv4UserCount+ipv6UserCount))" + + echo -e "\n" + +} +# ============================================ +echo +if [ "$#" = 1 ] && [ "$1" = "-h" ]; then + help +elif [ "$#" = 1 ] && [ "$1" = "-p" ]; then + if [ "$(date +%m)" -gt 1 ]; then + precedingMonth="$((10#$(date +%m)-1))" + year="$(date +%Y)" + if [ $precedingMonth -lt 10 ]; then + month="${year}0$precedingMonth" + else + month="$year$precedingMonth" + fi + else + precedingMonth=12 + year="$(($(date +%Y)-1))" + month="$year$precedingMonth" + fi + monthEnglish=$(LANG=en_EN.UTF-8;date -d $year-$precedingMonth-01 +%b) + echo -e "Rapport d'activité du service date.chapril.org du mois $monthEnglish $year" + generateReport "$monthEnglish" "$month" "$year" +elif [ "$#" -eq 2 ]; then + if ! (let "$1") 2>/dev/null; then + echo -e "Le mois doit être numérique." + help + elif ([ "$1" -lt 1 ] || [ "$1" -gt 12 ]); then + echo -e "Numéro du mois non valable $1." + help + elif ! (let "$2") 2>/dev/null; then + echo -e "L'année doit être numérique." + help + elif [ "$2" -lt 2018 ] || [ "$2" -gt "$(date +%Y)" ]; then + echo -e "Année non valable $2." + help + elif [ "$2" -le 2017 ] || [ "$2" -ge $(($(date +%Y)+1)) ] ; then + echo -e "Pas de données pour ce mois." + help + else + if [ "$1" -lt 10 ]; then + month="$2"0"$1" + else + month="$2""$1" + fi + monthEnglish=$(LANG=en_EN.UTF-8;date -d "$2-$1-01" +%b) + year="$2" + echo -e "Rapport d'activité du service date.chapril.org du mois $monthEnglish $2" + generateReport "$monthEnglish" "$month" "$year" + fi +elif [ "$#" -eq 0 ]; then + month="$(date +%Y%m)" + monthEnglish=$(LANG=en_EN.UTF-8;date +%b) + year="$(date +%Y)" + echo -e "Rapport d'activité du service date.chapril.org du mois $(date +%b) 20$(date +%y)" + generateReport "$monthEnglish" "$month" "$year" +else + echo -e "Bad parameter." + help +fi