FROM buildpack-deps:bookworm-curl
LABEL org.opencontainers.image.authors="dockerimage@dresi.wtf"

RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get upgrade -y && \
    DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
      iputils-ping snmp procps lm-sensors libcap2-bin && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

RUN wget -q -O - https://repos.influxdata.com/influxdata-archive.key | \
    gpg --dearmor > /etc/apt/trusted.gpg.d/influxdata.gpg

ENV TELEGRAF_VERSION=1.39.0
RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" && \
    case "${dpkgArch##*-}" in \
      amd64) ARCH='amd64';; \
      arm64) ARCH='arm64';; \
      *)     echo "Unsupported architecture: ${dpkgArch}"; exit 1;; \
    esac && \
    wget --no-verbose https://dl.influxdata.com/telegraf/releases/telegraf_${TELEGRAF_VERSION}-1_${ARCH}.deb.asc && \
    wget --no-verbose https://dl.influxdata.com/telegraf/releases/telegraf_${TELEGRAF_VERSION}-1_${ARCH}.deb && \
    gpg --batch --verify telegraf_${TELEGRAF_VERSION}-1_${ARCH}.deb.asc telegraf_${TELEGRAF_VERSION}-1_${ARCH}.deb && \
    dpkg -i telegraf_${TELEGRAF_VERSION}-1_${ARCH}.deb && \
    rm -f telegraf_${TELEGRAF_VERSION}-1_${ARCH}.deb*

RUN cd /usr/share/snmp/mibs && \
    wget -q https://raw.githubusercontent.com/net-snmp/net-snmp/master/mibs/SNMPv2-SMI.txt \
            https://raw.githubusercontent.com/net-snmp/net-snmp/master/mibs/SNMPv2-TC.txt \
            https://raw.githubusercontent.com/net-snmp/net-snmp/master/mibs/SNMPv2-CONF.txt \
            https://raw.githubusercontent.com/net-snmp/net-snmp/master/mibs/SNMPv2-MIB.txt \
            https://raw.githubusercontent.com/net-snmp/net-snmp/master/mibs/RFC1213-MIB.txt \
            https://raw.githubusercontent.com/net-snmp/net-snmp/master/mibs/HCNUM-TC.txt \
            https://raw.githubusercontent.com/net-snmp/net-snmp/master/mibs/HOST-RESOURCES-MIB.txt \
            https://raw.githubusercontent.com/net-snmp/net-snmp/master/mibs/IF-MIB.txt \
            https://raw.githubusercontent.com/net-snmp/net-snmp/master/mibs/SNMP-FRAMEWORK-MIB.txt && \
    wget -q -O UBNT-MIB \
      https://raw.githubusercontent.com/librenms/librenms/master/mibs/ubnt/UBNT-MIB && \
    wget -q -O UBNT-UniFi-MIB \
      https://raw.githubusercontent.com/librenms/librenms/master/mibs/ubnt/UBNT-UniFi-MIB && \
    echo "mibs +ALL" >> /etc/snmp/snmp.conf

COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["telegraf"]
