Add scripts used for activity reporting.
This commit is contained in:
parent
faa314a926
commit
cb9754cccf
12
README.md
12
README.md
|
@ -1 +1,13 @@
|
||||||
# XMPP tools
|
# XMPP tools
|
||||||
|
|
||||||
|
## Quickstart guide
|
||||||
|
|
||||||
|
mkdir -p /srv/xmpp.chapril.org
|
||||||
|
cd /src/xmpp.chapril.org
|
||||||
|
git clone ssh://gitea@forge.april.org:222/Chapril/xmpp.chapril.org-tools.git tools
|
||||||
|
cd /usr/local/sbin
|
||||||
|
ln -s /srv/xmpp.chapril.org/tools/rapport_activite/rapport_activites.sh
|
||||||
|
ln -s /srv/xmpp.chapril.org/tools/rapport_activite/update_ticket.sh
|
||||||
|
cat /etc/cron.d/update-ticket-rapport-dactivite
|
||||||
|
42 7 1 * * root API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx /usr/local/sbin/update_redmine_ticket
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
main() {
|
||||||
|
echo "h2. ## Global info"
|
||||||
|
echo ""
|
||||||
|
echo "* Total accounts: $(sudo -u ejabberd ejabberdctl registered_users chapril.org | egrep -v -e 'r\.giskard' -e '(lisa|bart)\.simpson' | wc -l)"
|
||||||
|
echo "* Total messages stored (MAM): $(count_archived_messages) "
|
||||||
|
# echo "Active users: $(sudo -u ejabberd ejabberdctl connected_users_number)"
|
||||||
|
echo ""
|
||||||
|
echo "h2. ## HTTP upload storage:"
|
||||||
|
echo ""
|
||||||
|
echo "* User quota: $(get_hard_quota)M"
|
||||||
|
echo "* Total disk usage: $(du -sh /srv/ejabberd/chapril.org/upload/ | awk '{print $1}')"
|
||||||
|
per_account_storage_usage
|
||||||
|
# echo "s2s outgoing connections: $(sudo -u ejabberd ejabberdctl incoming_s2s_number)"
|
||||||
|
# echo "s2s incoming connections: $(sudo -u ejabberd ejabberdctl outgoing_s2s_number)"
|
||||||
|
}
|
||||||
|
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
|
||||||
|
count_archived_messages() {
|
||||||
|
psql -U ejabberd -h localhost ejabberd -c "select count(*) from archive where peer not like 'irc%' and username not in ('r.giskard', 'lisa.simpson', 'bart.simpson')" -t | grep -v '^$' | awk '{print $1}'
|
||||||
|
}
|
||||||
|
|
||||||
|
main
|
|
@ -0,0 +1,46 @@
|
||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
REDMINE_BASE_URL="https://agir.april.org"
|
||||||
|
TICKET_ID=4047
|
||||||
|
REPORT_COMMAND="/usr/local/sbin/display_activity_report"
|
||||||
|
|
||||||
|
if [ 'z' = "z${API_KEY}" ]; then
|
||||||
|
echo "Missing environment variable API_KEY" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
main() {
|
||||||
|
post_report
|
||||||
|
}
|
||||||
|
|
||||||
|
post_report() {
|
||||||
|
datafile=$(mktemp /tmp/report_stats_$(date +%Y-%m-%d_%H%M)_XXXX.json)
|
||||||
|
cat <<EOF > "${datafile}"
|
||||||
|
{
|
||||||
|
"issue": {
|
||||||
|
"notes": "$(${REPORT_COMMAND} | sed -z 's/\n/\\n/g')"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
curl -s \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "X-Redmine-API-Key: ${API_KEY}" \
|
||||||
|
-X PUT --data-binary "@${datafile}" \
|
||||||
|
"${REDMINE_BASE_URL}/issues/${TICKET_ID}.json"
|
||||||
|
rm "${datafile}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# debug function
|
||||||
|
last_comment_date() {
|
||||||
|
curl -H "X-Redmine-API-Key: ${API_KEY}" -s "${REDMINE_BASE_URL}/issues/${TICKET_ID}.json?include=journals" \
|
||||||
|
| jq '.issue.journals | last | .created_on'
|
||||||
|
}
|
||||||
|
|
||||||
|
# debug function
|
||||||
|
list() {
|
||||||
|
curl -H "X-Redmine-API-Key: ${API_KEY}" -s "${REDMINE_BASE_URL}/issues/${TICKET_ID}.json?include=journals" \
|
||||||
|
| jq '.issue.journals[] | [.user.name, .notes]'
|
||||||
|
}
|
||||||
|
|
||||||
|
main
|
Loading…
Reference in New Issue