From 459159f5623ff92a38d6094db75b155221931878 Mon Sep 17 00:00:00 2001 From: tykayn Date: Thu, 26 Nov 2020 17:16:51 +0100 Subject: [PATCH 01/11] check version ok --- monitoring/check_version.sh | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 monitoring/check_version.sh diff --git a/monitoring/check_version.sh b/monitoring/check_version.sh new file mode 100644 index 0000000..c68746f --- /dev/null +++ b/monitoring/check_version.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# +# Nagios plugin to check mobilizon's version +# + +# program return value +# 0 : OK +# 1 : CRITICAL +# 2 : WARNING new version available +# 3 : UNKNOWN github or local repo not probable + +# project api for gitlab https://docs.gitlab.com/ee/api/tags.html +# upgrade documentation https://docs.joinmobilizon.org/administration/upgrading/ +LOCAL_REPO=/srv/mobilizon.chapril.org/live +FRAMAGIT_PROJECT_ID=20125 + + +function usage() { + echo "Usage : $0" +} + +# +if [ "$#" -ne 0 ]; then + usage +else + lastVersion=$(curl -s https://framagit.org/api/v4/projects/$FRAMAGIT_PROJECT_ID/releases | jshon -a -e name|cut -d '"' -f2|grep -v '[\^\(alpha\)]'|head -n 1) + currentVersion=$(cd $LOCAL_REPO && git branch | grep '*'|cut -c 3-100 ) + +# echo "current version: $currentVersion" +# echo "last version: $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 + From 4ea16c163a0f1533863236f89dd848638ded7180 Mon Sep 17 00:00:00 2001 From: tykayn Date: Thu, 26 Nov 2020 17:42:02 +0100 Subject: [PATCH 02/11] curl and show stats from GraphQL api --- rapport_activite/rapport_activite.sh | 39 ++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/rapport_activite/rapport_activite.sh b/rapport_activite/rapport_activite.sh index 1f3395b..5558244 100755 --- a/rapport_activite/rapport_activite.sh +++ b/rapport_activite/rapport_activite.sh @@ -30,6 +30,17 @@ source "/etc/mobilizon.chapril.org/mobilizonchaprilorg.conf" IPV4_PATTERN="[0-9]{1,3}(\.[0-9]{1,3}){3}" IPV6_PATTERN="[0-9a-f]{0,4}(:[0-9a-f]{0,4}){2,7}" + +# TODO métriques à récupérer +# https://docs.joinmobilizon.org/contribute/graphql_api/ +API_URL="https://mobilizon.chapril.org/api/" + +# get statistics from the graphQL api of the website + json=$(curl -X POST \ + -H "Content-Type: application/json" \ + --data '{"query":"{\n statistics {\n numberOfUsers\n numberOfEvents\n numberOfLocalEvents\n numberOfComments\n numberOfLocalComments\n numberOfGroups\n numberOfLocalGroups\n numberOfInstanceFollowers\n numberOfInstanceFollowings\n }\n}\n"}' $API_URL) + +echo $json; # help() { @@ -73,9 +84,19 @@ generateHTTPReport() echo } +# display the value of a key in the json fetched with curl +function show +{ + # to navigate to sub keys like data.statistics.my_key , we must use multiple -e extract options + local value=$(echo "$json" | jshon -e "data" -e "statistics" -e $1 -u) + printf " $key=$value" +} + # generateSpecificReport() { + + local monthEnglish="$1" local year="$2" local yearMonth="$3" @@ -90,11 +111,19 @@ generateSpecificReport() echo "Nombre d'ipv6 utilisatrices du service = $ipv6UserCount" echo "Nombre total d'ip utilisatrices du service = $((ipv4UserCount+ipv6UserCount))" - # TODO métriques à récupérer - # https://docs.joinmobilizon.org/contribute/graphql_api/ - echo "Nombre de comptes utilisateurs" - echo "Nombre d'évènements passés" - echo "Nombre d'évènements à venir" + +# echo "Nombre de comptes utilisateurs = " + show "numberOfEvents" + show "numberOfLocalEvents" + show "numberOfGroups" + show "numberOfLocalGroups" + show "numberOfComments" + show "numberOfLocalComments" + show "numberOfInstanceFollowers" + show "numberOfInstanceFollowings" + show "numberOfUsers" +# echo "Nombre d'évènements passés" +# echo "Nombre d'évènements à venir" echo } From 88ae1876c3e7910179092b8d919de0c454af9682 Mon Sep 17 00:00:00 2001 From: tykayn Date: Thu, 26 Nov 2020 17:43:11 +0100 Subject: [PATCH 03/11] correct check of version --- monitoring/.gitkeep | 0 monitoring/check_version.sh | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) delete mode 100644 monitoring/.gitkeep mode change 100644 => 100755 monitoring/check_version.sh diff --git a/monitoring/.gitkeep b/monitoring/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/monitoring/check_version.sh b/monitoring/check_version.sh old mode 100644 new mode 100755 index c9cc566..1b3e920 --- a/monitoring/check_version.sh +++ b/monitoring/check_version.sh @@ -26,8 +26,8 @@ else lastVersion=$(curl -s https://framagit.org/api/v4/projects/$FRAMAGIT_PROJECT_ID/releases | jshon -a -e name|cut -d '"' -f2|grep -v '[\^\(alpha\)]'|head -n 1) currentVersion=$(cd $LOCAL_REPO && git branch | grep '*'|cut -c 3-100 ) - echo "current version: $currentVersion" - echo "last version: $lastVersion" + #echo "current version: $currentVersion" + #echo "last version: $lastVersion" if [ $currentVersion = $lastVersion ]; then echo "OK" result=0 From 092e13a4111743803c5ffef440ae7c59780010ea Mon Sep 17 00:00:00 2001 From: tykayn Date: Thu, 26 Nov 2020 17:52:58 +0100 Subject: [PATCH 04/11] newline rapport activite --- rapport_activite/rapport_activite.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rapport_activite/rapport_activite.sh b/rapport_activite/rapport_activite.sh index 5558244..42de885 100755 --- a/rapport_activite/rapport_activite.sh +++ b/rapport_activite/rapport_activite.sh @@ -89,7 +89,7 @@ function show { # to navigate to sub keys like data.statistics.my_key , we must use multiple -e extract options local value=$(echo "$json" | jshon -e "data" -e "statistics" -e $1 -u) - printf " $key=$value" + printf "$1=$value\n" } # From 8de2f4c4561583327d240076608c993c79a84575 Mon Sep 17 00:00:00 2001 From: tykayn Date: Thu, 26 Nov 2020 17:55:34 +0100 Subject: [PATCH 05/11] remove curl json output --- rapport_activite/rapport_activite.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/rapport_activite/rapport_activite.sh b/rapport_activite/rapport_activite.sh index 42de885..f05d8de 100755 --- a/rapport_activite/rapport_activite.sh +++ b/rapport_activite/rapport_activite.sh @@ -40,7 +40,6 @@ API_URL="https://mobilizon.chapril.org/api/" -H "Content-Type: application/json" \ --data '{"query":"{\n statistics {\n numberOfUsers\n numberOfEvents\n numberOfLocalEvents\n numberOfComments\n numberOfLocalComments\n numberOfGroups\n numberOfLocalGroups\n numberOfInstanceFollowers\n numberOfInstanceFollowings\n }\n}\n"}' $API_URL) -echo $json; # help() { From f4246dfcfcc39081007de149280cc8bce4ef9cc9 Mon Sep 17 00:00:00 2001 From: tykayn Date: Thu, 26 Nov 2020 18:15:30 +0100 Subject: [PATCH 06/11] fix things to grep in report --- rapport_activite/rapport_activite.sh | 33 ++++++++++++++++++---------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/rapport_activite/rapport_activite.sh b/rapport_activite/rapport_activite.sh index f05d8de..122af2e 100755 --- a/rapport_activite/rapport_activite.sh +++ b/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." From 5de0869ed6677b918f1d4620ce031cec10bb4ac5 Mon Sep 17 00:00:00 2001 From: tykayn Date: Thu, 26 Nov 2020 18:18:47 +0100 Subject: [PATCH 07/11] date formats are different for error and access --- rapport_activite/rapport_activite.sh | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/rapport_activite/rapport_activite.sh b/rapport_activite/rapport_activite.sh index 122af2e..61ef172 100755 --- a/rapport_activite/rapport_activite.sh +++ b/rapport_activite/rapport_activite.sh @@ -56,26 +56,27 @@ generateHTTPReport() local monthEnglish="$1" local year="$2" local yearMonth="$3" - local dateLogYearMonth="$2/$4" + local errorLogFormatDate="$2/$4" + local accessLogFormatDate="$1/$2" echo "=§= Rapport d'activité HTTP" echo - local httpRequestCount=$(zgrep "$dateLogYearMonth" $LOG_PREFIX-access.log*|grep $year|wc -l) + local httpRequestCount=$(zgrep "$accessLogFormatDate" $LOG_PREFIX-access.log*|grep $year|wc -l) echo "Nombre total de requêtes http = $httpRequestCount" - local trueHttpRequestCount=$(zgrep "$dateLogYearMonth" $LOG_PREFIX-access.log*|grep $year|grep -vi bot|grep -v check_http|wc -l) + local trueHttpRequestCount=$(zgrep "$accessLogFormatDate" $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 "$dateLogYearMonth" $LOG_PREFIX-access.log*|grep "$year"|grep -i bot|grep -c -v check_http) + local botRequestCount=$(zgrep "$accessLogFormatDate" $LOG_PREFIX-access.log*|grep "$year"|grep -i bot|grep -c -v check_http) echo "Nombre de requêtes bot = $botRequestCount" - local errorRequestCount=$(zgrep "$dateLogYearMonth" $LOG_PREFIX-error.log*|grep -c "$year") + local errorRequestCount=$(zgrep "$errorLogFormatDate" $LOG_PREFIX-error.log*|grep -c "$year") echo "Nombre de requêtes http en erreur = $errorRequestCount" - 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 ) + local ipv4VisitorCount=$(zgrep -h "$accessLogFormatDate" $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 "$dateLogYearMonth" $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 "$accessLogFormatDate" $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))" @@ -100,21 +101,26 @@ generateSpecificReport() local year="$2" local yearMonth="$3" local numMonth="$4" - local dateLogYearMonth="$2/$4" + local errorLogFormatDate="$2/$4" + local accessLogFormatDate="$1/$2" # nginx shows logs like this: + # error log format: + # 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" + # access log, format : + # 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)" # 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 - errorsCount=$(zgrep -h "$dateLogYearMonth" $LOG_PREFIX-error.log*|wc -l ) + errorsCount=$(zgrep -h "$errorLogFormatDate" $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 ) + ipv4UserCount=$(zgrep -h "$accessLogFormatDate" $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 "$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 ) + ipv6UserCount=$(zgrep -h "$accessLogFormatDate" $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))" From 30b0bb0e79c4917364cf66b82ac8782fff9f8cbd Mon Sep 17 00:00:00 2001 From: tykayn Date: Thu, 26 Nov 2020 18:43:53 +0100 Subject: [PATCH 08/11] counter with numeric month --- rapport_activite/rapport_activite.sh | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/rapport_activite/rapport_activite.sh b/rapport_activite/rapport_activite.sh index 61ef172..fce39f4 100755 --- a/rapport_activite/rapport_activite.sh +++ b/rapport_activite/rapport_activite.sh @@ -103,12 +103,14 @@ generateSpecificReport() local numMonth="$4" local errorLogFormatDate="$2/$4" local accessLogFormatDate="$1/$2" +# echo " errorLogFormatDate $errorLogFormatDate" +# echo " accessLogFormatDate $accessLogFormatDate" # nginx shows logs like this: - # error log format: - # 2020/11/19 + # --------------------- error log format: + # --------------------- 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" - # access log, format : - # 26/Nov/2020 + # --------------------- access log, format : + # --------------------- 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)" # 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'erreurs = $errorsCount" -# echo "Nombre de comptes utilisateurs = " show "numberOfEvents" show "numberOfLocalEvents" show "numberOfGroups" @@ -145,7 +146,7 @@ generateSpecificReport() generateReport() { echo "Rapport d'activité du service $SERVICE_NAME de $monthEnglish $year" - echo + echo "" echo "=================================================================" echo generateHTTPReport "$1" "$2" "$3" "$4" @@ -160,6 +161,7 @@ if [ "$#" = 1 ] && [ "$1" = "-h" ]; then 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" @@ -170,6 +172,7 @@ elif [ "$#" = 1 ] && [ "$1" = "-p" ]; then precedingMonth=12 year="$(($(date +%Y)-1))" yearMonth="$year-$precedingMonth" + fi monthEnglish=$(LANG=en_EN.UTF-8;date -d $year-$precedingMonth-01 +%b) generateReport "$monthEnglish" "$year" "$yearMonth" "$precedingMonth" @@ -183,10 +186,10 @@ elif [ "$#" -eq 2 ]; then 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." + elif [ "$2" -lt 2020 ] || [ "$2" -gt "$(date +%Y)" ]; then + echo -e "Année non valable $2. Le service a été mis en ligne en Novembre 2020" 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." help else @@ -197,13 +200,16 @@ elif [ "$#" -eq 2 ]; then fi monthEnglish=$(LANG=en_EN.UTF-8;date -d "$2-$1-01" +%b) year="$2" - generateReport "$monthEnglish" "$year" "$yearMonth" + echo "et HOP ===================" + generateReport "$monthEnglish" "$year" "$yearMonth" "$1" fi elif [ "$#" -eq 0 ]; then yearMonth="$(date +%Y-%m)" + monthNumeric=$(date +%m) monthEnglish=$(LANG=en_EN.UTF-8;date +%b) year="$(date +%Y)" - generateReport "$monthEnglish" "$year" "$yearMonth" + echo "et TADAM ===================" + generateReport "$monthEnglish" "$year" "$yearMonth" $(date +%m) else echo -e "Bad parameter." help From c2434501ddbd0544b19a15ba44fae3ea3bd92a6d Mon Sep 17 00:00:00 2001 From: tykayn Date: Thu, 26 Nov 2020 18:46:34 +0100 Subject: [PATCH 09/11] remove tadam log --- rapport_activite/rapport_activite.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/rapport_activite/rapport_activite.sh b/rapport_activite/rapport_activite.sh index fce39f4..642b1be 100755 --- a/rapport_activite/rapport_activite.sh +++ b/rapport_activite/rapport_activite.sh @@ -200,7 +200,6 @@ elif [ "$#" -eq 2 ]; then fi monthEnglish=$(LANG=en_EN.UTF-8;date -d "$2-$1-01" +%b) year="$2" - echo "et HOP ===================" generateReport "$monthEnglish" "$year" "$yearMonth" "$1" fi elif [ "$#" -eq 0 ]; then @@ -208,7 +207,6 @@ elif [ "$#" -eq 0 ]; then monthNumeric=$(date +%m) monthEnglish=$(LANG=en_EN.UTF-8;date +%b) year="$(date +%Y)" - echo "et TADAM ===================" generateReport "$monthEnglish" "$year" "$yearMonth" $(date +%m) else echo -e "Bad parameter." From eeec1cc9f7ae9f1917904ebffe867ec17d9129f4 Mon Sep 17 00:00:00 2001 From: tykayn Date: Fri, 27 Nov 2020 12:14:51 +0100 Subject: [PATCH 10/11] make upgrade script --- upgrade/upgrade.sh | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 upgrade/upgrade.sh diff --git a/upgrade/upgrade.sh b/upgrade/upgrade.sh new file mode 100644 index 0000000..ca69784 --- /dev/null +++ b/upgrade/upgrade.sh @@ -0,0 +1,55 @@ +#!/bin/bash +# upgrade du mobilizon du Chapril +LOCAL_REPO=/srv/mobilizon.chapril.org/live +echo "========================= " +echo "=§= Upgrade de mobilizon " +echo "========================= " +echo " " +echo " https://docs.joinmobilizon.org/administration/upgrading/ " +echo " " +echo "=§= récupération du tag le plus récent" +echo " " +cd LOCAL_REPO +git fetch --tags + +lastVersion=$(curl -s https://framagit.org/api/v4/projects/$FRAMAGIT_PROJECT_ID/releases | jshon -a -e name|cut -d '"' -f2|grep -v '[\^\(alpha\)]'|head -n 1) +currentVersion=$(cd $LOCAL_REPO && git branch | grep '*'|cut -c 3-100 ) +if [ $currentVersion = $lastVersion ]; then + echo " " + echo "=§= pas besoin de mettre à jour, la version actuelle est déjà la plus récente" + echo " " + exit 0 + else + echo "UPGRADE : récupération de la version $lastVersion." + git status + git checkout $lastVersion + echo " " + echo "=§= stopper le service" + echo " " + service mobilizon stop + echo " " + echo "=§= recompiler le front end" + echo " " + cd js + NODE_BUILD_MEMORY=1024 yarn run build + echo " " + echo "=§= recompiler les elixirs du backend" + echo " " + cd .. + MIX_ENV=prod mix compile + + echo " " + echo "=§= migration de la base de données" + echo " " + MIX_ENV=prod mix ecto.migrate + + echo " " + echo "=§= migration de la base de données" + echo " " + service mobilizon start + journalctl -fu mobilizon.service + + # pour créer un utilisateur vous pouvez lancer cette commande + # MIX_ENV=prod mix mobilizon.users.new "your@email.com" --admin --password "Y0urP4ssw0rd" + + fi From 0b1481b22137846225d4957e634477ec7d9d8374 Mon Sep 17 00:00:00 2001 From: tykayn Date: Fri, 27 Nov 2020 12:15:04 +0100 Subject: [PATCH 11/11] silence curl and remove comm --- rapport_activite/rapport_activite.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rapport_activite/rapport_activite.sh b/rapport_activite/rapport_activite.sh index 642b1be..f843780 100755 --- a/rapport_activite/rapport_activite.sh +++ b/rapport_activite/rapport_activite.sh @@ -31,12 +31,11 @@ source "/etc/mobilizon.chapril.org/mobilizonchaprilorg.conf" IPV4_PATTERN="[0-9]{1,3}(\.[0-9]{1,3}){3}" IPV6_PATTERN="[0-9a-f]{0,4}(:[0-9a-f]{0,4}){2,7}" -# TODO métriques à récupérer # https://docs.joinmobilizon.org/contribute/graphql_api/ API_URL="https://mobilizon.chapril.org/api/" # get statistics from the graphQL api of the website - json=$(curl -X POST \ + json=$(curl -s -X POST \ -H "Content-Type: application/json" \ --data '{"query":"{\n statistics {\n numberOfUsers\n numberOfEvents\n numberOfLocalEvents\n numberOfComments\n numberOfLocalComments\n numberOfGroups\n numberOfLocalGroups\n numberOfInstanceFollowers\n numberOfInstanceFollowings\n }\n}\n"}' $API_URL)