mirror of
https://github.com/wickedyoda/public-setupfiles.git
synced 2026-11-16 13:31:56 -06:00
commit
1e25e36ce6
195 files changed
+152301
No files matched your search
@@ -0,0 +1,43 @@
|
||||
<<<<<<< HEAD
|
||||
# telegraf-setup-scripts
|
||||
|
||||
## Purpose
|
||||
This directory contains files related to **telegraf setup scripts**.
|
||||
|
||||
## Contents
|
||||
- `install-client.sh`
|
||||
- `update-telegraf-w-keys.sh`
|
||||
|
||||
## Usage
|
||||
- Review each script or configuration file before running
|
||||
- Some scripts may require **root or sudo**
|
||||
- Paths and variables may need adjustment for your environment
|
||||
|
||||
## Notes
|
||||
- This folder is part of the **public-setupfiles** repository
|
||||
- Files are provided as-is for reference or automation
|
||||
|
||||
## Safety
|
||||
Always back up data before running scripts that modify system state.
|
||||
=======
|
||||
# telegraf-setup-scripts
|
||||
|
||||
## Overview
|
||||
This directory is part of the **public-setupfiles** repository.
|
||||
It contains scripts, configuration files, or resources related to **telegraf-setup-scripts**.
|
||||
|
||||
## Usage
|
||||
- Review scripts before execution
|
||||
- Some files may require **root or sudo privileges**
|
||||
- Paths, variables, or credentials may need customization
|
||||
|
||||
## Logging & Output
|
||||
Scripts may generate logs or output files in the same directory or system locations.
|
||||
|
||||
## Safety Notes
|
||||
- Always back up important data before running scripts
|
||||
- Test in a non-production environment when possible
|
||||
- Use at your own risk
|
||||
|
||||
---
|
||||
>>>>>>> main
|
||||
@@ -0,0 +1,4 @@
|
||||
wget -q https://repos.influxdata.com/influxdata-archive_compat.key
|
||||
echo '393e8779c89ac8d958f81f942f9ad7fb82a25e133faddaf92e15b16e6ac9ce4c influxdata-archive_compat.key' | sha256sum -c && cat influxdata-archive_compat.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/influxdata-archive_compat.gpg > /dev/null
|
||||
echo 'deb [signed-by=/etc/apt/trusted.gpg.d/influxdata-archive_compat.gpg] https://repos.influxdata.com/debian stable main' | sudo tee /etc/apt/sources.list.d/influxdata.list
|
||||
sudo apt-get update && sudo apt-get install telegraf
|
||||
@@ -0,0 +1,81 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# === CONFIGURATION ===
|
||||
TOKEN_FILE="/run/secrets/${HOSTNAME}"
|
||||
if [[ -r "$TOKEN_FILE" ]]; then
|
||||
TOKEN="$(sudo cat "$TOKEN_FILE")"
|
||||
else
|
||||
echo "[!] Docker secret $TOKEN_FILE not found or unreadable." >&2
|
||||
read -rsp "Enter InfluxDB token: " TOKEN
|
||||
echo
|
||||
if [[ -z "$TOKEN" ]]; then
|
||||
echo "[✗] No token provided. Exiting." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
BUCKET="Home_Network"
|
||||
ORG="Home Network"
|
||||
URL="http://docker2:8086"
|
||||
DOCKER_SOCKET="/var/run/docker.sock"
|
||||
TELEGRAF_CONF="/etc/telegraf/telegraf.conf"
|
||||
BACKUP_PATH="/etc/telegraf/telegraf.conf.bak.$(date +%F-%H%M%S)"
|
||||
|
||||
echo "[+] Backing up current config to $BACKUP_PATH"
|
||||
sudo cp "$TELEGRAF_CONF" "$BACKUP_PATH"
|
||||
|
||||
echo "[+] Updating InfluxDB output block..."
|
||||
|
||||
if grep -q '^\[\[outputs.influxdb_v2\]\]' "$TELEGRAF_CONF"; then
|
||||
echo "[+] Found existing outputs.influxdb_v2 block. Updating values..."
|
||||
sudo sed -i '/^\[\[outputs.influxdb_v2\]\]/,/^\[/ s|^\( token = \).*|\1 "'"$TOKEN"'"|' "$TELEGRAF_CONF"
|
||||
sudo sed -i '/^\[\[outputs.influxdb_v2\]\]/,/^\[/ s|^\( urls = \).*|\1 ["'"$URL"'"]|' "$TELEGRAF_CONF"
|
||||
sudo sed -i '/^\[\[outputs.influxdb_v2\]\]/,/^\[/ s|^\( organization = \).*|\1 "'"$ORG"'"|' "$TELEGRAF_CONF"
|
||||
sudo sed -i '/^\[\[outputs.influxdb_v2\]\]/,/^\[/ s|^\( bucket = \).*|\1 "'"$BUCKET"'"|' "$TELEGRAF_CONF"
|
||||
else
|
||||
echo "[+] outputs.influxdb_v2 block not found. Appending to config..."
|
||||
cat <<EOF | sudo tee -a "$TELEGRAF_CONF" > /dev/null
|
||||
|
||||
[[outputs.influxdb_v2]]
|
||||
urls = ["$URL"]
|
||||
token = "$TOKEN"
|
||||
organization = "$ORG"
|
||||
bucket = "$BUCKET"
|
||||
EOF
|
||||
fi
|
||||
|
||||
echo "[+] Checking for Docker plugin..."
|
||||
if ! grep -q '^\s*\[\[inputs.docker\]\]' "$TELEGRAF_CONF"; then
|
||||
cat <<EOF | sudo tee -a "$TELEGRAF_CONF" > /dev/null
|
||||
|
||||
[[inputs.docker]]
|
||||
endpoint = "unix://$DOCKER_SOCKET"
|
||||
gather_services = false
|
||||
|
||||
EOF
|
||||
echo "[+] Docker plugin added."
|
||||
else
|
||||
echo "[+] Docker plugin already present. Skipping."
|
||||
fi
|
||||
|
||||
echo "[+] Validating config..."
|
||||
if sudo telegraf --config "$TELEGRAF_CONF" --config-directory /etc/telegraf/telegraf.d --test > /dev/null; then
|
||||
echo "[✓] Config is valid."
|
||||
else
|
||||
echo "[✗] Config test failed. Check output and fix issues." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[+] Restarting Telegraf service..."
|
||||
sudo systemctl restart telegraf
|
||||
|
||||
sleep 2
|
||||
if systemctl is-active --quiet telegraf; then
|
||||
echo "[✓] Telegraf is now running."
|
||||
else
|
||||
echo "[✗] Telegraf failed to start. Check logs with: journalctl -xeu telegraf.service" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[✓] Setup complete on $(hostname)."
|
||||
Reference in new issue
Block a user