Telemt's Prometheus endpoint exposes only active-IP counts, while its loopback control API includes both the address list and sensitive proxy links. Add a root systemd timer that enters the Telemt container network namespace, filters the API response in memory, and publishes only username/address rows through the Zabbix agent key telemt.active_ips.list.\n\nThe collector refreshes every 30 seconds, writes atomically with root:zabbix 0640 permissions, and leaves the control API unexposed. Document the host installation and recommend one-day Zabbix history because client IP addresses are sensitive operational data.
53 lines
1.5 KiB
Bash
Executable File
53 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/bash
|
|
set -euo pipefail
|
|
|
|
container_name="ts-lan-telemt"
|
|
output_dir="/var/lib/zabbix"
|
|
json_target="${output_dir}/telemt-active-ips.json"
|
|
text_target="${output_dir}/telemt-active-ips.txt"
|
|
|
|
install -d -o root -g zabbix -m 0750 "${output_dir}"
|
|
|
|
container_pid="$(docker inspect --format '{{.State.Pid}}' "${container_name}")"
|
|
if [[ -z "${container_pid}" || "${container_pid}" == "0" ]]; then
|
|
exit 1
|
|
fi
|
|
|
|
json_tmp="$(mktemp "${output_dir}/.telemt-active-ips.json.XXXXXX")"
|
|
text_tmp="$(mktemp "${output_dir}/.telemt-active-ips.txt.XXXXXX")"
|
|
trap 'rm -f "${json_tmp}" "${text_tmp}"' EXIT
|
|
|
|
# The API response also contains proxy links and secrets. Filter it in-memory
|
|
# and persist only the username and current active IP address list.
|
|
nsenter -t "${container_pid}" -n \
|
|
curl --fail --silent --show-error --max-time 5 \
|
|
http://127.0.0.1:9091/v1/users |
|
|
jq --compact-output '{
|
|
users: [
|
|
.data[]
|
|
| {
|
|
username,
|
|
active_unique_ips: (.active_unique_ips_list // [])
|
|
}
|
|
]
|
|
}' > "${json_tmp}"
|
|
|
|
{
|
|
active_count="$(jq '[.users[].active_unique_ips[]] | length' "${json_tmp}")"
|
|
printf 'Active IP addresses: %s\n' "${active_count}"
|
|
jq --raw-output '
|
|
[
|
|
.users[] as $user
|
|
| $user.active_unique_ips[]
|
|
| "\($user.username) | \(.)"
|
|
]
|
|
| if length == 0 then ["No active IP addresses"] else . end
|
|
| .[]
|
|
' "${json_tmp}"
|
|
} > "${text_tmp}"
|
|
|
|
chown root:zabbix "${json_tmp}" "${text_tmp}"
|
|
chmod 0640 "${json_tmp}" "${text_tmp}"
|
|
mv -f "${json_tmp}" "${json_target}"
|
|
mv -f "${text_tmp}" "${text_target}"
|