Dépôt d'outils pour le service paste.chapril.org. https://paste.chapril.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
6.6 KiB

  1. #!/bin/bash
  2. #
  3. # Copyright (C) 2018, 2019 Didier Clermonté <dclermonte@april.org>
  4. # Copyright (C) 2018, 2019 Christian Pierre Momon <christian.momon@devinsy.fr>
  5. #
  6. # This file is part of paste.chapril.org.
  7. #
  8. # This script is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as
  10. # published by the Free Software Foundation, either version 3 of the
  11. # License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. # ============================================
  22. help()
  23. {
  24. echo "Usage:"
  25. echo " $(basename "$0") -h display help"
  26. echo " $(basename "$0") analyse current month"
  27. echo " $(basename "$0") -p analyse preceding month"
  28. echo " $(basename "$0") month_number year analyse this month"
  29. }
  30. generateReport()
  31. {
  32. local monthEnglish="$1"
  33. local year="$2"
  34. local yearMonth="$3"
  35. echo -e "================================================================="
  36. echo
  37. httpRequestCount=$(zgrep "$monthEnglish" /var/log/apache2/paste.chapril.org/paste.chapril.org-access.log*|grep $year|wc -l)
  38. echo "Nombre total de requêtes http = $httpRequestCount"
  39. trueHttpRequestCount=$(zgrep "$monthEnglish" /var/log/apache2/paste.chapril.org/paste.chapril.org-access.log*|grep $year|grep -vi bot|grep -v check_http|wc -l)
  40. echo "Nombre de vraies requêtes http = $trueHttpRequestCount"
  41. botRequestCount=$(zgrep "$monthEnglish" /var/log/apache2/paste.chapril.org/paste.chapril.org-access.log*|grep "$year"|grep -i bot|grep -c -v check_http)
  42. echo "Nombre de requêtes bot = $botRequestCount"
  43. errorsRequestCount=$(zgrep "$monthEnglish" /var/log/apache2/paste.chapril.org/paste.chapril.org-error.log*|grep -c "$year")
  44. echo "Nombre de requêtes http en erreur = $errorsRequestCount"
  45. createdPasteCount=$(grep "$yearMonth" /var/www/paste.chapril.org/paste.log | grep -c CREATE)
  46. echo "Nombre de pastes créés ce mois = $createdPasteCount"
  47. deletedPasteCount=$(grep "$yearMonth" /var/www/paste.chapril.org/paste.log | grep -c DELETE)
  48. echo "Nombre de pastes supprimés ce mois = $deletedPasteCount"
  49. commentCount=$(grep "$yearMonth" /var/www/paste.chapril.org/paste.log | grep -c COMMENT)
  50. echo "Nombre de commentaires ce mois = $commentCount"
  51. readPasteCount=$(grep "$yearMonth" /var/www/paste.chapril.org/paste.log | grep -c READ)
  52. echo "Nombre de lectures ce mois = $readPasteCount"
  53. echo "Nombre de lectures ce mois - les commentaires = $((readPasteCount-commentCount))"
  54. pasteCount=$(find /var/www/paste.chapril.org/data -mindepth 3 -maxdepth 3 -type f | wc -l)
  55. echo "Nombre de pastes dans la base actuellement = $pasteCount"
  56. pasteBaseSize=$(du -sh /var/www/paste.chapril.org/data |cut -f1)
  57. echo "Taille totale de la base des pastes = $pasteBaseSize"
  58. ipv4Count=$(zgrep -h "$monthEnglish" /var/log/apache2/paste.chapril.org/paste.chapril.org-access.log*|grep "$year"|grep -vi bot|grep -v check_http|grep '^\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\} '|cut -d' ' -f1|sort|uniq|wc -l )
  59. echo "Nombre d'ipv4 ayant visité le service = $ipv4Count"
  60. ipv6Count=$(zgrep -h "$monthEnglish" /var/log/apache2/paste.chapril.org/paste.chapril.org-access.log*|grep "$year"|grep -vi bot|grep -v check_http|grep '^\([0-9a-f]\{0,4\}:\)\{2,7\}\([0-9a-f]\{0,4\}\)\{1\} '|cut -d' ' -f1|sort|uniq|wc -l )
  61. echo "Nombre d'ipv6 ayant visité le service = $ipv6Count"
  62. echo "Nombre total d'ip ayant visité le service = $((ipv4Count+ipv6Count))"
  63. ipv4UserCount=$(zgrep -h "$monthEnglish" /var/log/apache2/paste.chapril.org/paste.chapril.org-access.log*|grep "$year"|grep -vi bot|grep -v check_http|grep '^\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\} '|grep POST|cut -d' ' -f 1|sort|uniq|wc -l )
  64. echo "Nombre d'ipv4 utilisatrices du service = $ipv4UserCount"
  65. ipv6UserCount=$(zgrep -h "$monthEnglish" /var/log/apache2/paste.chapril.org/paste.chapril.org-access.log*|grep "$year"|grep -vi bot|gre\p -v check_http|grep '^\([0-9a-f]\{0,4\}:\)\{2,7\}\([0-9a-f]\{0,4\}\)\{1\} '|grep POST|cut -d' ' -f 1|sort|uniq|wc -l )
  66. echo "Nombre d'ipv6 utilisatrices du service = $ipv6UserCount"
  67. echo "Nombre total d'ip utilisatrices du service = $((ipv4UserCount+ipv6UserCount))"
  68. echo -e "\n"
  69. }
  70. # ============================================
  71. echo
  72. if [ "$#" = 1 ] && [ "$1" = "-h" ]; then
  73. help
  74. elif [ "$#" = 1 ] && [ "$1" = "-p" ]; then
  75. if [ "$(date +%m)" -gt 1 ]; then
  76. precedingMonth="$((10#$(date +%m)-1))"
  77. year="$(date +%Y)"
  78. if [ $precedingMonth -lt 10 ]; then
  79. yearMonth="$year-0$precedingMonth"
  80. else
  81. yearMonth="$year-$precedingMonth"
  82. fi
  83. else [ "$(date +%m)" -eq 1 ]
  84. precedingMonth=12
  85. year="$(($(date +%Y)-1))"
  86. yearMonth="$year-$precedingMonth"
  87. fi
  88. monthEnglish=$(LANG=en_EN.UTF-8;date -d $year-$precedingMonth-01 +%b)
  89. echo -e "Rapport d'activité du service paste.chapril.org du mois $monthEnglish $year"
  90. generateReport "$monthEnglish" "$year" "$yearMonth"
  91. elif [ "$#" -eq 2 ]; then
  92. if ! (let "$1") 2>/dev/null; then
  93. echo -e "Le mois doit être numérique."
  94. help
  95. elif ([ "$1" -lt 1 ] || [ "$1" -gt 12 ]); then
  96. echo -e "Numéro du mois non valable $1."
  97. help
  98. elif ! (let "$2") 2>/dev/null; then
  99. echo -e "L'année doit être numérique."
  100. help
  101. elif [ "$2" -lt 2018 ] || [ "$2" -gt "$(date +%Y)" ]; then
  102. echo -e "Année non valable $2."
  103. help
  104. elif [ "$2" -le 2017 ] || [ "$2" -ge $(($(date +%Y)+1)) ] ; then
  105. echo -e "Pas de données pour ce mois."
  106. help
  107. else
  108. if [ "$1" -lt 10 ]; then
  109. yearMonth="$2-0$1"
  110. else
  111. yearMonth="$2-$1"
  112. fi
  113. monthEnglish=$(LANG=en_EN.UTF-8;date -d "$2-$1-01" +%b)
  114. year="$2"
  115. echo -e "Rapport d'activité du service paste.chapril.org du mois $monthEnglish $2"
  116. generateReport "$monthEnglish" "$year" "$yearMonth"
  117. fi
  118. elif [ "$#" -eq 0 ]; then
  119. yearMonth="$(date +%Y-%m)"
  120. monthEnglish=$(LANG=en_EN.UTF-8;date +%b)
  121. year="$(date +%Y)"
  122. echo -e "Rapport d'activité du service paste.chapril.org du mois $(date +%b) 20$(date +%y)"
  123. generateReport "$monthEnglish" "$year" "$yearMonth"
  124. else
  125. echo -e "Bad parameter."
  126. help
  127. fi