From 57ddeab5207f6a44b81a9c7411d1ae3efcb6db50 Mon Sep 17 00:00:00 2001 From: /rootzoll Date: Sun, 6 Oct 2024 21:35:21 +0200 Subject: [PATCH] #2624 Add Telegraf to SSH menus (#4788) * #2624 add telegraf to SSH SETTINGS menu * #2624 add telegraf to main SSH menu --- CHANGES.md | 2 +- home.admin/00mainMenu.sh | 6 + home.admin/00settingsMenuBasics.sh | 18 + home.admin/_provision_.sh | 2 +- .../raspiblitz.conf-snippet-for-telegraf | 2 +- home.admin/config.scripts/bonus.telegraf.sh | 354 +++++++++++------- 6 files changed, 248 insertions(+), 136 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 5a05d80ce..34d296f83 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,7 @@ ## What's new in Version 1.11.3 of RaspiBlitz? - New: Tailscale (SSH menu > SETTINGS) [details](https://en.wikipedia.org/wiki/Tailscale) +- New: Telegraf Metrics for InfluxDB/Grafana (SSH menu > SETTINGS) [details](https://github.com/raspiblitz/raspiblitz/tree/dev/home.admin/assets/telegraf/README.md) - New: Connect Zeus to CLN via CLNrest (using the clnrest plugin and runes) - Update: Core Lightning v24.08.1 [details](https://github.com/ElementsProject/lightning/releases/tag/v24.08.1) - Update: Thunderhub v0.13.31 [details](https://github.com/apotdevin/thunderhub/releases/tag/v0.13.31) @@ -10,7 +11,6 @@ - Update: Balance of Satoshis 19.3.4 (bos) [details](https://github.com/alexbosworth/balanceofsatoshis/blob/v19.3.4/CHANGELOG.md#1934) - Update: Labelbase 2.2.2 [details](https://x.com/labelbase_space) - Update: LNbits 0.12.11 [details](https://github.com/lnbits/lnbits/releases/tag/0.12.11) -- Update: Telegraf Metrics for InfluxDB/Grafana [details](https://github.com/raspiblitz/raspiblitz/tree/dev/home.admin/assets/telegraf/README.md) - Update: RTL v0.15.2 [details](https://github.com/Ride-The-Lightning/RTL/releases/tag/v0.15.2) - Update: Jam (JoinMarket Web UI) v0.3.0 [details](https://github.com/joinmarket-webui/jam/releases/tag/v0.3.0) - Update: CLBOSS 0.13.3 [details](https://github.com/ZmnSCPxj/clboss/releases/tag/v0.13.3) diff --git a/home.admin/00mainMenu.sh b/home.admin/00mainMenu.sh index e9568f32e..1b046a092 100755 --- a/home.admin/00mainMenu.sh +++ b/home.admin/00mainMenu.sh @@ -174,6 +174,9 @@ fi if [ "${tailscale}" == "on" ]; then OPTIONS+=(TAILSCALE "Tailscale VPN") fi +if [ "${telegraf}" == "on" ]; then + OPTIONS+=(TELEGRAF "Telegraf InfluxDB/Grafana Metrics") +fi # dont offer to switch to "testnet view for now" - so no wswitch back to mainnet needed @@ -341,6 +344,9 @@ case $CHOICE in TAILSCALE) sudo /home/admin/config.scripts/internet.tailscale.sh menu ;; + TELEGRAF) + /home/admin/config.scripts/bonus.telegraf.sh menu + ;; FINTS) sudo /home/admin/config.scripts/bonus.fints.sh menu ;; diff --git a/home.admin/00settingsMenuBasics.sh b/home.admin/00settingsMenuBasics.sh index 972841164..a5ae0b27e 100755 --- a/home.admin/00settingsMenuBasics.sh +++ b/home.admin/00settingsMenuBasics.sh @@ -17,6 +17,7 @@ if [ ${#clAutoUnlock} -eq 0 ]; then clAutoUnlock="off"; fi if [ ${#clWatchtowerClient} -eq 0 ]; then clWatchtowerClient="off"; fi if [ ${#blitzapi} -eq 0 ]; then blitzapi="off"; fi if [ ${#tailscale} -eq 0 ]; then tailscale="off"; fi +if [ ${#telegraf} -eq 0 ]; then telegraf="off"; fi # detect if LND auto-unlock is active source <(/home/admin/config.scripts/lnd.autounlock.sh status) @@ -114,6 +115,8 @@ OPTIONS+=(t 'Run behind Tor' ${runBehindTor}) OPTIONS+=(z 'ZeroTier' ${zerotierSwitch}) OPTIONS+=(l 'Tailscale VPN' ${tailscale}) +OPTIONS+=(g 'Telegraf InfluxDB/Grafana Metrics' ${telegraf}) + if [ ${#runBehindTor} -eq 0 ] || [ "${runBehindTor}" = "off" ]; then OPTIONS+=(y ${dynDomainMenu} ${domainValue}) fi @@ -337,6 +340,21 @@ else echo "tailscale setting unchanged." fi +# Telegraf process choice +choice="off"; check=$(echo "${CHOICES}" | grep -c "g") +if [ ${check} -eq 1 ]; then choice="on"; fi +if [ "${telegraf}" != "${choice}" ]; then + echo "telegraf setting changed .." + anychange=1 + error="" + sudo -u admin /home/admin/config.scripts/bonus.telegraf.sh ${choice} + if [ "${choice}" = "on" ]; then + sudo -u admin /home/admin/config.scripts/bonus.telegraf.sh menu + fi +else + echo "telegraf setting unchanged." +fi + # LND choice choice="off"; check=$(echo "${CHOICES}" | grep -c "m") if [ ${check} -eq 1 ]; then choice="on"; fi diff --git a/home.admin/_provision_.sh b/home.admin/_provision_.sh index 65154f4ba..c7671705c 100755 --- a/home.admin/_provision_.sh +++ b/home.admin/_provision_.sh @@ -735,7 +735,7 @@ else fi # Telegraf -if [ "${telegrafMonitoring}" = "on" ]; then +if [ "${telegraf}" = "on" ]; then echo "Provisioning Telegraf - run config script" >> ${logFile} /home/admin/_cache.sh set message "Setup Telegraf" sudo -u admin /home/admin/config.scripts/bonus.telegraf.sh on >> ${logFile} 2>&1 diff --git a/home.admin/assets/telegraf/raspiblitz.conf-snippet-for-telegraf b/home.admin/assets/telegraf/raspiblitz.conf-snippet-for-telegraf index 653d95181..a38ed4539 100644 --- a/home.admin/assets/telegraf/raspiblitz.conf-snippet-for-telegraf +++ b/home.admin/assets/telegraf/raspiblitz.conf-snippet-for-telegraf @@ -5,7 +5,7 @@ # all telegraf switches and configuration variables -telegrafMonitoring=on +telegraf=on telegrafInfluxUrl='http://192.168.2.46:8086' telegrafInfluxDatabase='telegraf' telegrafInfluxUsername='telegraf' diff --git a/home.admin/config.scripts/bonus.telegraf.sh b/home.admin/config.scripts/bonus.telegraf.sh index 5ae883d9f..ed02886ab 100644 --- a/home.admin/config.scripts/bonus.telegraf.sh +++ b/home.admin/config.scripts/bonus.telegraf.sh @@ -10,7 +10,8 @@ if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then echo "# config script to switch the telegraf metric collection" echo "# detailed setup info: github.com/raspiblitz/raspiblitz/tree/dev/home.admin/assets/telegraf" echo "# bonus.telegraf.sh status ---> get status of telegraf service" - echo "# bonus.telegraf.sh on ---> install & config" + echo "# bonus.telegraf.sh on ---> install" + echo "# bonus.telegraf.sh menu ---> info & config" echo "# bonus.telegraf.sh off ---> uninstall & reset config" exit 1 fi @@ -21,20 +22,48 @@ source /mnt/hdd/raspiblitz.conf # this variables is used repeatedly in this script resources_dir=/home/admin/assets/telegraf/etc-telegraf +# source and target dir for copy operation +telegraf_source_dir=${resources_dir} +telegraf_target_dir=/etc/telegraf + +# full path to telegraf config file for sed-replace operation +telegraf_conf_file=${telegraf_target_dir}/telegraf.conf + + ############################### # give status if [ "$1" = "status" ]; then echo "##### STATUS TELEGRAF SERVICE" - # check if "telegrafMonitoring" is enabled ("1"|"on") in raspiblitz.conf - if [ "${telegrafMonitoring}" = "1" ] || [ "${telegrafMonitoring}" = "on" ]; then + # check if "telegraf" is enabled ("1"|"on") in raspiblitz.conf + if [ "${telegraf}" = "1" ] || [ "${telegraf}" = "on" ]; then echo "configured=1" else echo "configured=0" fi - serviceInstalled=$(sudo systemctl status telegraf --no-page 2>/dev/null | grep -c "telegraf.service - The plugin-driven") + # check if config data in raspiblitz.conf is available + configMissing=0 + if [ ${#telegrafInfluxUrl} -eq 0 ]; then + echo "# Missing telegrafInfluxUrl in raspiblitz.conf" + configMissing=1 + fi + if [ ${#telegrafInfluxDatabase} -eq 0 ]; then + echo "# Missing telegrafInfluxDatabase in raspiblitz.conf" + configMissing=1 + fi + if [ ${#telegrafInfluxUsername} -eq 0 ]; then + echo "# Missing telegrafInfluxUsername in raspiblitz.conf" + configMissing=1 + fi + if [ ${#telegrafInfluxPassword} -eq 0 ]; then + echo "# Missing telegrafInfluxPassword in raspiblitz.conf" + configMissing=1 + fi + echo "configMissing=${configMissing}" + + serviceInstalled=$(sudo systemctl status telegraf --no-page 2>/dev/null | grep -q 'Loaded: loaded' && echo 1 || echo 0) echo "serviceInstalled=${serviceInstalled}" if [ ${serviceInstalled} -eq 0 ]; then echo "infoMessage='Telegraf service not installed'" @@ -48,6 +77,13 @@ if [ "$1" = "status" ]; then echo "infoMessage='Not running - check: sudo journalctl -u telegraf'" fi + errorReport="" + countReportError=$(sudo journalctl -u telegraf.service -n 5 | grep -c "Failed to write metric") + if [ ${countReportError} -gt 0 ]; then + errorReport='failed to write metric to server' + fi + echo "errorReport='${errorReport}'" + exit 0 fi @@ -70,6 +106,46 @@ function validate_url() { fi } +function config_telegraf() { + + echo "# *** telegraf installation: replace influxDB url and creds" + sudo systemctl stop telegraf.service 2>/dev/null + + # make sure that raspiblitz.conf has the telegraf-variables properly set + # telegrafInfluxUrl + # telegrafInfluxDatabase + # telegrafInfluxUsername + # telegrafInfluxPassword + source /mnt/hdd/raspiblitz.conf + + echo "# *** telegraf installation: telegrafInfluxUrl = '${telegrafInfluxUrl}'" + # due to the occurrence of '/' in the ${telegrafInfluxUrl} we need to switch to '#' as the sed-separator + sudo sed -i "s#^urls = .*#urls = \[\"${telegrafInfluxUrl}\"\]#g" ${telegraf_conf_file} + # + # the other replacements work with the std separator '/' + # + # CAUTION: make sure that *none* of the following variables (especially "password") contains a '/' + # this would break the sed-replacement + + echo "*** telegraf installation: telegrafInfluxDatabase = '${telegrafInfluxDatabase}'" + sudo sed -i "s/^database = .*/database = \"${telegrafInfluxDatabase}\"/g" ${telegraf_conf_file} + + echo "*** telegraf installation: telegrafInfluxUsername = '${telegrafInfluxUsername}'" + sudo sed -i "s/^username = .*/username = \"${telegrafInfluxUsername}\"/g" ${telegraf_conf_file} + + echo "*** telegraf installation: telegrafInfluxPassword = '${telegrafInfluxPassword}'" + sudo sed -i "s/^password = .*/password = \"${telegrafInfluxPassword}\"/g" ${telegraf_conf_file} + + + echo "*** telegraf installation: restart telegraf service with updated config files" + # restart telegraf service + sudo systemctl start telegraf.service + # ...and push some status into the logfile + sleep 2 + sudo systemctl status telegraf.service --no-page 2>/dev/null + +} + ############################### # switch on if [ "$1" = "1" ] || [ "$1" = "on" ]; then @@ -77,30 +153,108 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then echo "*** INSTALL TELEGRAF ***" # check installed by looking for service - serviceInstalled=$(sudo systemctl status telegraf --no-page 2>/dev/null | grep -c "telegraf.service - The plugin-driven") + source <(/home/admin/config.scripts/bonus.telegraf.sh status) if [ ${serviceInstalled} -eq 1 ]; then echo "# Telegraf service is installed." echo "# If you want to reset config and reinstall, please switch off first." exit 0 fi - # check if config data in raspiblitz.conf is available - configMissing=0 - if [ ${#telegrafInfluxUrl} -eq 0 ]; then - echo "# Missing telegrafInfluxUrl in raspiblitz.conf" - configMissing=1 + echo "*** telegraf installation: apt-get part" + # get the repository public key for apt-get + curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add - + DISTRIB_ID=$(lsb_release -c -s) + # + # changed according suggestion from @frennkie in #1501 + echo "deb https://repos.influxdata.com/debian ${DISTRIB_ID} stable" | sudo tee -a /etc/apt/sources.list.d/influxdb.list >/dev/null + # + # as the key is untrusted, this is a dirty fix + sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys D8FF8E1F7DF8B07E + sudo apt-get update + sudo apt-get install -y telegraf || exit 1 + + + echo "*** telegraf installation: usermod part" + # enable telegraf user to call "/opt/vc/bin/vcgencmd" for frequency and temperatures measurements + sudo usermod -aG video telegraf + # + # enable telegraf as admin for lnd + sudo usermod telegraf -a -G lndadmin + # + # add telegraf to sudoers (for later application with smartmontools) + sudo usermod telegraf -a -G sudo + + # stop telegraf service + sudo systemctl stop telegraf.service 2>/dev/null + + echo "*** telegraf installation: copying telegraf config templates" + # copy custom "telegraf.conf" template to the telegraf target dir + # the telegraf inputs part goes into telegraf.d subdir + # this split into "telegraf.conf" and "telegraf.d/telegraf_inputs.conf" is necessary + # as the the [[inputs.***]] part contains lines with the keywords + # "urls", "database", "username" "password" + # so the sed-replacement-part would get confused + # + # Note: the apt-get install should have already created the path /etc/telegraf and /etc/telegraf/telegraf.d + # + sudo cp -v ${telegraf_source_dir}/telegraf.conf ${telegraf_target_dir}/telegraf.conf + sudo cp -v ${telegraf_source_dir}/telegraf.d/telegraf_inputs.conf ${telegraf_target_dir}/telegraf.d/telegraf_inputs.conf + # + # copy shell script for service uptime metrics + sudo cp -v ${telegraf_source_dir}/getserviceuptime.sh ${telegraf_target_dir}/getserviceuptime.sh + sudo chmod 755 ${telegraf_target_dir}/getserviceuptime.sh + # + # copy shell script for IP address tracking + sudo cp -v ${telegraf_source_dir}/getraspiblitzipinfo.sh ${telegraf_target_dir}/getraspiblitzipinfo.sh + sudo chmod 755 ${telegraf_target_dir}/getraspiblitzipinfo.sh + + echo "*** telegraf installation: set 'telegraf=on' in config file 'raspiblitz.conf'" + /home/admin/config.scripts/blitz.conf.sh set telegraf "on" + + echo "*** install telegraf done ***" + + # run config if data is set in raspiblitz.conf + source <(/home/admin/config.scripts/bonus.telegraf.sh status) + if [ ${configMissing} -eq 0 ]; then + config_telegraf + else + echo "# missing config data - run 'bonus.telegraf.sh menu' to enter" fi - if [ ${#telegrafInfluxDatabase} -eq 0 ]; then - echo "# Missing telegrafInfluxDatabase in raspiblitz.conf" - configMissing=1 - fi - if [ ${#telegrafInfluxUsername} -eq 0 ]; then - echo "# Missing telegrafInfluxUsername in raspiblitz.conf" - configMissing=1 - fi - if [ ${#telegrafInfluxPassword} -eq 0 ]; then - echo "# Missing telegrafInfluxPassword in raspiblitz.conf" - configMissing=1 + + exit 0 +fi + +############################### +# switch off +if [ "$1" = "0" ] || [ "$1" = "off" ]; then + echo "*** REMOVE TELEGRAF ***" + + # let apt-get remove the package + sudo apt-get remove -y telegraf + + echo "*** telegraf switch off and remove config ***" + /home/admin/config.scripts/blitz.conf.sh set telegraf "off" + /home/admin/config.scripts/blitz.conf.sh delete telegrafInfluxUrl + /home/admin/config.scripts/blitz.conf.sh delete telegrafInfluxDatabase + /home/admin/config.scripts/blitz.conf.sh delete telegrafInfluxUsername + /home/admin/config.scripts/blitz.conf.sh delete telegrafInfluxPassword + + echo "*** remove telegraf done ***" + + exit 0 +fi + +############################### +# menu +if [ "$1" = "menu" ]; then + + echo "# get status" + source <(/home/admin/config.scripts/bonus.telegraf.sh status) + + # check if telegraf is installed + if [ ${serviceInstalled} -eq 0 ]; then + echo "# telegraf is not installed - no menu" + exit 1 fi # enter config if missing (first init) @@ -153,6 +307,11 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then whiptail --msgbox "Input cannot be empty. Please enter a valid database name." 8 78 continue fi + # check that database name does not contain a '/' or a '"' + if [[ $telegrafInfluxDatabase == *"/"* ]] || [[ $telegrafInfluxDatabase == *"\""* ]]; then + whiptail --msgbox "Database name cannot contain a '/'. Please enter a valid database name." 8 78 + continue + fi break done @@ -168,6 +327,11 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then whiptail --msgbox "Input cannot be empty. Please enter a valid username." 8 78 continue fi + # check that username does not contain a '/' or a '"' + if [[ $telegrafInfluxUsername == *"/"* ]] || [[ $telegrafInfluxUsername == *"\""* ]]; then + whiptail --msgbox "Username cannot contain a '/' or a '\"'. Please enter a valid username." 8 78 + continue + fi break done @@ -183,6 +347,12 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then whiptail --msgbox "Input cannot be empty. Please enter a valid password." 8 78 continue fi + # check that password does not contain a '/' or a '"' + if [[ $telegrafInfluxPassword == *"/"* ]] || [[ $telegrafInfluxPassword == *"\""* ]]; then + whiptail --msgbox "Password cannot contain a '/' or a '\"'. Please enter a valid password." 8 78 + continue + fi + break done @@ -191,123 +361,41 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then /home/admin/config.scripts/blitz.conf.sh set telegrafInfluxDatabase "${telegrafInfluxDatabase}" /home/admin/config.scripts/blitz.conf.sh set telegrafInfluxUsername "${telegrafInfluxUsername}" /home/admin/config.scripts/blitz.conf.sh set telegrafInfluxPassword "${telegrafInfluxPassword}" + + # run the config function + config_telegraf + + echo "# config data saved - telegraf starting up ... wait 10sec" + sleep 10 fi - # source and target dir for copy operation - telegraf_source_dir=${resources_dir} - telegraf_target_dir=/etc/telegraf - - # full path to telegraf config file for sed-replace operation - telegraf_conf_file=${telegraf_target_dir}/telegraf.conf - - echo "*** telegraf installation: apt-get part" - # get the repository public key for apt-get - curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add - - DISTRIB_ID=$(lsb_release -c -s) - # - # changed according suggestion from @frennkie in #1501 - echo "deb https://repos.influxdata.com/debian ${DISTRIB_ID} stable" | sudo tee -a /etc/apt/sources.list.d/influxdb.list >/dev/null - # - # as the key is untrusted, this is a dirty fix - sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys D8FF8E1F7DF8B07E - sudo apt-get update - sudo apt-get install -y telegraf - - echo "*** telegraf installation: usermod part" - # enable telegraf user to call "/opt/vc/bin/vcgencmd" for frequency and temperatures measurements - sudo usermod -aG video telegraf - # - # enable telegraf as admin for lnd - sudo usermod telegraf -a -G lndadmin - # - # add telegraf to sudoers (for later application with smartmontools) - sudo usermod telegraf -a -G sudo - - # stop telegraf service - sudo systemctl stop telegraf.service - - echo "*** telegraf installation: copying telegraf config templates" - # copy custom "telegraf.conf" template to the telegraf target dir - # the telegraf inputs part goes into telegraf.d subdir - # this split into "telegraf.conf" and "telegraf.d/telegraf_inputs.conf" is necessary - # as the the [[inputs.***]] part contains lines with the keywords - # "urls", "database", "username" "password" - # so the sed-replacement-part would get confused - # - # Note: the apt-get install should have already created the path /etc/telegraf and /etc/telegraf/telegraf.d - # - sudo cp -v ${telegraf_source_dir}/telegraf.conf ${telegraf_target_dir}/telegraf.conf - sudo cp -v ${telegraf_source_dir}/telegraf.d/telegraf_inputs.conf ${telegraf_target_dir}/telegraf.d/telegraf_inputs.conf - # - # copy shell script for service uptime metrics - sudo cp -v ${telegraf_source_dir}/getserviceuptime.sh ${telegraf_target_dir}/getserviceuptime.sh - sudo chmod 755 ${telegraf_target_dir}/getserviceuptime.sh - # - # copy shell script for IP address tracking - sudo cp -v ${telegraf_source_dir}/getraspiblitzipinfo.sh ${telegraf_target_dir}/getraspiblitzipinfo.sh - sudo chmod 755 ${telegraf_target_dir}/getraspiblitzipinfo.sh - - echo "*** telegraf installation: replace influxDB url and creds" - # here comes the sed-replace-part - # - # make sure that raspiblitz.conf has the telegraf-variables properly set - # telegrafInfluxUrl - # telegrafInfluxDatabase - # telegrafInfluxUsername - # telegrafInfluxPassword - # - echo "*** telegraf installation: telegrafInfluxUrl = '${telegrafInfluxUrl}'" - # due to the occurrence of '/' in the ${telegrafInfluxUrl} we need to switch to '#' as the sed-separator - sudo sed -i "s#^urls = .*#urls = \[\"${telegrafInfluxUrl}\"\]#g" ${telegraf_conf_file} - # - # the other replacements work with the std separator '/' - # - # CAUTION: make sure that *none* of the following variables (especially "password") contains a '/' - # this would break the sed-replacement - # - echo "*** telegraf installation: telegrafInfluxDatabase = '${telegrafInfluxDatabase}'" - sudo sed -i "s/^database = .*/database = \"${telegrafInfluxDatabase}\"/g" ${telegraf_conf_file} - # - echo "*** telegraf installation: telegrafInfluxUsername = '${telegrafInfluxUsername}'" - sudo sed -i "s/^username = .*/username = \"${telegrafInfluxUsername}\"/g" ${telegraf_conf_file} - # - echo "*** telegraf installation: telegrafInfluxPassword = '${telegrafInfluxPassword}'" - sudo sed -i "s/^password = .*/password = \"${telegrafInfluxPassword}\"/g" ${telegraf_conf_file} - - - echo "*** telegraf installation: restart telegraf service with updated config files" - # restart telegraf service - sudo systemctl start telegraf.service - # ...and push some status into the logfile + echo "# ... " sleep 2 - sudo systemctl status telegraf.service --no-page 2>/dev/null + source <(/home/admin/config.scripts/bonus.telegraf.sh status) + if [ ${serviceRunning} -eq 0 ]; then + echo "# telegraf is not running" + sleep 3 + exit 1 + fi - echo "*** telegraf installation: set 'telegrafMonitoring=on' in config file 'raspiblitz.conf'" - /home/admin/config.scripts/blitz.conf.sh set telegrafMonitoring "on" - - echo "*** install telegraf done ***" - - exit 0 -fi - - -############################### -# switch off -if [ "$1" = "0" ] || [ "$1" = "off" ]; then - echo "*** REMOVE TELEGRAF ***" - - # let apt-get remove the package - sudo apt-get remove -y telegraf - - echo "*** telegraf switch off and remove config ***" - /home/admin/config.scripts/blitz.conf.sh set telegrafMonitoring "off" - /home/admin/config.scripts/blitz.conf.sh delete telegrafInfluxUrl - /home/admin/config.scripts/blitz.conf.sh delete telegrafInfluxDatabase - /home/admin/config.scripts/blitz.conf.sh delete telegrafInfluxUsername - /home/admin/config.scripts/blitz.conf.sh delete telegrafInfluxPassword - - echo "*** remove telegraf done ***" + # whiptail info with option to reset config + if [ ${#errorReport} -gt 0 ]; then + infoText="The Telegraf service is running but reports an error:\n${errorReport}\n\nCheck error logs for details:\nsudo journalctl -u telegraf.service -n 20\n\nUse RESET-CONFIG to re-enter the InfluxDB credentials." + else + infoText="Telegraf is running.\n\nInfluxDB: ${telegrafInfluxUrl}\nDatabase: ${telegrafInfluxDatabase}\nUsername: ${telegrafInfluxUsername}\n\nCheck logs for details:\nsudo journalctl -u telegraf.service -n 20" + fi + whiptail --title " Telegraf " --yes-button "OK" --no-button "RESET-CONFIG" --yesno "${infoText}" 0 0 + if [ $? -eq 1 ]; then + sudo systemctl stop telegraf.service 2>/dev/null + /home/admin/config.scripts/blitz.conf.sh delete telegrafInfluxUrl + /home/admin/config.scripts/blitz.conf.sh delete telegrafInfluxDatabase + /home/admin/config.scripts/blitz.conf.sh delete telegrafInfluxUsername + /home/admin/config.scripts/blitz.conf.sh delete telegrafInfluxPassword + echo "# config reset" + sleep 3 + /home/admin/config.scripts/bonus.telegraf.sh menu + fi exit 0 fi