24
0
Fork 0

counter with numeric month

This commit is contained in:
tykayn 2020-11-26 18:43:53 +01:00 committed by Baptiste Lemoine
parent 5de0869ed6
commit 30b0bb0e79
1 changed files with 17 additions and 11 deletions

View File

@ -103,12 +103,14 @@ generateSpecificReport()
local numMonth="$4" local numMonth="$4"
local errorLogFormatDate="$2/$4" local errorLogFormatDate="$2/$4"
local accessLogFormatDate="$1/$2" local accessLogFormatDate="$1/$2"
# echo " errorLogFormatDate $errorLogFormatDate"
# echo " accessLogFormatDate $accessLogFormatDate"
# nginx shows logs like this: # nginx shows logs like this:
# error log format: # --------------------- error log format:
# 2020/11/19 # --------------------- 2020/11/19
# 2020/11/19 20:31:05 [error] 1720#1720: *40 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.1.93, server: mobilizon.chapril.org, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:4000/", host: "mobilizon.chapril.org" # 2020/11/19 20:31:05 [error] 1720#1720: *40 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.1.93, server: mobilizon.chapril.org, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:4000/", host: "mobilizon.chapril.org"
# access log, format : # --------------------- access log, format :
# 26/Nov/2020 # --------------------- 26/Nov/2020
# 192.168.1.93 - - [26/Nov/2020:18:06:05 +0100] "GET / HTTP/1.1" 200 2731 "-" "check_http/v2.2 (monitoring-plugins 2.2)" # 192.168.1.93 - - [26/Nov/2020:18:06:05 +0100] "GET / HTTP/1.1" 200 2731 "-" "check_http/v2.2 (monitoring-plugins 2.2)"
# 7d01:4f8:14b:c41::12 - - [26/Nov/2020:18:07:06 +0100] "POST /api/ HTTP/1.1" 200 238 "-" "curl/7.64.0" # 7d01:4f8:14b:c41::12 - - [26/Nov/2020:18:07:06 +0100] "POST /api/ HTTP/1.1" 200 238 "-" "curl/7.64.0"
@ -126,7 +128,6 @@ generateSpecificReport()
echo "Nombre total d'ip utilisatrices du service = $((ipv4UserCount+ipv6UserCount))" echo "Nombre total d'ip utilisatrices du service = $((ipv4UserCount+ipv6UserCount))"
echo "Nombre total d'erreurs = $errorsCount" echo "Nombre total d'erreurs = $errorsCount"
# echo "Nombre de comptes utilisateurs = "
show "numberOfEvents" show "numberOfEvents"
show "numberOfLocalEvents" show "numberOfLocalEvents"
show "numberOfGroups" show "numberOfGroups"
@ -145,7 +146,7 @@ generateSpecificReport()
generateReport() generateReport()
{ {
echo "Rapport d'activité du service $SERVICE_NAME de $monthEnglish $year" echo "Rapport d'activité du service $SERVICE_NAME de $monthEnglish $year"
echo echo ""
echo "=================================================================" echo "================================================================="
echo echo
generateHTTPReport "$1" "$2" "$3" "$4" generateHTTPReport "$1" "$2" "$3" "$4"
@ -160,6 +161,7 @@ if [ "$#" = 1 ] && [ "$1" = "-h" ]; then
elif [ "$#" = 1 ] && [ "$1" = "-p" ]; then elif [ "$#" = 1 ] && [ "$1" = "-p" ]; then
if [ "$(date +%m)" -gt 1 ]; then if [ "$(date +%m)" -gt 1 ]; then
precedingMonth="$((10#$(date +%m)-1))" precedingMonth="$((10#$(date +%m)-1))"
year="$(date +%Y)" year="$(date +%Y)"
if [ $precedingMonth -lt 10 ]; then if [ $precedingMonth -lt 10 ]; then
yearMonth="$year-0$precedingMonth" yearMonth="$year-0$precedingMonth"
@ -170,6 +172,7 @@ elif [ "$#" = 1 ] && [ "$1" = "-p" ]; then
precedingMonth=12 precedingMonth=12
year="$(($(date +%Y)-1))" year="$(($(date +%Y)-1))"
yearMonth="$year-$precedingMonth" yearMonth="$year-$precedingMonth"
fi fi
monthEnglish=$(LANG=en_EN.UTF-8;date -d $year-$precedingMonth-01 +%b) monthEnglish=$(LANG=en_EN.UTF-8;date -d $year-$precedingMonth-01 +%b)
generateReport "$monthEnglish" "$year" "$yearMonth" "$precedingMonth" generateReport "$monthEnglish" "$year" "$yearMonth" "$precedingMonth"
@ -183,10 +186,10 @@ elif [ "$#" -eq 2 ]; then
elif ! (let "$2") 2>/dev/null; then elif ! (let "$2") 2>/dev/null; then
echo -e "L'année doit être numérique." echo -e "L'année doit être numérique."
help help
elif [ "$2" -lt 2018 ] || [ "$2" -gt "$(date +%Y)" ]; then elif [ "$2" -lt 2020 ] || [ "$2" -gt "$(date +%Y)" ]; then
echo -e "Année non valable $2." echo -e "Année non valable $2. Le service a été mis en ligne en Novembre 2020"
help help
elif [ "$2" -le 2017 ] || [ "$2" -ge $(($(date +%Y)+1)) ] ; then elif [ "$2" -le 2020 ] || [ "$2" -ge $(($(date +%Y)+1)) ] ; then
echo -e "Pas de données pour ce mois." echo -e "Pas de données pour ce mois."
help help
else else
@ -197,13 +200,16 @@ elif [ "$#" -eq 2 ]; then
fi fi
monthEnglish=$(LANG=en_EN.UTF-8;date -d "$2-$1-01" +%b) monthEnglish=$(LANG=en_EN.UTF-8;date -d "$2-$1-01" +%b)
year="$2" year="$2"
generateReport "$monthEnglish" "$year" "$yearMonth" echo "et HOP ==================="
generateReport "$monthEnglish" "$year" "$yearMonth" "$1"
fi fi
elif [ "$#" -eq 0 ]; then elif [ "$#" -eq 0 ]; then
yearMonth="$(date +%Y-%m)" yearMonth="$(date +%Y-%m)"
monthNumeric=$(date +%m)
monthEnglish=$(LANG=en_EN.UTF-8;date +%b) monthEnglish=$(LANG=en_EN.UTF-8;date +%b)
year="$(date +%Y)" year="$(date +%Y)"
generateReport "$monthEnglish" "$year" "$yearMonth" echo "et TADAM ==================="
generateReport "$monthEnglish" "$year" "$yearMonth" $(date +%m)
else else
echo -e "Bad parameter." echo -e "Bad parameter."
help help