Extend the provisioned Telegram proxy fleet selector with visible host name 02-tekhnohim-docker while retaining the existing Agent 2 technical identity Fedora Kirochnaya.\n\nMake the collector read Prometheus metrics from 127.0.0.1:9090 inside the Telemt network namespace. This avoids dependence on host port 9092 and preserves the existing source-restricted metrics publication.\n\nValidated the dashboard with jq, the collector with bash -n, and the deployed Agent 2 keys on Client 02. The unrelated .DS_Store changes remain unstaged.
64 lines
2.1 KiB
Bash
Executable File
64 lines
2.1 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"
|
|
metrics_target="${output_dir}/telemt-metrics.prom"
|
|
|
|
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")"
|
|
metrics_tmp="$(mktemp "${output_dir}/.telemt-metrics.prom.XXXXXX")"
|
|
trap 'rm -f "${json_tmp}" "${text_tmp}" "${metrics_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[]] | unique | 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}"
|
|
|
|
# Cache Prometheus output from inside Telemt's network namespace. This avoids
|
|
# depending on the host-published metrics port or its source allowlist. Zabbix
|
|
# active checks read the cache, so the central server still needs no route to
|
|
# the private Docker host.
|
|
nsenter -t "${container_pid}" -n \
|
|
curl --fail --silent --show-error --max-time 5 \
|
|
http://127.0.0.1:9090/metrics > "${metrics_tmp}"
|
|
|
|
chown root:zabbix "${json_tmp}" "${text_tmp}" "${metrics_tmp}"
|
|
chmod 0640 "${json_tmp}" "${text_tmp}" "${metrics_tmp}"
|
|
mv -f "${json_tmp}" "${json_target}"
|
|
mv -f "${text_tmp}" "${text_target}"
|
|
mv -f "${metrics_tmp}" "${metrics_target}"
|