From f711a1e5af4a16a56b39e34a83d8b5bd292b2c33 Mon Sep 17 00:00:00 2001 From: CN-JS-HuiBai Date: Sun, 5 Apr 2026 23:21:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=90=8D=E7=A7=B0=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Prometheus/install_blackbox_exporter.sh | 55 ++++++++++++++----------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/Prometheus/install_blackbox_exporter.sh b/Prometheus/install_blackbox_exporter.sh index 2b4c2d0..dafe27c 100644 --- a/Prometheus/install_blackbox_exporter.sh +++ b/Prometheus/install_blackbox_exporter.sh @@ -85,33 +85,38 @@ if [ -t 0 ]; then read -rp "Your choice [1-5]: " CHOICE case $CHOICE in - 1) - read -rp "Enter ICMP targets (space separated, e.g. 8.8.8.8 1.1.1.1): " VAL - if [ -n "$VAL" ]; then - echo "- targets:" | sudo tee "$TARGETS_DIR/icmp.yml" > /dev/null - for t in $VAL; do echo " - $t" | sudo tee -a "$TARGETS_DIR/icmp.yml" > /dev/null; done - echo "Saved to: $TARGETS_DIR/icmp.yml" - fi - ;; - 2) - read -rp "Enter HTTP targets (space separated, e.g. https://google.com): " VAL - if [ -n "$VAL" ]; then - echo "- targets:" | sudo tee "$TARGETS_DIR/http.yml" > /dev/null - for t in $VAL; do echo " - $t" | sudo tee -a "$TARGETS_DIR/http.yml" > /dev/null; done - echo "Saved to: $TARGETS_DIR/http.yml" - fi - ;; - 3) - read -rp "Enter TCP targets (space separated, e.g. 1.1.1.1:443 8.8.8.8:53): " VAL - if [ -n "$VAL" ]; then - echo "- targets:" | sudo tee "$TARGETS_DIR/tcp.yml" > /dev/null - for t in $VAL; do echo " - $t" | sudo tee -a "$TARGETS_DIR/tcp.yml" > /dev/null; done - echo "Saved to: $TARGETS_DIR/tcp.yml" - fi + 1|2|3) + case $CHOICE in + 1) TYPE="icmp"; DESC="ICMP Ping"; EX="8.8.8.8";; + 2) TYPE="http"; DESC="HTTP Status"; EX="https://google.com";; + 3) TYPE="tcp"; DESC="TCP Connect"; EX="1.1.1.1:443";; + esac + + read -rp "Clear existing $DESC targets? [y/N]: " CLEAR_EXIST + [[ "$CLEAR_EXIST" =~ ^[Yy]$ ]] && sudo rm -f "$TARGETS_DIR/$TYPE.yml" + + while true; do + echo "--- Adding $DESC Object ---" + read -rp "Enter target (e.g. $EX, leave empty to stop): " T_VAL + [ -z "$T_VAL" ] && break + read -rp "Enter a descriptive name for this target: " T_NAME + + [ ! -f "$TARGETS_DIR/$TYPE.yml" ] && sudo touch "$TARGETS_DIR/$TYPE.yml" + sudo tee -a "$TARGETS_DIR/$TYPE.yml" > /dev/null </dev/null || echo "No targets configured yet." + echo "Current Target Configuration in $TARGETS_DIR:" + for f in "$TARGETS_DIR"/*.yml; do + [ -e "$f" ] || continue + echo "--- $(basename "$f") ---" + sudo cat "$f" + done ;; 5) break