Install and persist Grafana Zabbix plugin 6.5.0, provision the internal Zabbix datasource, and add a fleet dashboard modeled on client 02 Telemt panels. Add an active-agent Zabbix 7 template plus a 30-second sanitized collector for active IP count/list, connections, traffic, and uptime. Active checks avoid inbound polling of client-private Docker hosts. The exact Zabbix host names and required ZABBIX_API_TOKEN Portainer variable are documented. Compose validation passed on 10.0.0.6; the live plugin registered successfully under Grafana 13.1.0.
66 lines
2.1 KiB
Bash
Executable File
66 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
|
|
|
|
host_ip="$(ip -4 route get 1.1.1.1 | awk '{for (i=1; i<=NF; i++) if ($i == "src") {print $(i+1); exit}}')"
|
|
if [[ -z "${host_ip}" ]]; 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 locally. Zabbix active checks read the cache, so the
|
|
# central server does not need a route to each private Docker host.
|
|
curl --fail --silent --show-error --max-time 5 \
|
|
"http://${host_ip}:9092/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}"
|