Compare commits

...

6 Commits

View File

@ -33,11 +33,13 @@ IPV6_PATTERN="[0-9a-f]{0,4}(:[0-9a-f]{0,4}){2,7}"
#
help()
{
local prog
prog=$(basename "$0")
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"
echo " $prog -h display help"
echo " $prog analyse current month"
echo " $prog -p analyse preceding month"
echo " $prog month_number year analyse this month"
}
#
@ -49,23 +51,29 @@ generateHTTPReport()
echo "=§= Rapport d'activité HTTP"
echo
local httpRequestCount=$(zgrep "$monthEnglish" $LOG_PREFIX-access.log*|grep $year|wc -l)
local httpRequestCount
httpRequestCount=$(zgrep "$monthEnglish" $LOG_PREFIX-access.log*|grep -c "$year")
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
trueHttpRequestCount=$(zgrep "$monthEnglish" $LOG_PREFIX-access.log*|grep "$year"|grep -vi bot|grep -c -v check_http)
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
botRequestCount=$(zgrep "$monthEnglish" $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
errorRequestCount=$(zgrep "$monthEnglish" "$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
ipv4VisitorCount=$(zgrep -h "$monthEnglish" $LOG_PREFIX-access.log*|grep "$year"|grep -vi bot|grep -v check_http|grep -E "^$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
ipv6VisitorCount=$(zgrep -h "$monthEnglish" $LOG_PREFIX-access.log*|grep "$year"|grep -vi bot|grep -v check_http|grep -E "^$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))"
@ -83,10 +91,10 @@ generateSpecificReport()
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 )
ipv4UserCount=$(zgrep -h "$monthEnglish" $LOG_PREFIX-access.log*|grep "$year"|grep -vi bot|grep -v check_http|grep -E "^$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 "$monthEnglish" $LOG_PREFIX-access.log*|grep "$year"|grep -vi bot|grep -v check_http|grep -E "^$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))"
@ -95,45 +103,56 @@ generateSpecificReport()
# https://forge.chapril.org/api/swagger
#$(curl -s --dump-header - "https://forge.chapril.org/api/v1/admin/orgs?limit=1&page1&token=$GITEA_API_KEY" > t)
#$(curl -s "https://forge.chapril.org/api/v1/users/search?limit=1&token=$GITEA_API_KEY" | jq '. | length' > t)
local accountCount=$(curl -s "https://forge.chapril.org/api/v1/users/search?limit=100000&token=$GITEA_API_KEY" | jq '.data | length')
local accountCount
accountCount=$(curl -s "https://forge.chapril.org/api/v1/users/search?limit=100000&token=$GITEA_API_KEY" | jq '.data | length')
echo "Nombre de comptes = $accountCount"
local connectedAccountCount=$(curl -s "https://forge.chapril.org/api/v1/users/search?limit=100000&token=$GITEA_API_KEY" | jq '.data[].last_login' | grep -cv "1970")
local connectedAccountCount
connectedAccountCount=$(curl -s "https://forge.chapril.org/api/v1/users/search?limit=100000&token=$GITEA_API_KEY" | jq '.data[].last_login' | grep -cv "1970")
echo "Nombre de comptes connectés au moins une fois = $connectedAccountCount"
local unconnectedAccountCount=$(curl -s "https://forge.chapril.org/api/v1/users/search?limit=100000&token=$GITEA_API_KEY" | jq '.data[].last_login' | grep -c "1970")
local unconnectedAccountCount
unconnectedAccountCount=$(curl -s "https://forge.chapril.org/api/v1/users/search?limit=100000&token=$GITEA_API_KEY" | jq '.data[].last_login' | grep -c "1970")
echo "Nombre de comptes jamais connectés = $unconnectedAccountCount"
#$(curl -s "https://forge.chapril.org/api/v1/admin/orgs?limit=100000&token=$GITEA_API_KEY" | jq '. | length' > t)
local organizationCount=$(curl -s "https://forge.chapril.org/api/v1/admin/orgs?limit=100000&token=$GITEA_API_KEY" | jq '. | length')
local organizationCount
organizationCount=$(curl -s "https://forge.chapril.org/api/v1/admin/orgs?limit=100000&token=$GITEA_API_KEY" | jq '. | length')
if [[ -z "$organizationCount" ]]; then
organizationCount=0
organizationCount=0
fi
echo "Nombre d'organisations = $organizationCount"
#$(curl -s "https://forge.chapril.org/api/v1/orgs?limit=100000" > t)
local publicOrganizationCount=$(curl -s "https://forge.chapril.org/api/v1/orgs?limit=100000" | jq '. | length')
local publicOrganizationCount
publicOrganizationCount=$(curl -s "https://forge.chapril.org/api/v1/orgs?limit=100000" | jq '. | length')
if [[ -z "$publicOrganizationCount" ]]; then
publicOrganizationCount=0
publicOrganizationCount=0
fi
echo "Nombre d'organisations publiques = $publicOrganizationCount"
local repositoryCount=$(curl -s --dump-header - "https://forge.chapril.org/api/v1/repos/search?limit=1&token=$GITEA_API_KEY" | grep "X-Total-Count\:" | awk '{ print $2 }' | jq '.')
local repositoryCount
repositoryCount=$(curl -s --dump-header - "https://forge.chapril.org/api/v1/repos/search?limit=1&token=$GITEA_API_KEY" | grep "X-Total-Count\:" | awk '{ print $2 }' | jq '.')
echo "Nombre de dépôts = $repositoryCount"
local publicRepositoryCount=$(curl -s --dump-header - "https://forge.chapril.org/api/v1/repos/search?limit=1" | grep "X-Total-Count\:" | awk '{ print $2 }' | jq '.')
local publicRepositoryCount
publicRepositoryCount=$(curl -s --dump-header - "https://forge.chapril.org/api/v1/repos/search?limit=1" | grep "X-Total-Count\:" | awk '{ print $2 }' | jq '.')
echo "Nombre de dépôts publics = $publicRepositoryCount"
local repositorySpaceDisk=$(du -sh "$GITEA_REPO_HOME" | head -1 | awk '{ print $1 } ')
local repositorySpaceDisk
repositorySpaceDisk=$(du -sh "$GITEA_REPO_HOME" | head -1 | awk '{ print $1 } ')
echo "Espace disque occupé par les dépôts = $repositorySpaceDisk"
local directoryCount=$(find "$GITEA_REPO_HOME" -type d | wc -l )
local directoryCount
directoryCount=$(find "$GITEA_REPO_HOME" -type d | wc -l )
echo "Nombre de dossiers de l'espace disque = $directoryCount"
local fileCount=$(find "$GITEA_REPO_HOME" -type f | wc -l )
local fileCount
fileCount=$(find "$GITEA_REPO_HOME" -type f | wc -l )
echo "Nombre de fichiers de l'espace disque = $fileCount"
local totalFileCount=$(find "$GITEA_REPO_HOME" | wc -l )
local totalFileCount
totalFileCount=$(find "$GITEA_REPO_HOME" | wc -l )
echo "Nombre total de fichiers de l'espace disque = $totalFileCount"
echo
@ -157,45 +176,45 @@ 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
yearMonth="$year-0$precedingMonth"
else
yearMonth="$year-$precedingMonth"
fi
precedingMonth="$((10#$(date +%m)-1))"
year="$(date +%Y)"
if [ $precedingMonth -lt 10 ]; then
yearMonth="$year-0$precedingMonth"
else
yearMonth="$year-$precedingMonth"
fi
else [ "$(date +%m)" -eq 1 ]
precedingMonth=12
year="$(($(date +%Y)-1))"
yearMonth="$year-$precedingMonth"
precedingMonth=12
year="$(($(date +%Y)-1))"
yearMonth="$year-$precedingMonth"
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"
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
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
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
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
echo -e "Pas de données pour ce mois."
help
else
if [ "$1" -lt 10 ]; then
yearMonth="$2-0$1"
else
yearMonth="$2-$1"
fi
monthEnglish=$(LANG=en_EN.UTF-8;date -d "$2-$1-01" +%b)
year="$2"
generateReport "$monthEnglish" "$year" "$yearMonth"
if [ "$1" -lt 10 ]; then
yearMonth="$2-0$1"
else
yearMonth="$2-$1"
fi
monthEnglish=$(LANG=en_EN.UTF-8;date -d "$2-$1-01" +%b)
year="$2"
generateReport "$monthEnglish" "$year" "$yearMonth"
fi
elif [ "$#" -eq 0 ]; then
yearMonth="$(date +%Y-%m)"