15
0
Fork 0
Browse Source

fix things to grep in report

master
tykayn 2 years ago committed by Baptiste Lemoine
parent
commit
f4246dfcfc
  1. 33
      rapport_activite/rapport_activite.sh

33
rapport_activite/rapport_activite.sh

@ -56,26 +56,26 @@ generateHTTPReport()
local monthEnglish="$1"
local year="$2"
local yearMonth="$3"
local dateLogYearMonth="$2/$4"
echo "=§= Rapport d'activité HTTP"
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"
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"
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"
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"
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"
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 total d'ip ayant visité le service = $((ipv4VisitorCount+ipv6VisitorCount))"
@ -99,17 +99,26 @@ generateSpecificReport()
local monthEnglish="$1"
local year="$2"
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
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"
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 total d'ip utilisatrices du service = $((ipv4UserCount+ipv6UserCount))"
echo "Nombre total d'erreurs = $errorsCount"
# echo "Nombre de comptes utilisateurs = "
show "numberOfEvents"
@ -133,8 +142,8 @@ generateReport()
echo
echo "================================================================="
echo
generateHTTPReport "$1" "$2" "$3"
generateSpecificReport "$1" "$2" "$3"
generateHTTPReport "$1" "$2" "$3" "$4"
generateSpecificReport "$1" "$2" "$3" "$4"
}
@ -157,7 +166,7 @@ elif [ "$#" = 1 ] && [ "$1" = "-p" ]; then
yearMonth="$year-$precedingMonth"
fi
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
if ! (let "$1") 2>/dev/null; then
echo -e "Le mois doit être numérique."

Loading…
Cancel
Save