23
2
Fork 0

Add script to generate chaprilinfos properties file.

This commit is contained in:
pitchum 2021-01-04 13:45:42 +01:00 committed by root
parent 4720e4fc0b
commit f884dfdd57
3 changed files with 118 additions and 0 deletions

3
chaprilinfos/README.md Normal file
View File

@ -0,0 +1,3 @@
# ChaprilInfos generator
Cf. https://admin.chapril.org/doku.php?id=admin:services:statoolinfos.chapril.org

View File

@ -0,0 +1,37 @@
# [File]
file.class=service
file.generator=StatoolInfos
file.datetime=2020-12-10T23:15:23.723024
file.protocol=StatoolInfos-0.1.0
# [Service]
service.name=XMPP Chapril
service.description=Service de messagerie instantanée.
service.website=https://xmpp.chapril.org/
service.logo=https://www.chapril.org/.well-known/chaprilinfos/chapril-logo-mini.png
service.legal.url=https://www.chapril.org/cgu.html
service.guide.technical=https://admin.chapril.org/doku.php?id=admin:services:xmpp.chapril.org
service.guide.user=https://www.chapril.org/XMPP
service.contact.url=https://www.chapril.org/contact.xhtml
service.contact.email=xmpp-support@chapril.org
service.startDate=08/03/2020
service.endDate=
service.status.level=OK
service.status.description=Nominal
service.registration=Free
# [Host]
host.name=Hetzner
host.server.type=VIRTUAL
host.provider.type=HOSTEDSERVER
host.country.name=Allemagne
host.country.code=DE
# [Software]
software.name=ejabberd
software.website=https://www.ejabberd.im/
software.license.url=https://github.com/processone/ejabberd/blob/master/COPYING
software.license.name=GPLv2
software.version=__EJABBERD_VERSION__
software.source.url=https://github.com/processone/ejabberd/

View File

@ -0,0 +1,78 @@
#! /bin/bash
TEMPLATE=/srv/xmpp.chapril.org/tools/chaprilinfos/template-chaprilinfos.properties
TARGET_FILE=/srv/chaprilinfos/well-known/xmppchaprilorg.properties
main() {
cat "${TEMPLATE}" \
| sed "s/__EJABBERD_VERSION__/$(get_ejabberd_version)/" \
> ${TARGET_FILE}
# | sed "s/__USER_QUOTA__/$(get_hard_quota)/" \
# | sed "s/__UPLOAD_RETENTION__/1y/" \
# | sed "s/__TOTAL_USER_ACCOUNTS__/$(count_user_accounts)/" \
# | sed "s/__STARTTIME_WEEK__/$(starttime 7)/" \
# | sed "s/__STARTTIME_MONTH__/$(starttime 30)/" \
# | sed "s/__STARTTIME_HALFYEAR__/$(starttime 180)/" \
# | sed "s/__ACTIVE_USER_WEEK__/$(user_activity 7)/" \
# | sed "s/__ACTIVE_USER_MONTH__/$(user_activity 30)/" \
# | sed "s/__ACTIVE_USER_HALFYEAR__/$(user_activity 180)/" \
# | sed "s/__POSTS_COUNT__/$(count_archived_messages)/" \
# | sed "s/__AVG_DISK_USED_PER_USER__/$(TODO)/" \
}
get_ejabberd_version() {
dpkg -l ejabberd | grep ejabberd | awk '{print $3}'
}
count_user_accounts() {
# exclude special accounts like r.giskard (for compliance tester) an bart and lisa for testing.
sudo -u ejabberd ejabberdctl registered_users chapril.org | egrep -v -e 'r\.giskard' -e '(lisa|bart)\.simpson' | wc -l
}
get_hard_quota() {
grep hard_quota /etc/ejabberd/ejabberd.yml -A2 | grep all | sed -r 's/^\s*-\s([0-9]+).*/\1/'
}
per_account_storage_usage() {
STORAGE_DIR="/srv/ejabberd/chapril.org/upload/"
# TODO Directories to ignore because they are used for tests accounts (bart and lisa simpsons)
IGNORE_DIRS="35eae3ddc83d72e4d3fad3160a400db688d7d936 9be859c77649f33d207cbe0d74a126b2fd31cb33"
echo "Per user disk usage:"
tmp="$(du -sh ${STORAGE_DIR}* | sort -hr | awk '{print $1}')"
echo "** Max: "$(echo "${tmp}" | head -n 1)
# echo " Min: "$(echo "${tmp}" | tail -n 1)
subfolders_count=$(find ${STORAGE_DIR} -mindepth 1 -maxdepth 1 -type d | wc -l)
total_size=$(du -s ${STORAGE_DIR} | awk '{print $1}')
avg=$(((${total_size} / 1024) / ${subfolders_count}))
echo "** Avg: ${avg}M"
}
starttime() {
days_back=${1:-30}
date -u +%Y-%m-%dT%H:%M:%SZ --date="08:42 ${days_back} days ago"
}
user_activity() {
days_back=${1:-30}
sql="select count(distinct l.username)
from last l
where to_timestamp(cast(l.seconds as int)) > current_timestamp - interval '${days_back} days'
and username not in ('r.giskard', 'lisa.simpson', 'bart.simpson')"
psql -U ejabberd -h localhost ejabberd -c "${sql}" -t | grep -v '^$' | awk '{print $1}'
}
count_archived_messages() {
sql="select count(*)
from archive
where peer not like 'irc%'
and username not in ('r.giskard', 'lisa.simpson', 'bart.simpson')"
psql -U ejabberd -h localhost ejabberd -c "${sql}" -t | grep -v '^$' | awk '{print $1}'
}
main