Implemented first indicators for the mumble activity report: users and connections

This commit is contained in:
Laurent Poujoulat 2020-04-27 16:02:20 +02:00 committed by root
parent f6bcd7a5cb
commit c4e5501b47

View File

@ -0,0 +1,88 @@
#! /bin/bash
#
# Copyright (C) 2020 Laurent Poujoulat <lpoujoulat@april.org>
#
# This file is part of mumble.chapril.org
#
# This script is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# ============================================
# This scripts reads the nextcloud state, extract the main status variables
# and writes a plain text report on stdout
# ============================================
# Configuration data
MUMBLE_STATS_DIR="/var/lib/mumble.chapril.org"
MUMBLE_STATS_FILE="${VALISE_STATS_DIR}/stats"
# Format statistic value for the report
writeStatValue()
{
local LABEL=$1
local UNIT=$2
local CUR_VALUE=$3
local PREV_VALUE=$4
local VARIATION=$(( ${CUR_VALUE}-${PREV_VALUE} ))
if [ ${VARIATION} -gt 0 ]
then
VARIATION="+"${VARIATION}
fi
if [ "${UNIT}" == "" ]
then
echo ${LABEL}": "${CUR_VALUE}" ("${VARIATION}")"
else
echo ${LABEL}": "${CUR_VALUE}" "${UNIT}" ("${VARIATION}")"
fi
}
# Extraction mumble important values
NB_OF_USERS=0
NB_OF_CONNECTIONS=0
# Work out iso date match for prev month
PREV_MONTH_MATCH=$(date +%Y-%m -d "1 month ago")
NB_OF_CONNECTIONS=$(grep -hE "<W>${PREV_MONTH_MATCH}.*New connection" /var/log/mumble-server/*.log.*|wc -l)
NB_OF_USERS=$(grep -hE "<W>${PREV_MONTH_MATCH}.*Authenticated" /var/log/mumble-server/*.log.*|grep -hEo "<[0-9]+\:.*\(-1\)"|grep -hEo "\:.*"|sort|uniq|wc -l)
# Get previous values
NB_OF_USERS_P=0
NB_OF_CONNECTIONS_P=0
if [ -e ${MUMBLE_STATS_FILE} ]
then
source ${MUMBLE_STATS_FILE}
fi
# Save current values for the next run
mkdir -p ${MUMBLE_STATS_DIR}
echo "NB_OF_USERS_P="${NB_OF_USERS} >> ${MUMBLE_STATS_FILE}
echo "NB_OF_CONNECTIONS_P="${NB_OF_CONNECTIONS} >> ${MUMBLE_STATS_FILE}
# Generate report
echo "Rapport d'activité du service mumble.chapril.org au "`date "+%-d %B %Y"`
echo
echo "================================================================="
echo
writeStatValue "Nombre d'utilisateurs" "" ${NB_OF_USERS} ${NB_OF_USERS_P}
writeStatValue "Nombre de connexions" "" ${NB_OF_CONNECTIONS} ${NB_OF_CONNECTIONS_P}
# Addition des infos HTTP
# /srv/mumble.chapril.org/tools/rapports_activites/rapport_activites_http.sh -p