From 178076a796e534c20ae630279a41090f32e67ff5 Mon Sep 17 00:00:00 2001 From: Andy Grunwald Date: Fri, 7 Feb 2025 22:30:17 +0100 Subject: [PATCH] New Script: Prometheus Paperless NGX Exporter --- ct/prometheus-paperless-ngx-exporter.sh | 67 +++++++++++++++++++ ...ometheus-paperless-ngx-exporter-install.sh | 64 ++++++++++++++++++ json/prometheus-paperless-ngx-exporter.json | 43 ++++++++++++ 3 files changed, 174 insertions(+) create mode 100755 ct/prometheus-paperless-ngx-exporter.sh create mode 100755 install/prometheus-paperless-ngx-exporter-install.sh create mode 100644 json/prometheus-paperless-ngx-exporter.json diff --git a/ct/prometheus-paperless-ngx-exporter.sh b/ct/prometheus-paperless-ngx-exporter.sh new file mode 100755 index 00000000..22ffec88 --- /dev/null +++ b/ct/prometheus-paperless-ngx-exporter.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func) +# Copyright (c) 2021-2025 community-scripts ORG +# Author: Andy Grunwald (andygrunwald) +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE +# Source: https://github.com/hansmi/prometheus-paperless-exporter + +# App Default Values +APP="Prometheus-Paperless-NGX-Exporter" +var_tags="monitoring;alerting" +var_cpu="1" +var_ram="256" +var_disk="2" +var_os="debian" +var_version="12" +var_unprivileged="1" + +# App Output & Base Settings +header_info "$APP" +base_settings + +# Core +variables +color +catch_errors + +function update_script() { + header_info + check_container_storage + check_container_resources + if [[ ! -f /etc/systemd/system/prometheus-paperless-ngx-exporter.service ]]; then + msg_error "No ${APP} Installation Found!" + exit + fi + RELEASE=$(curl -s https://api.github.com/repos/hansmi/prometheus-paperless-exporter/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') + if [[ ! -f /opt/${APP}_version.txt ]] || [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]]; then + msg_info "Stopping ${APP}" + systemctl stop prometheus-paperless-ngx-exporter + msg_ok "Stopped ${APP}" + + msg_info "Updating ${APP} to v${RELEASE}" + cd /opt + wget -q https://github.com/hansmi/prometheus-paperless-exporter/releases/download/v${RELEASE}/prometheus-paperless-exporter_${RELEASE}_linux_amd64.tar.gz + tar -xf prometheus-paperless-exporter_${RELEASE}_linux_amd64.tar.gz + cp -rf prometheus-paperless-exporter_${RELEASE}_linux_amd64/prometheus-paperless-exporter /usr/local/bin/ + rm -rf prometheus-paperless-exporter_${RELEASE}_linux_amd64/ prometheus-paperless-exporter_${RELEASE}_linux_amd64.tar.gz + echo "${RELEASE}" >/opt/${APP}_version.txt + msg_ok "Updated ${APP} to v${RELEASE}" + + msg_info "Starting ${APP}" + systemctl start prometheus-paperless-ngx-exporter + msg_ok "Started ${APP}" + msg_ok "Updated Successfully" + else + msg_ok "No update required. ${APP} is already at v${RELEASE}" + fi + exit +} + +start +build_container +description + +msg_ok "Completed Successfully!\n" +echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}" +echo -e "${INFO}${YW} Access it using the following URL:${CL}" +echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:8081/metrics${CL}" \ No newline at end of file diff --git a/install/prometheus-paperless-ngx-exporter-install.sh b/install/prometheus-paperless-ngx-exporter-install.sh new file mode 100755 index 00000000..4756d9aa --- /dev/null +++ b/install/prometheus-paperless-ngx-exporter-install.sh @@ -0,0 +1,64 @@ +#!/usr/bin/env bash + +# Copyright (c) 2021-2025 community-scripts ORG +# Author: Andy Grunwald (andygrunwald) +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE +# Source: https://github.com/hansmi/prometheus-paperless-exporter + +source /dev/stdin <<< "$FUNCTIONS_FILE_PATH" +color +verb_ip6 +catch_errors +setting_up_container +network_check +update_os + +msg_info "Installing Dependencies" +$STD apt-get install -y \ + curl \ + sudo \ + mc +msg_ok "Installed Dependencies" + +msg_info "Installing Prometheus Paperless NGX Exporter" +RELEASE=$(curl -s https://api.github.com/repos/hansmi/prometheus-paperless-exporter/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') +wget -q https://github.com/hansmi/prometheus-paperless-exporter/releases/download/v${RELEASE}/prometheus-paperless-exporter_${RELEASE}_linux_amd64.tar.gz +tar -xf prometheus-paperless-exporter_${RELEASE}_linux_amd64.tar.gz +mv prometheus-paperless-exporter_${RELEASE}_linux_amd64/prometheus-paperless-exporter /usr/local/bin/ +mkdir -p /etc/prometheus-paperless-ngx-exporter +cat < /etc/prometheus-paperless-ngx-exporter/paperless_auth_token_file +SECRET_AUTH_TOKEN +EOF +echo "${RELEASE}" >/opt/${APPLICATION}_version.txt +msg_ok "Installed Prometheus Paperless NGX Exporter" + +msg_info "Creating Service" +cat </etc/systemd/system/prometheus-paperless-ngx-exporter.service +[Unit] +Description=Prometheus Paperless NGX Exporter +Wants=network-online.target +After=network-online.target + +[Service] +User=root +Restart=always +Type=simple +ExecStart=/usr/local/bin/prometheus-paperless-exporter \ + --paperless_url==http://paperless.example.org \ + --paperless_auth_token_file=/etc/prometheus-paperless-ngx-exporter/paperless_auth_token_file +ExecReload=/bin/kill -HUP \$MAINPID + +[Install] +WantedBy=multi-user.target +EOF +systemctl enable -q --now prometheus-paperless-ngx-exporter +msg_ok "Created Service" + +motd_ssh +customize + +msg_info "Cleaning up" +$STD apt-get -y autoremove +$STD apt-get -y autoclean +rm -rf prometheus-paperless-exporter_${RELEASE}_linux_amd64/ prometheus-paperless-exporter_${RELEASE}_linux_amd64.tar.gz +msg_ok "Cleaned" diff --git a/json/prometheus-paperless-ngx-exporter.json b/json/prometheus-paperless-ngx-exporter.json new file mode 100644 index 00000000..0364500c --- /dev/null +++ b/json/prometheus-paperless-ngx-exporter.json @@ -0,0 +1,43 @@ +{ + "name": "Prometheus Paperless NGX Exporter", + "slug": "prometheus-paperless-ngx-exporter", + "categories": [ + 9 + ], + "date_created": "2025-02-07", + "type": "ct", + "updateable": true, + "privileged": false, + "interface_port": 3000, + "documentation": null, + "website": "https://github.com/hansmi/prometheus-paperless-exporter", + "logo": "https://raw.githubusercontent.com/paperless-ngx/paperless-ngx/main/resources/logo/web/svg/square.svg", + "description": "Prometheus metrics exporter for Paperless-NGX, a document management system transforming physical documents into a searchable online archive. The exporter relies on Paperless' REST API.", + "install_methods": [ + { + "type": "default", + "script": "ct/prometheus-alertmanager.sh", + "resources": { + "cpu": 1, + "ram": 256, + "hdd": 2, + "os": "debian", + "version": "12" + } + } + ], + "default_credentials": { + "username": null, + "password": null + }, + "notes": [ + { + "text": "Please adjust the Paperless URL in the systemd unit file: /etc/systemd/system/prometheus-paperless-ngx-exporter.service", + "type": "info" + }, + { + "text": "Please adjust the Paperless authentication token in the configuration file: /etc/prometheus-paperless-ngx-exporter/paperless_auth_token_file", + "type": "info" + } + ] +}