1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

[synapse_]: Fix some stuff ...

- deactivated boolean values changed from 0 and 1 to false and true
- don't use  variable to store json (hitting ARG_MAX), but temporary file ()
This commit is contained in:
Sebastian L. 2025-01-15 15:26:21 +01:00
parent af90c6567d
commit 1b5aa8eb1f

View file

@ -168,18 +168,20 @@ EOM
esac esac
USERS=$(fetch_url -H "Authorization: Bearer ${AUTH_TOKEN}" "${SCHEME}${HOMESERVER}:${PORT}${ADMIN_API_PATH}/v2/users?deactivated=true&limit=${QUERY_LIMIT}") mktemp_command="${mktemp_command:-/usr/bin/mktemp}"
USERS_FILE=$($mktemp_command) || exit 73
trap 'rm -f "$USERS_FILE"' EXIT
fetch_url -H "Authorization: Bearer ${AUTH_TOKEN}" "${SCHEME}${HOMESERVER}:${PORT}${ADMIN_API_PATH}/v2/users?deactivated=true&limit=${QUERY_LIMIT}" > "$USERS_FILE"
ROOMS=$(fetch_url -H "Authorization: Bearer ${AUTH_TOKEN}" "${SCHEME}${HOMESERVER}:${PORT}${ADMIN_API_PATH}/v1/rooms?limit=${QUERY_LIMIT}") ROOMS=$(fetch_url -H "Authorization: Bearer ${AUTH_TOKEN}" "${SCHEME}${HOMESERVER}:${PORT}${ADMIN_API_PATH}/v1/rooms?limit=${QUERY_LIMIT}")
REPORTS=$(fetch_url -H "Authorization: Bearer ${AUTH_TOKEN}" "${SCHEME}${HOMESERVER}:${PORT}${ADMIN_API_PATH}/v1/event_reports" | jq .total) REPORTS=$(fetch_url -H "Authorization: Bearer ${AUTH_TOKEN}" "${SCHEME}${HOMESERVER}:${PORT}${ADMIN_API_PATH}/v1/event_reports" | jq .total)
echo multigraph synapse_users_"${CLEANHOMESERVER}" if total="$(jq -r .total "$USERS_FILE" | grep -E "^[0-9]+$")"; then
if USERS="$(echo "$USERS" | jq -r)"; then puppets="$(jq -r '.users[] | select(.deactivated==false) | select(.user_type!="bot")' "$USERS_FILE" | grep -c '"last_seen_ts": null')"
total="$(echo "$USERS" | jq -r .total)" bots="$(jq -r '.users[] | select(.deactivated==false)' "$USERS_FILE" | grep -c '"user_type": "bot"')"
puppets="$(echo "$USERS" | jq -r '.users[] | select(.deactivated!="1") | select(.user_type!="bot")' | grep -c '"last_seen_ts": null')"
bots="$(echo "$USERS" | jq -r '.users[] | select(.deactivated!="1")' | grep -c '"user_type": "bot"')"
virtual_users=$(( puppets + bots )) virtual_users=$(( puppets + bots ))
total_registered=$(( total - virtual_users )) total_registered=$(( total - virtual_users ))
active="$(echo "$USERS" | grep -c '"deactivated": 0')" active="$(jq -r < "$USERS_FILE" | grep -c '"deactivated": false')"
active_users=$(( active - virtual_users )) active_users=$(( active - virtual_users ))
echo total_registered.value "$total_registered" echo total_registered.value "$total_registered"
echo active_users.value "$active_users" echo active_users.value "$active_users"
@ -188,11 +190,11 @@ if USERS="$(echo "$USERS" | jq -r)"; then
time_ms=$(($(date +%s) * 1000)) time_ms=$(($(date +%s) * 1000))
interval_ms=$((INTERVAL * 1000)) interval_ms=$((INTERVAL * 1000))
time_interval_ago=$(( time_ms - interval_ms )) time_interval_ago=$(( time_ms - interval_ms ))
last_seen_times_ms=$(echo "$USERS" | jq -r '.users[] | select(.user_type!="bot") | select(.deactivated!="1")' | grep -E "\"last_seen_ts\": [0-9]+") last_seen_times_ms=$(jq -r '.users[] | select(.user_type!="bot") | select(.deactivated==true)' "$USERS_FILE" | grep -E "\"last_seen_ts\": [0-9]+")
online_users="$(echo "$last_seen_times_ms" | awk -v "count=0" -F": " '$2 > "'$time_interval_ago'" {count++} END {print count}')" online_users="$(echo "$last_seen_times_ms" | awk -v "count=0" -F": " '$2 > "'$time_interval_ago'" {count++} END {print count}')"
echo online_users.value "$online_users" echo online_users.value "$online_users"
echo deactivated_users.value "$(echo "$USERS" | grep -c '"deactivated": 1')" echo deactivated_users.value "$(grep -c '"deactivated": false' "$USERS_FILE")"
echo erased_users.value "$(echo "$USERS" | grep -c '"erased": true')" echo erased_users.value "$(grep -c '"erased": true' "$USERS_FILE")"
else else
echo "total_registered.value U" echo "total_registered.value U"
echo "active_users.value U" echo "active_users.value U"