fix things to grep in report

This commit is contained in:
tykayn 2020-11-26 18:15:30 +01:00 committed by Baptiste Lemoine
parent 8de2f4c456
commit f4246dfcfc

View File

@ -56,26 +56,26 @@ generateHTTPReport()
local monthEnglish="$1" local monthEnglish="$1"
local year="$2" local year="$2"
local yearMonth="$3" local yearMonth="$3"
local dateLogYearMonth="$2/$4"
echo "=§= Rapport d'activité HTTP" echo "=§= Rapport d'activité HTTP"
echo echo
local httpRequestCount=$(zgrep "$monthEnglish" $LOG_PREFIX-access.log*|grep $year|wc -l) local httpRequestCount=$(zgrep "$dateLogYearMonth" $LOG_PREFIX-access.log*|grep $year|wc -l)
echo "Nombre total de requêtes http = $httpRequestCount" echo "Nombre total de requêtes http = $httpRequestCount"
local trueHttpRequestCount=$(zgrep "$monthEnglish" $LOG_PREFIX-access.log*|grep $year|grep -vi bot|grep -v check_http|wc -l) local trueHttpRequestCount=$(zgrep "$dateLogYearMonth" $LOG_PREFIX-access.log*|grep $year|grep -vi bot|grep -v check_http|wc -l)
echo "Nombre de vraies requêtes http = $trueHttpRequestCount" echo "Nombre de vraies requêtes http = $trueHttpRequestCount"
local botRequestCount=$(zgrep "$monthEnglish" $LOG_PREFIX-access.log*|grep "$year"|grep -i bot|grep -c -v check_http) local botRequestCount=$(zgrep "$dateLogYearMonth" $LOG_PREFIX-access.log*|grep "$year"|grep -i bot|grep -c -v check_http)
echo "Nombre de requêtes bot = $botRequestCount" echo "Nombre de requêtes bot = $botRequestCount"
local errorRequestCount=$(zgrep "$monthEnglish" $LOG_PREFIX-error.log*|grep -c "$year") local errorRequestCount=$(zgrep "$dateLogYearMonth" $LOG_PREFIX-error.log*|grep -c "$year")
echo "Nombre de requêtes http en erreur = $errorRequestCount" echo "Nombre de requêtes http en erreur = $errorRequestCount"
local ipv4VisitorCount=$(zgrep -h "$monthEnglish" $LOG_PREFIX-access.log*|grep "$year"|grep -vi bot|grep -v check_http|egrep "^$IPV4_PATTERN "|cut -d' ' -f1|sort|uniq|wc -l ) local ipv4VisitorCount=$(zgrep -h "$dateLogYearMonth" $LOG_PREFIX-access.log*|grep "$year"|grep -vi bot|grep -v check_http|egrep "^$IPV4_PATTERN "|cut -d' ' -f1|sort|uniq|wc -l )
echo "Nombre d'ipv4 ayant visité le service = $ipv4VisitorCount" echo "Nombre d'ipv4 ayant visité le service = $ipv4VisitorCount"
local ipv6VisitorCount=$(zgrep -h "$monthEnglish" $LOG_PREFIX-access.log*|grep "$year"|grep -vi bot|grep -v check_http|egrep "^$IPV6_PATTERN "|cut -d' ' -f1|sort|uniq|wc -l ) local ipv6VisitorCount=$(zgrep -h "$dateLogYearMonth" $LOG_PREFIX-access.log*|grep "$year"|grep -vi bot|grep -v check_http|egrep "^$IPV6_PATTERN "|cut -d' ' -f1|sort|uniq|wc -l )
echo "Nombre d'ipv6 ayant visité le service = $ipv6VisitorCount" echo "Nombre d'ipv6 ayant visité le service = $ipv6VisitorCount"
echo "Nombre total d'ip ayant visité le service = $((ipv4VisitorCount+ipv6VisitorCount))" echo "Nombre total d'ip ayant visité le service = $((ipv4VisitorCount+ipv6VisitorCount))"
@ -99,17 +99,26 @@ generateSpecificReport()
local monthEnglish="$1" local monthEnglish="$1"
local year="$2" local year="$2"
local yearMonth="$3" local yearMonth="$3"
local numMonth="$4"
local dateLogYearMonth="$2/$4"
# nginx shows logs like this:
# 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"
# 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"
echo "=§= Rapport d'activité spécifique" echo "=§= Rapport d'activité spécifique"
echo echo
ipv4UserCount=$(zgrep -h "$monthEnglish" $LOG_PREFIX-access.log*|grep "$year"|grep -vi bot|grep -v check_http|egrep "^$IPV4_PATTERN " | cut -d' ' -f 1|sort|uniq|wc -l ) errorsCount=$(zgrep -h "$dateLogYearMonth" $LOG_PREFIX-error.log*|wc -l )
ipv4UserCount=$(zgrep -h "$dateLogYearMonth" $LOG_PREFIX-access.log*|grep "$year"|grep -vi bot|grep -v check_http|egrep "^$IPV4_PATTERN " | cut -d' ' -f 1|sort|uniq|wc -l )
echo "Nombre d'ipv4 utilisatrices du service = $ipv4UserCount" echo "Nombre d'ipv4 utilisatrices du service = $ipv4UserCount"
ipv6UserCount=$(zgrep -h "$monthEnglish" $LOG_PREFIX-access.log*|grep "$year"|grep -vi bot|gre\p -v check_http|egrep "^$IPV6_PATTERN " | cut -d' ' -f 1|sort|uniq|wc -l ) ipv6UserCount=$(zgrep -h "$dateLogYearMonth" $LOG_PREFIX-access.log*|grep "$year"|grep -vi bot|gre\p -v check_http|egrep "^$IPV6_PATTERN " | cut -d' ' -f 1|sort|uniq|wc -l )
echo "Nombre d'ipv6 utilisatrices du service = $ipv6UserCount" echo "Nombre d'ipv6 utilisatrices du service = $ipv6UserCount"
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 de comptes utilisateurs = " # echo "Nombre de comptes utilisateurs = "
show "numberOfEvents" show "numberOfEvents"
@ -133,8 +142,8 @@ generateReport()
echo echo
echo "=================================================================" echo "================================================================="
echo echo
generateHTTPReport "$1" "$2" "$3" generateHTTPReport "$1" "$2" "$3" "$4"
generateSpecificReport "$1" "$2" "$3" generateSpecificReport "$1" "$2" "$3" "$4"
} }
@ -157,7 +166,7 @@ elif [ "$#" = 1 ] && [ "$1" = "-p" ]; then
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" generateReport "$monthEnglish" "$year" "$yearMonth" "$precedingMonth"
elif [ "$#" -eq 2 ]; then elif [ "$#" -eq 2 ]; then
if ! (let "$1") 2>/dev/null; then if ! (let "$1") 2>/dev/null; then
echo -e "Le mois doit être numérique." echo -e "Le mois doit être numérique."