From 80eefdfb616d7d376f694c2160788f7a4e1d3fe0 Mon Sep 17 00:00:00 2001 From: tykayn Date: Thu, 19 Nov 2020 11:07:57 +0100 Subject: [PATCH 1/6] :zap: add check version script using framagit's api --- .gitignore | 74 +++++++++++++++++++++++++++++++++++++ monitoring/check_version.sh | 39 +++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 .gitignore create mode 100644 monitoring/check_version.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aae71db --- /dev/null +++ b/.gitignore @@ -0,0 +1,74 @@ +# Created by .ignore support plugin (hsz.mobi) +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + diff --git a/monitoring/check_version.sh b/monitoring/check_version.sh new file mode 100644 index 0000000..1f9e086 --- /dev/null +++ b/monitoring/check_version.sh @@ -0,0 +1,39 @@ +#!/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 11-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 2d44eef91476b27f33bdd6bef08e9ce3b9e24fdc Mon Sep 17 00:00:00 2001 From: tykayn Date: Thu, 19 Nov 2020 15:02:25 +0100 Subject: [PATCH 2/6] ignore things for git --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index aae71db..555599c 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ # Generated files .idea/**/contentModel.xml +.idea # Sensitive or high-churn files .idea/**/dataSources/ From ac4e6cfcef732b7243fe144acfcb07c6b2f16539 Mon Sep 17 00:00:00 2001 From: tykayn Date: Thu, 19 Nov 2020 15:02:52 +0100 Subject: [PATCH 3/6] :zap: check version script adaptated from the framadate tool to monitor chapril date service --- monitoring/check_version.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/monitoring/check_version.sh b/monitoring/check_version.sh index 1f9e086..0b9c570 100644 --- a/monitoring/check_version.sh +++ b/monitoring/check_version.sh @@ -26,14 +26,14 @@ 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 11-100 ) - echo "current version: $currentVersion" - echo "last version: $lastVersion" - if [ $currentVersion = $lastVersion ]; then - echo "OK" - result=0 +# 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 + echo "WARNING : new version available, current is $currentVersion, last is $lastVersion." + result=1 fi fi exit $result From 090af318f5b48913e2e8f11b4c07b89c6971f14a Mon Sep 17 00:00:00 2001 From: tykayn Date: Fri, 20 Nov 2020 09:10:14 +0100 Subject: [PATCH 4/6] add correct log prefix --- rapport_activite/rapport_activite.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/rapport_activite/rapport_activite.sh b/rapport_activite/rapport_activite.sh index 4d2ea55..b209293 100755 --- a/rapport_activite/rapport_activite.sh +++ b/rapport_activite/rapport_activite.sh @@ -18,11 +18,12 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -# +# access_log /var/log/nginx/mobilizon.chapril.org/mobilizon.chapril.org-access.log +# error_log /var/log/nginx/mobilizon.chapril.org/mobilizon.chapril.org-error.log # ============================================ -LOG_PREFIX="/var/log/apache2/mobilizon.chapril.org/mobilizon.chapril.org" +LOG_PREFIX="/var/log/nginx/mobilizon.chapril.org/mobilizon.chapril.org" SERVICE_NAME="mobilizon.chapril.org" source "/etc/mobilizon.chapril.org/mobilizonchaprilorg.conf" @@ -48,7 +49,7 @@ generateHTTPReport() echo "=§= Rapport d'activité HTTP" echo - + local httpRequestCount=$(zgrep "$monthEnglish" $LOG_PREFIX-access.log*|grep $year|wc -l) echo "Nombre total de requêtes http = $httpRequestCount" @@ -63,7 +64,7 @@ generateHTTPReport() 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 ) 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 ) echo "Nombre d'ipv6 ayant visité le service = $ipv6VisitorCount" @@ -84,12 +85,12 @@ generateSpecificReport() 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 ) 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 ) echo "Nombre d'ipv6 utilisatrices du service = $ipv6UserCount" echo "Nombre total d'ip utilisatrices du service = $((ipv4UserCount+ipv6UserCount))" - echo + echo echo } @@ -136,7 +137,7 @@ 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 + elif [ "$2" -lt 2018 ] || [ "$2" -gt "$(date +%Y)" ]; then echo -e "Année non valable $2." help elif [ "$2" -le 2017 ] || [ "$2" -ge $(($(date +%Y)+1)) ] ; then @@ -147,7 +148,7 @@ elif [ "$#" -eq 2 ]; then yearMonth="$2-0$1" else yearMonth="$2-$1" - fi + fi monthEnglish=$(LANG=en_EN.UTF-8;date -d "$2-$1-01" +%b) year="$2" generateReport "$monthEnglish" "$year" "$yearMonth" From 5cd0178416fa7772c6c279ec06e5f7f3e6d6e945 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Thu, 26 Nov 2020 14:52:42 +0100 Subject: [PATCH 5/6] add todo elements --- .idea/mobilizon.chapril.org-tools.iml | 8 ++++ .idea/modules.xml | 8 ++++ .idea/vcs.xml | 6 +++ .idea/workspace.xml | 67 +++++++++++++++++++++++++++ monitoring/mobilizonchaprilorg.cron | 1 + rapport_activite/rapport_activite.sh | 17 ++++--- 6 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 .idea/mobilizon.chapril.org-tools.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 monitoring/mobilizonchaprilorg.cron diff --git a/.idea/mobilizon.chapril.org-tools.iml b/.idea/mobilizon.chapril.org-tools.iml new file mode 100644 index 0000000..c956989 --- /dev/null +++ b/.idea/mobilizon.chapril.org-tools.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..6f68488 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..23b641b --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1605258558512 + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/monitoring/mobilizonchaprilorg.cron b/monitoring/mobilizonchaprilorg.cron new file mode 100644 index 0000000..efd9224 --- /dev/null +++ b/monitoring/mobilizonchaprilorg.cron @@ -0,0 +1 @@ + 5 0 1 * * root /srv/mobilizon.chapril.org/tools/rapport_activite/rapport_activite.sh -p >> /srv/mobilizon.chapril.org/Exploitation/rapport_mobilizon.log 2>&1 diff --git a/rapport_activite/rapport_activite.sh b/rapport_activite/rapport_activite.sh index 4d2ea55..7adef67 100755 --- a/rapport_activite/rapport_activite.sh +++ b/rapport_activite/rapport_activite.sh @@ -48,7 +48,7 @@ generateHTTPReport() echo "=§= Rapport d'activité HTTP" echo - + local httpRequestCount=$(zgrep "$monthEnglish" $LOG_PREFIX-access.log*|grep $year|wc -l) echo "Nombre total de requêtes http = $httpRequestCount" @@ -63,7 +63,7 @@ generateHTTPReport() 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 ) 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 ) echo "Nombre d'ipv6 ayant visité le service = $ipv6VisitorCount" @@ -84,13 +84,16 @@ generateSpecificReport() 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 ) 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 ) echo "Nombre d'ipv6 utilisatrices du service = $ipv6UserCount" echo "Nombre total d'ip utilisatrices du service = $((ipv4UserCount+ipv6UserCount))" - echo - + # 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 } @@ -136,7 +139,7 @@ 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 + elif [ "$2" -lt 2018 ] || [ "$2" -gt "$(date +%Y)" ]; then echo -e "Année non valable $2." help elif [ "$2" -le 2017 ] || [ "$2" -ge $(($(date +%Y)+1)) ] ; then @@ -147,7 +150,7 @@ elif [ "$#" -eq 2 ]; then yearMonth="$2-0$1" else yearMonth="$2-$1" - fi + fi monthEnglish=$(LANG=en_EN.UTF-8;date -d "$2-$1-01" +%b) year="$2" generateReport "$monthEnglish" "$year" "$yearMonth" From 959294fd487c8e97d39367844796cc8dc5642723 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Thu, 26 Nov 2020 15:14:38 +0100 Subject: [PATCH 6/6] add readme showing graphql info --- .idea/workspace.xml | 11 +++++----- README.md | 51 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 README.md diff --git a/.idea/workspace.xml b/.idea/workspace.xml index ad12d01..245cfb3 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,9 +2,8 @@ - - - + + - + + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..077d357 --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +#Mobilizon Chapril Tools + +## Monitoring +Surveiller les signes de vie du site depuis Icinga. +https://icinga.chapril.org + + +## Rapport d'activité +Générer un rapport incluant des statistiques à propos de l'utilisation du site et le publier dans un ticket Redmine de Agir.chapril.org + +## Statistiques +obtention des statistiques publiques de l'instance par une requête GraphQL à l'url https://mobilizon.chapril.org/api/ dont le corps est: + +```graphql +{ + statistics { + numberOfUsers + numberOfEvents + numberOfLocalEvents + numberOfComments + numberOfLocalComments + numberOfGroups + numberOfLocalGroups + numberOfInstanceFollowers + numberOfInstanceFollowings + } +} +``` +exemple de réponse: +``` +{ + "data": { + "statistics": { + "numberOfComments": 9, + "numberOfEvents": 45, + "numberOfGroups": 7, + "numberOfInstanceFollowers": 0, + "numberOfInstanceFollowings": 1, + "numberOfLocalComments": 0, + "numberOfLocalEvents": 0, + "numberOfLocalGroups": 0, + "numberOfUsers": 1 + } + } +} +``` +Détail des paramètres à demander sur la doc: +https://framagit.org/framasoft/mobilizon/-/blob/master/js/schema.graphql + +On peut tester des requêtes sur cette sandbox +https://mobilizon.fr/graphiql