From fee60a01c812d33cdf414393a09a35ba7996d344 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Thu, 21 May 2020 18:02:42 +0200 Subject: [PATCH] Add LibreNMS Weathermap plugin (#81) --- Dockerfile | 16 ++++++--- README.md | 1 + doc/docker/environment-variables.md | 2 ++ examples/compose-legacy/librenms.env | 3 ++ examples/compose/librenms.env | 3 ++ examples/pwd/librenms.yml | 2 ++ examples/traefik/librenms.env | 3 ++ rootfs/etc/cont-init.d/03-config.sh | 5 +-- rootfs/etc/cont-init.d/08-svc-weathermap.sh | 38 +++++++++++++++++++++ 9 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 rootfs/etc/cont-init.d/08-svc-weathermap.sh diff --git a/Dockerfile b/Dockerfile index b5e0084..e6b5857 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,13 +27,12 @@ RUN apk --update --no-cache add \ coreutils \ curl \ fping \ - git \ graphviz \ imagemagick \ ipmitool \ + mariadb-client \ monitoring-plugins \ mtr \ - mysql-client \ net-snmp \ net-snmp-tools \ nginx \ @@ -105,7 +104,9 @@ ENV S6_BEHAVIOUR_IF_STAGE2_FAILS="2" \ PUID="1000" \ PGID="1000" -RUN mkdir -p /opt \ +RUN apk --update --no-cache add -t build-dependencies \ + git \ + && mkdir -p /opt \ && curl -sSL https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer \ && git clone --branch ${LIBRENMS_VERSION} https://github.com/librenms/librenms.git ${LIBRENMS_PATH} \ && COMPOSER_CACHE_DIR="/tmp" composer install --no-dev --no-interaction --no-ansi --working-dir=${LIBRENMS_PATH} \ @@ -118,8 +119,15 @@ RUN mkdir -p /opt \ && echo "foreach (glob(\"/data/config/*.php\") as \$filename) include \$filename;" >> ${LIBRENMS_PATH}/config.php \ && echo "foreach (glob(\"${LIBRENMS_PATH}/config.d/*.php\") as \$filename) include \$filename;" >> ${LIBRENMS_PATH}/config.php \ && pip3 install -r ${LIBRENMS_PATH}/requirements.txt \ + && git clone https://github.com/librenms-plugins/Weathermap.git ${LIBRENMS_PATH}/html/plugins/Weathermap \ && chown -R nobody.nogroup ${LIBRENMS_PATH} \ - && rm -rf ${LIBRENMS_PATH}/.git /tmp/* + && apk del build-dependencies \ + && rm -rf /var/cache/apk/* \ + ${LIBRENMS_PATH}/.git \ + ${LIBRENMS_PATH}/html/plugins/Test \ + ${LIBRENMS_PATH}/html/plugins/Weathermap/.git \ + ${LIBRENMS_PATH}/html/plugins/Weathermap/configs \ + /tmp/* COPY rootfs / diff --git a/README.md b/README.md index 214a44d..4ff5071 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ It's a fork of [CrazyMax's LibreNMS Docker image repository](https://github.com/ * [Dispatcher service](doc/docker/environment-variables.md#dispatcher-service) or legacy [cron](doc/docker/environment-variables.md#cron-legacy) as "sidecar" containers * Syslog-ng support through a ["sidecar" container](doc/docker/environment-variables.md#syslog-ng) * Ability to configure [distributed polling](https://docs.librenms.org/Extensions/Distributed-Poller/) +* Built-in LibreNMS [Weathermap plugin](https://docs.librenms.org/Extensions/Weathermap/) * Ability to add custom Monitoring plugins (Nagios) * OPCache enabled to store precompiled script bytecode in shared memory * [s6-overlay](https://github.com/just-containers/s6-overlay/) as process supervisor diff --git a/doc/docker/environment-variables.md b/doc/docker/environment-variables.md index d93f76d..6906077 100644 --- a/doc/docker/environment-variables.md +++ b/doc/docker/environment-variables.md @@ -83,6 +83,8 @@ ### Misc * `LIBRENMS_SNMP_COMMUNITY`: This container's SNMP v2c community string (default `librenmsdocker`) +* `LIBRENMS_WEATHERMAP`: Enable LibreNMS [Weathermap plugin](https://docs.librenms.org/Extensions/Weathermap/) (default `false`) +* `LIBRENMS_WEATHERMAP_SCHEDULE`: CRON expression format (default `*/5 * * * *`) * `MEMCACHED_HOST`: Hostname / IP address of a Memcached server * `MEMCACHED_PORT`: Port of the Memcached server (default `11211`) * `RRDCACHED_HOST`: Hostname / IP address of a RRDcached server diff --git a/examples/compose-legacy/librenms.env b/examples/compose-legacy/librenms.env index 6a91910..e9b8a8d 100644 --- a/examples/compose-legacy/librenms.env +++ b/examples/compose-legacy/librenms.env @@ -24,3 +24,6 @@ MEMCACHED_HOST=memcached MEMCACHED_PORT=11211 RRDCACHED_HOST=rrdcached RRDCACHED_PORT=42217 + +LIBRENMS_WEATHERMAP=false +LIBRENMS_WEATHERMAP_SCHEDULE=*/5 * * * * diff --git a/examples/compose/librenms.env b/examples/compose/librenms.env index 6b8655e..6fae16c 100644 --- a/examples/compose/librenms.env +++ b/examples/compose/librenms.env @@ -26,3 +26,6 @@ LIBRENMS_SERVICE_UPDATE_FREQUENCY=86400 LIBRENMS_SERVICE_PING_ENABLED=false LIBRENMS_SERVICE_WATCHDOG_ENABLED=false + +LIBRENMS_WEATHERMAP=false +LIBRENMS_WEATHERMAP_SCHEDULE=*/5 * * * * diff --git a/examples/pwd/librenms.yml b/examples/pwd/librenms.yml index 2dd9dbc..e7dc364 100644 --- a/examples/pwd/librenms.yml +++ b/examples/pwd/librenms.yml @@ -33,6 +33,8 @@ x-envlibrenms: &envlibrenms LIBRENMS_SERVICE_UPDATE_FREQUENCY: "86400" LIBRENMS_SERVICE_PING_ENABLED: "false" LIBRENMS_SERVICE_WATCHDOG_ENABLED: "false" + LIBRENMS_WEATHERMAP: "true" + LIBRENMS_WEATHERMAP_SCHEDULE: "*/5 * * * *" services: db: diff --git a/examples/traefik/librenms.env b/examples/traefik/librenms.env index bcc5fb3..6cdca5c 100644 --- a/examples/traefik/librenms.env +++ b/examples/traefik/librenms.env @@ -26,3 +26,6 @@ LIBRENMS_SERVICE_UPDATE_FREQUENCY=86400 LIBRENMS_SERVICE_PING_ENABLED=false LIBRENMS_SERVICE_WATCHDOG_ENABLED=false + +LIBRENMS_WEATHERMAP=false +LIBRENMS_WEATHERMAP_SCHEDULE=*/5 * * * * diff --git a/rootfs/etc/cont-init.d/03-config.sh b/rootfs/etc/cont-init.d/03-config.sh index b26bd31..c4b2247 100644 --- a/rootfs/etc/cont-init.d/03-config.sh +++ b/rootfs/etc/cont-init.d/03-config.sh @@ -86,7 +86,8 @@ sed -i -e "s/RANDOMSTRINGGOESHERE/${LIBRENMS_SNMP_COMMUNITY}/" /etc/snmp/snmpd.c # Init files and folders echo "Initializing LibreNMS files / folders..." -mkdir -p /data/config /data/logs /data/monitoring-plugins /data/rrd +mkdir -p /data/config /data/logs /data/monitoring-plugins /data/rrd /data/weathermap +ln -sf /data/weathermap ${LIBRENMS_PATH}/html/plugins/Weathermap/configs touch /data/logs/librenms.log rm -rf ${LIBRENMS_PATH}/logs rm -f ${LIBRENMS_PATH}/config.d/* @@ -188,7 +189,7 @@ fi # Fix perms echo "Fixing perms..." -chown librenms. /data/config /data/monitoring-plugins /data/rrd +chown librenms. /data/config /data/monitoring-plugins /data/rrd /data/weathermap chown -R librenms. /data/logs ${LIBRENMS_PATH}/config.d ${LIBRENMS_PATH}/bootstrap ${LIBRENMS_PATH}/logs ${LIBRENMS_PATH}/storage chmod ug+rw /data/logs /data/rrd ${LIBRENMS_PATH}/bootstrap/cache ${LIBRENMS_PATH}/storage ${LIBRENMS_PATH}/storage/framework/* diff --git a/rootfs/etc/cont-init.d/08-svc-weathermap.sh b/rootfs/etc/cont-init.d/08-svc-weathermap.sh new file mode 100644 index 0000000..48a568e --- /dev/null +++ b/rootfs/etc/cont-init.d/08-svc-weathermap.sh @@ -0,0 +1,38 @@ +#!/usr/bin/with-contenv bash + +CRONTAB_PATH="/var/spool/cron/crontabs" + +LIBRENMS_WEATHERMAP=${LIBRENMS_WEATHERMAP:-false} +LIBRENMS_WEATHERMAP_SCHEDULE=${LIBRENMS_WEATHERMAP_SCHEDULE:-*/5 * * * *} + +SIDECAR_CRON=${SIDECAR_CRON:-0} +SIDECAR_DISPATCHER=${SIDECAR_DISPATCHER:-0} +SIDECAR_SYSLOGNG=${SIDECAR_SYSLOGNG:-0} + +if [ "$SIDECAR_CRON" = "1" ] || [ "$SIDECAR_DISPATCHER" = "1" ] || [ "$SIDECAR_SYSLOGNG" = "1" ] || [ "$LIBRENMS_WEATHERMAP" != "true" ]; then + exit 0 +fi + +# Init +rm -rf ${CRONTAB_PATH} +mkdir -m 0644 -p ${CRONTAB_PATH} +touch ${CRONTAB_PATH}/librenms + +# Cron +if [ -n "$LIBRENMS_WEATHERMAP_SCHEDULE" ]; then + echo "Creating LibreNMS Weathermap cron task with the following period fields: $LIBRENMS_WEATHERMAP_SCHEDULE" + echo "${LIBRENMS_WEATHERMAP_SCHEDULE} php -f /opt/librenms/html/plugins/Weathermap/map-poller.php" >> ${CRONTAB_PATH}/librenms +fi + +# Fix perms +echo "Fixing crontabs permissions..." +chmod -R 0644 ${CRONTAB_PATH} + +# Create service +mkdir -p /etc/services.d/weathermap +cat > /etc/services.d/weathermap/run <