mirror of
https://github.com/wickedyoda/public-setupfiles.git
synced 2026-11-16 13:31:56 -06:00
Reorganize repository structure and refresh READMEs
This commit is contained in:
1 parent
2270530d9e
commit
a8b7ccbf2a
170 files changed
+616
-1391
No files matched your search
@@ -0,0 +1,17 @@
|
||||
# monitoring_and_remote_admin
|
||||
|
||||
## Overview
|
||||
This category groups monitoring, SNMP, Telegraf, Observium, Docker monitoring helpers, and remote-command execution tools.
|
||||
|
||||
## Contents
|
||||
- `docker_stuff`
|
||||
- `observium`
|
||||
- `snmp`
|
||||
- `system_command_run`
|
||||
- `telegraf-setup-scripts`
|
||||
|
||||
## Usage
|
||||
Use these folders when configuring monitoring agents, exposing metrics, or pushing commands across machines.
|
||||
|
||||
## Notes
|
||||
Several scripts here interact with running services or remote systems and may require elevated privileges.
|
||||
@@ -0,0 +1,13 @@
|
||||
# docker_stuff
|
||||
|
||||
## Overview
|
||||
Docker-related helper scripts for monitoring and service integration tasks.
|
||||
|
||||
## Contents
|
||||
- `uptime_kurma_fix`
|
||||
|
||||
## Usage
|
||||
Use the subfolders here for targeted Docker maintenance or monitoring setup tasks.
|
||||
|
||||
## Notes
|
||||
These scripts can change Docker daemon behavior and should be applied intentionally.
|
||||
@@ -0,0 +1,13 @@
|
||||
# uptime_kurma_fix
|
||||
|
||||
## Overview
|
||||
Utility script for enabling the Docker remote API so Uptime Kuma can check Docker status.
|
||||
|
||||
## Contents
|
||||
- `uptime_docker-fix.sh`
|
||||
|
||||
## Usage
|
||||
Run the script as root on the target host and optionally restrict access with the `--allow-ip` flag.
|
||||
|
||||
## Notes
|
||||
The script modifies the Docker systemd override and can expose the Docker API over TCP, so firewall controls matter.
|
||||
+199
@@ -0,0 +1,199 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# setup-docker-remote-api.sh
|
||||
# Enables Docker remote API on tcp://0.0.0.0:2375 using a systemd override.
|
||||
# Optional: lock port 2375 down to a single source IP.
|
||||
#
|
||||
# Usage:
|
||||
# sudo bash setup-docker-remote-api.sh
|
||||
# sudo bash setup-docker-remote-api.sh --allow-ip 10.0.84.50
|
||||
#
|
||||
# Notes:
|
||||
# - This exposes the Docker API over unencrypted TCP.
|
||||
# - Anyone who can reach port 2375 can effectively control Docker on the host.
|
||||
# - Strongly recommended: use --allow-ip with your Uptime Kuma server IP.
|
||||
|
||||
ALLOW_IP=""
|
||||
OVERRIDE_DIR="/etc/systemd/system/docker.service.d"
|
||||
OVERRIDE_FILE="${OVERRIDE_DIR}/override.conf"
|
||||
BACKUP_SUFFIX="$(date +%Y%m%d-%H%M%S)"
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage:
|
||||
sudo bash $0 [--allow-ip IP]
|
||||
|
||||
Options:
|
||||
--allow-ip IP Allow only this source IP to access TCP 2375 using iptables.
|
||||
-h, --help Show this help.
|
||||
|
||||
Examples:
|
||||
sudo bash $0
|
||||
sudo bash $0 --allow-ip 10.0.84.50
|
||||
EOF
|
||||
}
|
||||
|
||||
log() {
|
||||
echo "[INFO] $*"
|
||||
}
|
||||
|
||||
warn() {
|
||||
echo "[WARN] $*" >&2
|
||||
}
|
||||
|
||||
err() {
|
||||
echo "[ERROR] $*" >&2
|
||||
}
|
||||
|
||||
require_root() {
|
||||
if [[ "${EUID}" -ne 0 ]]; then
|
||||
err "Run this script as root or with sudo."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
parse_args() {
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--allow-ip)
|
||||
shift
|
||||
[[ $# -gt 0 ]] || { err "Missing value for --allow-ip"; exit 1; }
|
||||
ALLOW_IP="$1"
|
||||
;;
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
err "Unknown argument: $1"
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
||||
check_prereqs() {
|
||||
command -v systemctl >/dev/null 2>&1 || { err "systemctl not found."; exit 1; }
|
||||
command -v docker >/dev/null 2>&1 || { err "docker not found."; exit 1; }
|
||||
command -v ss >/dev/null 2>&1 || { err "ss not found."; exit 1; }
|
||||
command -v curl >/dev/null 2>&1 || { err "curl not found."; exit 1; }
|
||||
|
||||
if ! systemctl list-unit-files | grep -q '^docker.service'; then
|
||||
err "docker.service not found."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
backup_existing_override() {
|
||||
mkdir -p "${OVERRIDE_DIR}"
|
||||
|
||||
if [[ -f "${OVERRIDE_FILE}" ]]; then
|
||||
cp -a "${OVERRIDE_FILE}" "${OVERRIDE_FILE}.bak.${BACKUP_SUFFIX}"
|
||||
log "Backed up existing override to ${OVERRIDE_FILE}.bak.${BACKUP_SUFFIX}"
|
||||
fi
|
||||
}
|
||||
|
||||
write_override() {
|
||||
cat > "${OVERRIDE_FILE}" <<'EOF'
|
||||
[Service]
|
||||
ExecStart=
|
||||
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375 --containerd=/run/containerd/containerd.sock
|
||||
EOF
|
||||
|
||||
log "Wrote Docker systemd override: ${OVERRIDE_FILE}"
|
||||
}
|
||||
|
||||
reload_and_restart() {
|
||||
log "Reloading systemd..."
|
||||
systemctl daemon-reload
|
||||
|
||||
log "Restarting Docker..."
|
||||
systemctl restart docker
|
||||
|
||||
log "Checking Docker service status..."
|
||||
systemctl --no-pager --full status docker.service || true
|
||||
}
|
||||
|
||||
verify_listener() {
|
||||
log "Verifying Docker is listening on TCP 2375..."
|
||||
if ss -lntp | grep -q ':2375'; then
|
||||
ss -lntp | grep ':2375' || true
|
||||
log "Docker is listening on port 2375."
|
||||
else
|
||||
err "Docker is not listening on port 2375."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
verify_local_api() {
|
||||
log "Verifying local Docker API response..."
|
||||
if curl -fsS http://127.0.0.1:2375/version >/dev/null; then
|
||||
curl -fsS http://127.0.0.1:2375/version
|
||||
echo
|
||||
log "Local Docker API test succeeded."
|
||||
else
|
||||
err "Local Docker API test failed."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
configure_firewall() {
|
||||
if [[ -z "${ALLOW_IP}" ]]; then
|
||||
warn "No --allow-ip provided. Port 2375 will remain reachable by anything that can route to this host."
|
||||
return
|
||||
fi
|
||||
|
||||
command -v iptables >/dev/null 2>&1 || {
|
||||
warn "iptables not found. Skipping firewall rules."
|
||||
return
|
||||
}
|
||||
|
||||
log "Applying iptables rules to allow only ${ALLOW_IP} to TCP 2375..."
|
||||
|
||||
# Avoid duplicate rules
|
||||
iptables -C INPUT -p tcp -s "${ALLOW_IP}" --dport 2375 -j ACCEPT 2>/dev/null || \
|
||||
iptables -A INPUT -p tcp -s "${ALLOW_IP}" --dport 2375 -j ACCEPT
|
||||
|
||||
iptables -C INPUT -p tcp --dport 2375 -j DROP 2>/dev/null || \
|
||||
iptables -A INPUT -p tcp --dport 2375 -j DROP
|
||||
|
||||
log "iptables rules applied."
|
||||
warn "Make sure your firewall rules are saved persistently on this host."
|
||||
}
|
||||
|
||||
show_summary() {
|
||||
echo
|
||||
echo "Done."
|
||||
echo
|
||||
echo "Docker remote API should now be available at:"
|
||||
echo " tcp://$(hostname -I | awk '{print $1}'):2375"
|
||||
echo
|
||||
echo "Use this in Uptime Kuma:"
|
||||
echo " tcp://HOST_IP:2375"
|
||||
echo
|
||||
if [[ -n "${ALLOW_IP}" ]]; then
|
||||
echo "Access restricted to source IP:"
|
||||
echo " ${ALLOW_IP}"
|
||||
else
|
||||
echo "No IP restriction was applied."
|
||||
fi
|
||||
echo
|
||||
}
|
||||
|
||||
main() {
|
||||
require_root
|
||||
parse_args "$@"
|
||||
check_prereqs
|
||||
backup_existing_override
|
||||
write_override
|
||||
reload_and_restart
|
||||
verify_listener
|
||||
verify_local_api
|
||||
configure_firewall
|
||||
show_summary
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -0,0 +1,14 @@
|
||||
# observium
|
||||
|
||||
## Overview
|
||||
Observium installation helpers plus the agent-specific setup scripts stored in the `observium_agent` subfolder.
|
||||
|
||||
## Contents
|
||||
- `custom_install.sh`
|
||||
- `observium_agent`
|
||||
|
||||
## Usage
|
||||
Use this folder when deploying Observium or its agent configuration on supported hosts.
|
||||
|
||||
## Notes
|
||||
Observium setup often depends on web, database, and SNMP prerequisites that should be prepared in advance.
|
||||
@@ -0,0 +1,642 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
VERSION="0.3.1"
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BOLD='\033[1m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
function observiumfound {
|
||||
observium_found="no"
|
||||
if [ -d "/opt/observium" ]; then
|
||||
observium_found="yes"
|
||||
if [ -f "/opt/observium/config.php" ]; then
|
||||
observium_found="configured"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function agentinstall {
|
||||
if [ -d "/run/systemd/system" ] && [ -f "/opt/observium/scripts/systemd/observium_agent.socket" ]; then
|
||||
echo -e "${GREEN}Installing systemd unix-agent service...${NC}"
|
||||
cp /opt/observium/scripts/systemd/observium_agent.service /etc/systemd/system/observium_agent\@.service
|
||||
cp /opt/observium/scripts/systemd/observium_agent.socket /etc/systemd/system/observium_agent.socket
|
||||
systemctl daemon-reload
|
||||
systemctl enable observium_agent.socket
|
||||
systemctl start observium_agent.socket
|
||||
apt -qq install -y dmidecode
|
||||
else
|
||||
echo -e "${GREEN}Installing xinetd unix-agent service...${NC}"
|
||||
apt-get -qq install -y xinetd libwww-perl dmidecode
|
||||
cp /opt/observium/scripts/observium_agent_xinetd /etc/xinetd.d/observium_agent_xinetd
|
||||
service xinetd restart
|
||||
fi
|
||||
|
||||
cp /opt/observium/scripts/observium_agent /usr/bin/observium_agent
|
||||
mkdir -p /usr/lib/observium_agent
|
||||
mkdir -p /usr/lib/observium_agent/scripts-available
|
||||
mkdir -p /usr/lib/observium_agent/scripts-enabled
|
||||
cp -r /opt/observium/scripts/agent-local/* /usr/lib/observium_agent/scripts-available
|
||||
chmod +x /usr/bin/observium_agent
|
||||
ln -sf /usr/lib/observium_agent/scripts-available/dmi /usr/lib/observium_agent/scripts-enabled
|
||||
ln -sf /usr/lib/observium_agent/scripts-available/dpkg /usr/lib/observium_agent/scripts-enabled
|
||||
|
||||
if [ "$observ_ver" -lt "4" ]; then
|
||||
ln -sf /usr/lib/observium_agent/scripts-available/apache /usr/lib/observium_agent/scripts-enabled
|
||||
ln -sf /usr/lib/observium_agent/scripts-available/mysql /usr/lib/observium_agent/scripts-enabled
|
||||
fi
|
||||
|
||||
|
||||
echo "\$config['poller_modules']['unix-agent'] = 1;" >> /opt/observium/config.php
|
||||
echo -e "${GREEN}DONE! UNIX-agent is installed and this server is now monitored by Observium${NC}"
|
||||
}
|
||||
|
||||
function snmpdinstall {
|
||||
echo -e "${GREEN}Installing snmpd...${NC}"
|
||||
apt-get -qq install -y snmpd
|
||||
|
||||
observiumfound
|
||||
if [ $observium_found = "no" ]; then
|
||||
# Observium not installed, download distro from site
|
||||
curl -s -o /usr/local/bin/distro https://www.observium.org/files/distro
|
||||
#wget -O /usr/local/bin/distro https://www.observium.org/files/distro
|
||||
else
|
||||
# locally installed observium, copy from scripts
|
||||
cp /opt/observium/scripts/distro /usr/local/bin/distro
|
||||
fi
|
||||
chmod +x /usr/local/bin/distro
|
||||
|
||||
echo -e "${YELLOW}Reconfiguring local snmpd${NC}"
|
||||
if [ $observ_ver = 6 ] || [ $observium_found = "no" ]; then
|
||||
# remote poller hostname
|
||||
hostname="$(hostname -f)"
|
||||
# WARNING. Remote pollers have troubles with ip 127.0.1.1 (default in debian for hosts)
|
||||
echo "agentAddress udp:161" > /etc/snmp/snmpd.conf
|
||||
else
|
||||
# common install, probably better to use full hostname..
|
||||
hostname="localhost"
|
||||
echo "agentAddress udp:127.0.0.1:161" > /etc/snmp/snmpd.conf
|
||||
fi
|
||||
snmpcommunity="yates-network"
|
||||
echo "rocommunity yates-network" >> /etc/snmp/snmpd.conf
|
||||
|
||||
# Distro sctipt
|
||||
echo "# This line allows Observium to detect the host OS if the distro script is installed" >> /etc/snmp/snmpd.conf
|
||||
echo "extend .1.3.6.1.4.1.2021.7890.1 distro /usr/local/bin/distro" >> /etc/snmp/snmpd.conf
|
||||
|
||||
# Vendor/hardware extending
|
||||
if [ -f "/sys/devices/virtual/dmi/id/product_name" ]; then
|
||||
echo "# This lines allows Observium to detect hardware, vendor and serial" >> /etc/snmp/snmpd.conf
|
||||
echo "extend .1.3.6.1.4.1.2021.7890.2 hardware /bin/cat /sys/devices/virtual/dmi/id/product_name" >> /etc/snmp/snmpd.conf
|
||||
echo "extend .1.3.6.1.4.1.2021.7890.3 vendor /bin/cat /sys/devices/virtual/dmi/id/sys_vendor" >> /etc/snmp/snmpd.conf
|
||||
echo "#extend .1.3.6.1.4.1.2021.7890.4 serial /bin/cat /sys/devices/virtual/dmi/id/product_serial" >> /etc/snmp/snmpd.conf
|
||||
elif [ -f "/proc/device-tree/model" ]; then
|
||||
# ARM/RPi specific hardware
|
||||
echo "# This lines allows Observium to detect hardware, vendor and serial" >> /etc/snmp/snmpd.conf
|
||||
echo "extend .1.3.6.1.4.1.2021.7890.2 hardware /bin/cat /proc/device-tree/model" >> /etc/snmp/snmpd.conf
|
||||
echo "#extend .1.3.6.1.4.1.2021.7890.4 serial /bin/cat /proc/device-tree/serial" >> /etc/snmp/snmpd.conf
|
||||
fi
|
||||
|
||||
# Accurate uptime
|
||||
echo "# This line allows Observium to collect an accurate uptime" >> /etc/snmp/snmpd.conf
|
||||
echo "extend uptime /bin/cat /proc/uptime" >> /etc/snmp/snmpd.conf
|
||||
|
||||
echo "# This line enables Observium's ifAlias description injection" >> /etc/snmp/snmpd.conf
|
||||
echo "#pass_persist .1.3.6.1.2.1.31.1.1.1.18 /usr/local/bin/ifAlias_persist" >> /etc/snmp/snmpd.conf
|
||||
|
||||
service snmpd restart
|
||||
|
||||
if [ $observium_found = "no" ]; then
|
||||
# snmpd without observium install
|
||||
echo -e "${YELLOW}You can add host to Observium${NC}"
|
||||
echo -e " SNMP hostname: ${BOLD}$hostname${NC}"
|
||||
echo -e " SNMP v2c community: ${BOLD}$snmpcommunity${NC}"
|
||||
echo -e "${GREEN}DONE! SNMPD is installed and this server can be monitored by Observium${NC}"
|
||||
else
|
||||
# observium install, auto add host to db
|
||||
echo -e "${YELLOW}Adding $hostname to Observium${NC}"
|
||||
/opt/observium/add_device.php $hostname $snmpcommunity
|
||||
echo -e "${GREEN}DONE! SNMPD is installed and this server is now monitored by Observium${NC}"
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo -e "${RED}ERROR: You must be a root user${NC}" 2>&1
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ARCH=$(uname -m | sed 's/x86_//;s/i[3-6]86/32/')
|
||||
|
||||
if [ -f /etc/lsb-release ]; then
|
||||
. /etc/lsb-release
|
||||
OS=$DISTRIB_ID
|
||||
VER=$DISTRIB_RELEASE
|
||||
elif [ -f /etc/debian_version ]; then
|
||||
OS=Debian # XXX or Ubuntu??
|
||||
VER=$(cat /etc/debian_version)
|
||||
else
|
||||
OS=$(uname -s)
|
||||
VER=$(uname -r)
|
||||
fi
|
||||
|
||||
if [[ !$OS =~ ^(Ubuntu|Debian)$ ]]; then
|
||||
echo -e "${RED} [*] ERROR: This installscript does not support this distro, only Debian or Ubuntu supported. Use the manual guide at https://docs.observium.org/install_rhel7/ ${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cat << "EOF"
|
||||
___ _ _
|
||||
/ _ \| |__ ___ ___ _ ____ _(_)_ _ _ __ ___
|
||||
| | | | '_ \/ __|/ _ \ '__\ \ / / | | | | '_ ` _ \
|
||||
| |_| | |_) \__ \ __/ | \ V /| | |_| | | | | | |
|
||||
\___/|_.__/|___/\___|_| \_/ |_|\__,_|_| |_| |_|
|
||||
EOF
|
||||
echo -e ""
|
||||
echo -e "${GREEN}Welcome to Observium installation script v${VERSION}"
|
||||
echo -e ""
|
||||
echo -e "Please select the version of Observium you would like to install${NC}"
|
||||
echo -e ""
|
||||
echo -e "1. Observium ${BOLD}Community Edition${NC}"
|
||||
echo -e "2. Observium ${BOLD}Pro/Ent Edition ${GREEN}stable${NC} (requires account at https://www.observium.org/subs/)"
|
||||
echo -e "3. Observium ${BOLD}Pro/Ent Edition ${YELLOW}rolling${NC} (requires account at https://www.observium.org/subs/)"
|
||||
echo -e "4. Install the UNIX-Agent"
|
||||
echo -e "5. Install the SNMPD (snmpd-config will be overwritten)"
|
||||
echo -e "6. ${YELLOW}Remote poller${NC} for ${BOLD}Observium Pro/Ent Edition ${GREEN}stable${NC} (requires account at https://www.observium.org/subs/)"
|
||||
echo -n "(1-6): "
|
||||
read -n 1 observ_ver
|
||||
echo -e ""
|
||||
echo "you choose $observ_ver"
|
||||
echo " "
|
||||
|
||||
# check already installed Observium
|
||||
observiumfound
|
||||
if [ $observ_ver = 4 ]; then
|
||||
if [ $observium_found = "no" ]; then
|
||||
echo -e "${YELLOW} Observium not installed. Install it before install UNIX-Agent${NC}"
|
||||
fi
|
||||
agentinstall
|
||||
exit 1
|
||||
elif [ $observ_ver = 5 ]; then
|
||||
snmpdinstall
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ $observium_found = "yes" ]; then
|
||||
echo -e "${RED} Observium already installed.${NC}"
|
||||
echo -e " Please follow update procedure: https://docs.observium.org/#upgrading-observium"
|
||||
echo -e " or backup and remove /opt/observium directory for reinstall."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ $observ_ver = 2 ] || [ $observ_ver = 3 ]; then
|
||||
echo -e "${BOLD} Your SVN username and password can be found after logging in at: https://www.observium.org/subs/${NC}"
|
||||
read -p "Please enter your SVN Username: " svn_user
|
||||
read -s -p "Please enter your SVN Password: " svn_password
|
||||
echo -e ""
|
||||
mysql_user="observium"
|
||||
elif [ $observ_ver = 6 ]; then
|
||||
echo -e "${BOLD} Requested installing Remote poller for Observium Pro/Ent${NC}"
|
||||
echo -e ""
|
||||
|
||||
echo -e "${YELLOW}Please enter your params...${NC}"
|
||||
echo -e "${BOLD} Your SVN username and password can be found after logging in at: https://www.observium.org/subs/${NC}"
|
||||
read -p " SVN Username: " svn_user
|
||||
read -s -p " SVN Password: " svn_password
|
||||
echo -e ""
|
||||
|
||||
echo -e "${BOLD} Your MySQL server should be remotely accessed to DB 'observium' with this username and password${NC}"
|
||||
read -p " MySQL Host:Port: " mysql_host
|
||||
read -p " MySQL Username [observium]: " mysql_user
|
||||
mysql_user=${mysql_user:-observium}
|
||||
read -s -p " MySQL Password: " mysql_password
|
||||
echo -e ""
|
||||
|
||||
read -p " RRDCacheD Host:Port: " rrdcahed_host
|
||||
echo -e ""
|
||||
|
||||
hostname="$(hostname -f)"
|
||||
read -p " Observium Poller Name [$hostname]: " observium_poller
|
||||
if [ -z "${observium_poller}" ]; then
|
||||
observium_poller=$hostname
|
||||
fi
|
||||
echo -e ""
|
||||
elif [ $observ_ver = 1 ]; then
|
||||
echo -e "${BOLD} Requested installing Observium CE${NC}"
|
||||
echo -e ""
|
||||
mysql_user="observium"
|
||||
else
|
||||
echo -e "${RED} [*] ERROR: Invalid option $observ_ver${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$observ_ver" -lt "4" ]; then
|
||||
if [ -f /etc/apache2/sites-available/000-default.conf ] || [ -f /etc/apache2/sites-available/default ]; then
|
||||
echo -e "${YELLOW}WARNING: Apache default configuration was found. This script will overwrite that configuration, and your current settings will be lost.${NC}"
|
||||
echo "Continue?"
|
||||
select yn in "Yes" "No"; do
|
||||
case $yn in
|
||||
Yes )
|
||||
echo "Apache config will be overwritten..."
|
||||
break
|
||||
;;
|
||||
No )
|
||||
echo "Exiting..."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
# mysql server only for base install
|
||||
if $(dpkg --list mysql-server 2>/dev/null | egrep -q ^ii) || $(dpkg --list mariadb-server 2>/dev/null | egrep -q ^ii); then
|
||||
echo -e "${YELLOW}WARNING: A MySQL server is already installed. Do you know the root password for this server?${NC}"
|
||||
select yn in "Yes" "No"; do
|
||||
case $yn in
|
||||
Yes )
|
||||
echo "Please enter the MySQL root password and press [ENTER]"
|
||||
read -s mysql_root
|
||||
break
|
||||
;;
|
||||
No )
|
||||
echo "Exiting..."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
else
|
||||
echo -e "${GREEN} [*] No MySQL server was detected on this server. Installing MySQL...${NC}"
|
||||
echo "Choose a MySQL root password"
|
||||
read -s mysql_root
|
||||
fi
|
||||
|
||||
echo "mysql-server mysql-server/root_password password $mysql_root" | debconf-set-selections
|
||||
echo "mysql-server mysql-server/root_password_again password $mysql_root" | debconf-set-selections
|
||||
fi
|
||||
|
||||
echo -e "${GREEN} [*] Starting package installation; this may take up to 30 minutes${NC}"
|
||||
if [ $OS = "Ubuntu" ] && [ $VER = "16.04" ]; then
|
||||
# Unsupported!
|
||||
echo -e "${GREEN} [*] We are on Ubuntu 16.04 LTS, installing packages...${NC}"
|
||||
apt-get -qq update
|
||||
apt-get -qq install -y php7.0-cli php7.0-mysql php7.0-gd php7.0-mcrypt php7.0-json php7.0-bcmath php7.0-mbstring php7.0-curl php-apcu php-pear snmp fping mysql-client python-mysqldb rrdtool subversion whois mtr-tiny ipmitool
|
||||
phpenmod mcrypt
|
||||
if [ "$observ_ver" -lt "4" ]; then
|
||||
apt-get -qq install -y libapache2-mod-php7.0 graphviz imagemagick mysql-server apache2
|
||||
a2dismod mpm_event
|
||||
a2enmod mpm_prefork
|
||||
a2enmod php7.0
|
||||
fi
|
||||
elif [ $OS = "Ubuntu" ] && [ $VER = "17.04" ]; then
|
||||
# Unsupported!
|
||||
echo -e "${GREEN} [*] We are on Ubuntu 17.04, installing packages...${NC}"
|
||||
apt-get -qq update
|
||||
apt-get -qq install -y php7.0-cli php7.0-mysql php7.0-gd php7.0-mcrypt php7.0-json php7.0-bcmath php7.0-mbstring php7.0-curl php-apcu php-pear snmp fping mysql-client python-mysqldb rrdtool subversion whois mtr-tiny ipmitool
|
||||
phpenmod mcrypt
|
||||
if [ "$observ_ver" -lt "4" ]; then
|
||||
apt-get -qq install -y libapache2-mod-php7.0 graphviz imagemagick mysql-server apache2
|
||||
a2dismod mpm_event
|
||||
a2enmod mpm_prefork
|
||||
a2enmod php7.0
|
||||
fi
|
||||
elif [ $OS = "Ubuntu" ] && [ $VER = "17.10" ]; then
|
||||
# Unsupported!
|
||||
echo -e "${GREEN} [*] We are on Ubuntu 17.10, installing packages...${NC}"
|
||||
apt-get -qq update
|
||||
apt-get -qq install -y php7.1-cli php7.1-mysql php7.1-gd php7.1-mcrypt php7.1-json php7.1-bcmath php7.1-mbstring php7.1-opcache php7.1-curl php-apcu php-pear snmp fping mysql-client python-mysqldb rrdtool subversion whois mtr-tiny ipmitool libvirt-clients
|
||||
phpenmod mcrypt
|
||||
if [ "$observ_ver" -lt "4" ]; then
|
||||
apt-get -qq install -y libapache2-mod-php7.1 graphviz imagemagick mysql-server apache2
|
||||
a2dismod mpm_event
|
||||
a2enmod mpm_prefork
|
||||
a2enmod php7.1
|
||||
fi
|
||||
elif [ $OS = "Ubuntu" ] && [ $VER = "18.04" ]; then
|
||||
echo -e "${GREEN} [*] We are on Ubuntu 18.04 LTS, installing packages...${NC}"
|
||||
add-apt-repository universe -y
|
||||
add-apt-repository multiverse -y
|
||||
apt -qq update
|
||||
apt -q install -y php7.2-cli php7.2-mysql php7.2-gd php7.2-json php7.2-bcmath php7.2-mbstring php7.2-opcache php7.2-curl php-apcu php-pear snmp fping mysql-client python-mysqldb rrdtool subversion whois mtr-tiny ipmitool libvirt-clients
|
||||
#phpenmod mcrypt
|
||||
if [ "$observ_ver" -lt "4" ]; then
|
||||
apt -q install -y libapache2-mod-php7.2 graphviz imagemagick mysql-server apache2
|
||||
a2dismod mpm_event
|
||||
a2enmod mpm_prefork
|
||||
a2enmod php7.2
|
||||
fi
|
||||
elif [ $OS = "Ubuntu" ] && [ $VER = "20.04" ]; then
|
||||
echo -e "${GREEN} [*] We are on Ubuntu 20.04 LTS, installing packages...${NC}"
|
||||
add-apt-repository universe -y
|
||||
add-apt-repository multiverse -y
|
||||
apt -qq update
|
||||
apt -q install php7.4-cli php7.4-mysql php7.4-gd php7.4-json php7.4-bcmath php7.4-mbstring php7.4-opcache php7.4-curl php-apcu php-pear snmp fping mysql-client rrdtool subversion whois mtr-tiny ipmitool libvirt-clients python3-mysqldb python3-pymysql python-is-python3
|
||||
if [ "$observ_ver" -lt "4" ]; then
|
||||
apt -q install libapache2-mod-php7.4 graphviz imagemagick mysql-server apache2
|
||||
a2dismod mpm_event
|
||||
a2enmod mpm_prefork
|
||||
a2enmod php7.4
|
||||
fi
|
||||
elif [ $OS = "Ubuntu" ] && [ $VER = "21.04" ]; then
|
||||
echo -e "${GREEN} [*] We are on Ubuntu 21.04, installing packages...${NC}"
|
||||
echo -e "${YELLOW} [*] Please note that we generally recommend using the latest Ubuntu LTS release.${NC}"
|
||||
add-apt-repository universe -y
|
||||
add-apt-repository multiverse -y
|
||||
apt -qq update
|
||||
apt -q install php7.4-cli php7.4-mysql php7.4-gd php7.4-json php7.4-bcmath php7.4-mbstring php7.4-opcache php7.4-curl php-apcu php-pear snmp fping mysql-client rrdtool subversion whois mtr-tiny ipmitool libvirt-clients python3-mysqldb python3-pymysql python-is-python3
|
||||
if [ "$observ_ver" -lt "4" ]; then
|
||||
apt -q install libapache2-mod-php7.4 graphviz imagemagick mysql-server apache2
|
||||
a2dismod mpm_event
|
||||
a2enmod mpm_prefork
|
||||
a2enmod php7.4
|
||||
fi
|
||||
elif [ $OS = "Ubuntu" ] && [ $VER = "22.04" ]; then
|
||||
echo -e "${GREEN} [*] We are on Ubuntu 22.04, installing PHP 8.1 and other packages...${NC}"
|
||||
add-apt-repository universe -y
|
||||
add-apt-repository multiverse -y
|
||||
apt -qq update
|
||||
apt -q install php8.1-cli php8.1-mysql php8.1-gd php8.1-bcmath php8.1-mbstring php8.1-opcache php8.1-curl php-apcu php-pear snmp fping mysql-client rrdtool subversion whois mtr-tiny ipmitool libvirt-clients python3-mysqldb python3-pymysql python-is-python3
|
||||
if [ "$observ_ver" -lt "4" ]; then
|
||||
apt -q install libapache2-mod-php8.1 graphviz imagemagick mysql-server apache2
|
||||
a2dismod mpm_event
|
||||
a2enmod mpm_prefork
|
||||
a2enmod php8.1
|
||||
fi
|
||||
elif [ $OS = "Ubuntu" ] && [ $VER = "24.04" ]; then
|
||||
echo -e "${GREEN} [*] We are on Ubuntu 24.04, installing PHP 8.3 and other packages...${NC}"
|
||||
add-apt-repository universe -y
|
||||
add-apt-repository multiverse -y
|
||||
apt -qq update
|
||||
apt -q install php8.3-cli php8.3-mysql php8.3-gd php8.3-bcmath php8.3-mbstring php8.3-opcache php8.3-curl php-apcu php-pear snmp fping mysql-client rrdtool subversion whois mtr-tiny ipmitool libvirt-clients python3-mysqldb python3-pymysql python-is-python3
|
||||
if [ "$observ_ver" -lt "4" ]; then
|
||||
apt -q install libapache2-mod-php8.3 graphviz imagemagick mysql-server apache2
|
||||
a2dismod mpm_event
|
||||
a2enmod mpm_prefork
|
||||
a2enmod php8.3
|
||||
fi
|
||||
elif [ $OS = "Debian" ] && [[ $VER =~ ^8.* ]]; then
|
||||
echo -e "${GREEN} [*] We are on Debian 8.x, installing packages...${NC}"
|
||||
# Unsupported!
|
||||
apt-get -qq update
|
||||
apt-get -qq install -y php7.0-cli php7.0-mysql php7.0-gd php7.0-libsodium php7.0-mcrypt php7.0-json php7.0-bcmath php7.0-mbstring php7.0-opcache php7.0-apcu php7.0-curl php-pear snmp fping mysql-client python-mysqldb rrdtool subversion whois mtr-tiny ipmitool
|
||||
phpenmod mcrypt
|
||||
if [ "$observ_ver" -lt "4" ]; then
|
||||
apt-get -qq install -y libapache2-mod-php7.0 graphviz imagemagick mysql-server apache2
|
||||
a2dismod mpm_event
|
||||
a2enmod mpm_prefork
|
||||
a2enmod php7.0
|
||||
fi
|
||||
elif [ $OS = "Debian" ] && [[ $VER =~ ^9.* ]]; then
|
||||
# Unsupported!
|
||||
echo -e "${GREEN} [*] We are on Debian 9.x, installing packages...${NC}"
|
||||
apt-get -qq update
|
||||
apt-get -qq install -y php7.0-cli php7.0-mysql php7.0-gd php7.0-libsodium php7.0-mcrypt php7.0-json php7.0-bcmath php7.0-mbstring php7.0-opcache php7.0-apcu php7.0-curl php-pear snmp fping mariadb-client python-mysqldb rrdtool subversion whois mtr-tiny ipmitool
|
||||
phpenmod mcrypt
|
||||
if [ "$observ_ver" -lt "4" ]; then
|
||||
apt-get -qq install -y libapache2-mod-php7.0 graphviz imagemagick mariadb-server apache2
|
||||
a2dismod mpm_event
|
||||
a2enmod mpm_prefork
|
||||
a2enmod php7.0
|
||||
fi
|
||||
elif [ $OS = "Debian" ] && [[ $VER =~ ^10.* ]]; then
|
||||
echo -e "${GREEN} [*] We are on Debian 10.x, we will install PHP 7.3. Installing packages...${NC}"
|
||||
apt -qq update
|
||||
apt -qq install -y php7.3-cli php7.3-mysql php7.3-gd php7.3-json php7.3-bcmath php7.3-mbstring php7.3-opcache php7.3-apcu php7.3-curl php-pear snmp fping mariadb-client python-mysqldb rrdtool subversion whois mtr-tiny ipmitool libvirt-clients
|
||||
#phpenmod mcrypt
|
||||
if [ "$observ_ver" -lt "4" ]; then
|
||||
apt -qq install -y libapache2-mod-php7.3 graphviz imagemagick mariadb-server apache2
|
||||
a2dismod mpm_event
|
||||
a2enmod mpm_prefork
|
||||
fi
|
||||
elif [ $OS = "Debian" ] && [[ $VER =~ ^11.* ]]; then
|
||||
echo -e "${GREEN} [*] We are on Debian 11.x, we will install PHP 7.4. Installing packages...${NC}"
|
||||
apt -qq update
|
||||
apt -qq install -y php7.4-cli php7.4-mysql php7.4-gd php7.4-json php7.4-bcmath php7.4-mbstring php7.4-opcache php7.4-apcu php7.4-curl php-pear snmp fping mariadb-client python3-mysqldb rrdtool subversion whois mtr-tiny ipmitool libvirt-clients python-is-python3 python3-pymysql
|
||||
if [ "$observ_ver" -lt "4" ]; then
|
||||
apt -qq install -y libapache2-mod-php7.4 graphviz imagemagick mariadb-server apache2
|
||||
a2dismod mpm_event
|
||||
a2enmod mpm_prefork
|
||||
fi
|
||||
elif [ $OS = "Debian" ] && [[ $VER =~ ^12.* ]]; then
|
||||
echo -e "${GREEN} [*] We are on Debian 12.x, we will install PHP 8.2. Installing packages...${NC}"
|
||||
apt -qq update
|
||||
apt -qq install -y php8.2-cli php8.2-mysql php8.2-gd php8.2-bcmath php8.2-mbstring php8.2-opcache php8.2-apcu php8.2-curl php-json php-pear snmp fping mariadb-client python3-mysqldb python3-pymysql python-is-python3 rrdtool subversion whois mtr-tiny ipmitool libvirt-clients
|
||||
if [ "$observ_ver" -lt "4" ]; then
|
||||
apt -qq install -y libapache2-mod-php8.2 graphviz imagemagick mariadb-server apache2
|
||||
a2dismod mpm_event
|
||||
a2enmod mpm_prefork
|
||||
fi
|
||||
else
|
||||
echo -e "${RED} [*] ERROR: This installscript does not support this distro, only Debian or Ubuntu supported. Use the manual guide at https://docs.observium.org/install_rhel7/ ${NC}"
|
||||
echo "OS:" $OS
|
||||
echo "Version:" $VER
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${GREEN} [*] Creating Observium dir${NC}"
|
||||
mkdir -p /opt/observium && cd /opt
|
||||
|
||||
if [ $observ_ver = 1 ]; then
|
||||
echo -e "${GREEN} [*] Downloading Observium CE and unpacking...${NC}"
|
||||
wget -r -nv https://www.observium.org/observium-community-latest.tar.gz -O /opt/observium-community-latest.tar.gz
|
||||
tar zxf observium-community-latest.tar.gz --checkpoint=.1000
|
||||
echo " "
|
||||
elif [ $observ_ver = 2 ] || [ $observ_ver = 6 ]; then
|
||||
echo -e "${GREEN} [*] Checking out Observium Pro/Ent stable from SVN${NC}"
|
||||
#echo "Your SVN username and password is found after you login at: https://www.observium.org/subs/"
|
||||
#read -p "Please enter your SVN username: " svn_user
|
||||
svn co -q --username "$svn_user" --password "$svn_password" https://svn.observium.org/svn/observium/branches/stable observium
|
||||
elif [ $observ_ver = 3 ]; then
|
||||
echo -e "${GREEN} [*] Checking out Observium Pro/Ent rolling from SVN${NC}"
|
||||
#echo "Your SVN username and password is found after you login at: https://www.observium.org/subs/"
|
||||
#read -p "Please enter your SVN username: " svn_user
|
||||
svn co -q --username "$svn_user" --password "$svn_password" https://svn.observium.org/svn/observium/trunk observium
|
||||
fi
|
||||
|
||||
cd observium
|
||||
|
||||
if [ "$observ_ver" -lt "4" ]; then
|
||||
# initial mysql db user/password creation
|
||||
echo -e "${GREEN} [*] Creating database user for Observium with a random password...${NC}"
|
||||
mysql_password="$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-15};echo;)"
|
||||
mysql -uroot -p"$mysql_root" -e "CREATE DATABASE observium DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci"
|
||||
|
||||
if [[ $OS = "Ubuntu" ]] && ( [[ $VER = "20.04" ]] || [[ $VER = "21.04" ]] || [[ $VER = "22.04" ]] || [[ $VER = "24.04" ]] ); then
|
||||
#echo -e "${GREEN} [*] We are on Ubuntu 20.04 LTS, installing packages...${NC}"
|
||||
mysql -uroot -p"$mysql_root" -e "CREATE USER 'observium'@'localhost' IDENTIFIED BY '$mysql_password'"
|
||||
mysql -uroot -p"$mysql_root" -e "GRANT ALL ON observium.* TO 'observium'@'localhost'"
|
||||
else
|
||||
mysql -uroot -p"$mysql_root" -e "GRANT ALL PRIVILEGES ON observium.* TO 'observium'@'localhost' IDENTIFIED BY '$mysql_password'"
|
||||
fi
|
||||
elif [ $observ_ver = 6 ]; then
|
||||
echo -e ""
|
||||
if mysql -u "$mysql_user" -p"$mysql_password" -h "$mysql_host" -D observium -e "SELECT VERSION();" > /dev/null 2>&1; then
|
||||
echo "Connection to database successful."
|
||||
else
|
||||
# still configure poller for manual config later
|
||||
echo "Failed to connect to database. Please check DB host/user/password and set correct in config.php"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo -e "${GREEN} [*] Creating Observium config-file...${NC}"
|
||||
sed "s/'USERNAME'/'$mysql_user'/g" config.php.default > config.php
|
||||
sed -i "s/'PASSWORD'/'$mysql_password'/g" config.php
|
||||
if [ $observ_ver = 6 ]; then
|
||||
# extra configurations for remote poller
|
||||
sed -i "s/'localhost'/'$mysql_host'/g" config.php
|
||||
|
||||
echo -e "" >> config.php
|
||||
echo -e "# Remote poller" >> config.php
|
||||
echo -e "\$config['rrdcached'] = '$rrdcahed_host';" >> config.php
|
||||
echo -e "# Force get poller_id by host id if name changed" >> config.php
|
||||
echo -e "\$config['poller_by_host'] = TRUE;" >> config.php
|
||||
echo -e "\$config['poller_name'] = '$observium_poller';" >> config.php
|
||||
|
||||
fi
|
||||
|
||||
echo -e "${GREEN} [*] Creating log and rrd-directories...${NC}"
|
||||
id -u observium &>/dev/null || useradd -G www-data observium
|
||||
mkdir -p logs
|
||||
chown -R observium:observium logs
|
||||
#this mode makes all files created inherit permissions of rrd/-folder
|
||||
mkdir -p --mode=u+rwx,g+rs,o-w rrd
|
||||
chown -R observium:www-data rrd
|
||||
chmod -R g+w rrd
|
||||
|
||||
if [ "$observ_ver" -lt "4" ]; then
|
||||
# DB schema upgrade & apache config for common install
|
||||
./discovery.php -u
|
||||
|
||||
apachever="$(apache2ctl -v)"
|
||||
if [[ $apachever == *"Apache/2.4"* ]]; then
|
||||
echo -e "${GREEN} [*] Apache version is 2.4, creating config...${NC}"
|
||||
cat > /etc/apache2/sites-available/000-default.conf <<- EOM
|
||||
<VirtualHost *:80>
|
||||
ServerAdmin webmaster@localhost
|
||||
DocumentRoot /opt/observium/html
|
||||
<FilesMatch \.php$>
|
||||
SetHandler application/x-httpd-php
|
||||
</FilesMatch>
|
||||
<Directory />
|
||||
Options FollowSymLinks
|
||||
AllowOverride None
|
||||
</Directory>
|
||||
<Directory /opt/observium/html/>
|
||||
DirectoryIndex index.php
|
||||
Options Indexes FollowSymLinks MultiViews
|
||||
AllowOverride All
|
||||
Require all granted
|
||||
</Directory>
|
||||
ErrorLog ${APACHE_LOG_DIR}/error.log
|
||||
LogLevel warn
|
||||
CustomLog ${APACHE_LOG_DIR}/access.log combined
|
||||
ServerSignature On
|
||||
</VirtualHost>
|
||||
EOM
|
||||
|
||||
#echo "$APACHE24" > /etc/apache2/sites-available/000-default.conf
|
||||
elif [[ $apachever == *"Apache/2.2"* ]]; then
|
||||
echo -e "${GREEN} [*] Apache version is 2.2m creating config...${NC}"
|
||||
cat > /etc/apache2/sites-available/default <<- EOM
|
||||
<VirtualHost *:80>
|
||||
ServerAdmin webmaster@localhost
|
||||
DocumentRoot /opt/observium/html
|
||||
<FilesMatch \.php$>
|
||||
SetHandler application/x-httpd-php
|
||||
</FilesMatch>
|
||||
<Directory />
|
||||
Options FollowSymLinks
|
||||
AllowOverride None
|
||||
</Directory>
|
||||
<Directory /opt/observium/html/>
|
||||
DirectoryIndex index.php
|
||||
Options Indexes FollowSymLinks MultiViews
|
||||
AllowOverride All
|
||||
Order allow,deny
|
||||
allow from all
|
||||
</Directory>
|
||||
ErrorLog ${APACHE_LOG_DIR}/error.log
|
||||
LogLevel warn
|
||||
CustomLog ${APACHE_LOG_DIR}/access.log combined
|
||||
ServerSignature On
|
||||
</VirtualHost>
|
||||
EOM
|
||||
|
||||
#echo "$APACHE22" > /etc/apache2/sites-available/default
|
||||
else
|
||||
echo -e "${RED} [*] ERROR: Could not find right version of Apache${NC}"
|
||||
exit 1
|
||||
fi
|
||||
a2enmod rewrite
|
||||
apache2ctl restart
|
||||
|
||||
echo -e "${GREEN} [*] Create first time Observium admin user..${NC}"
|
||||
read -p "Username: " observ_username
|
||||
read -s -p "Password: " observ_password
|
||||
./adduser.php $observ_username $observ_password 10
|
||||
|
||||
echo -e "${GREEN} [*] Creating Observium cronjob...${NC}"
|
||||
cat > /etc/cron.d/observium <<- EOM
|
||||
# Run a complete discovery of all devices once every 6 hours
|
||||
33 */6 * * * observium /opt/observium/observium-wrapper discovery >> /dev/null 2>&1
|
||||
# Run automated discovery of newly added devices every 5 minutes
|
||||
*/5 * * * * observium /opt/observium/observium-wrapper discovery --host new >> /dev/null 2>&1
|
||||
# Run multithreaded poller wrapper every 5 minutes
|
||||
*/5 * * * * observium /opt/observium/observium-wrapper poller >> /dev/null 2>&1
|
||||
|
||||
# Run housekeeping script daily for syslog, eventlog and alert log
|
||||
13 5 * * * observium /opt/observium/housekeeping.php -ysel >> /dev/null 2>&1
|
||||
# Run housekeeping script daily for rrds, ports, orphaned entries in the database and performance data
|
||||
47 4 * * * observium /opt/observium/housekeeping.php -yrptb >> /dev/null 2>&1
|
||||
EOM
|
||||
|
||||
else
|
||||
# remote poller, housekeeping disabled
|
||||
echo -e "${GREEN} [*] Creating Observium cronjob...${NC}"
|
||||
cat > /etc/cron.d/observium <<- EOM
|
||||
# Run a complete discovery of all devices once every 6 hours
|
||||
33 */6 * * * observium /opt/observium/observium-wrapper discovery >> /dev/null 2>&1
|
||||
# Run automated discovery of newly added devices every 5 minutes
|
||||
*/5 * * * * observium /opt/observium/observium-wrapper discovery --host new >> /dev/null 2>&1
|
||||
# Run multithreaded poller wrapper every 5 minutes
|
||||
*/5 * * * * observium /opt/observium/observium-wrapper poller >> /dev/null 2>&1
|
||||
|
||||
# Run housekeeping script daily for syslog, eventlog and alert log
|
||||
#13 5 * * * observium /opt/observium/housekeeping.php -ysel >> /dev/null 2>&1
|
||||
# Run housekeeping script daily for rrds, ports, orphaned entries in the database and performance data
|
||||
#47 4 * * * observium /opt/observium/housekeeping.php -yrptb >> /dev/null 2>&1
|
||||
EOM
|
||||
|
||||
fi
|
||||
|
||||
# Fixate fping on ARM before snmpinstall
|
||||
# chmod u+s /usr/bin/fping
|
||||
|
||||
echo -en "${GREEN}Would you like to install/configure SNMP daemon and monitor this host with Observium? ${YELLOW}(your snmpd-config will be overwritten!)${NC} (${BOLD}Y${NC}/n): "
|
||||
read -n 1 yn
|
||||
echo
|
||||
case $yn in
|
||||
No|no|N|n)
|
||||
echo "Skipping snmpd installation"
|
||||
;;
|
||||
*)
|
||||
snmpdinstall
|
||||
;;
|
||||
esac
|
||||
|
||||
echo -en "${GREEN}Would you like to install the UNIX-agent on this host?${NC} (y/${BOLD}N${NC}): "
|
||||
read -n 1 yn
|
||||
echo
|
||||
case $yn in
|
||||
Yes|YES|yes|Y|y)
|
||||
agentinstall
|
||||
;;
|
||||
*)
|
||||
echo "Skipping unix-agent installation"
|
||||
;;
|
||||
esac
|
||||
|
||||
echo -e "${GREEN} [*] Installation complete! Open your web browser, log in to the web interface with the account you just created, and add your first device.${NC}"
|
||||
|
||||
# EOF
|
||||
@@ -0,0 +1,14 @@
|
||||
# observium_agent
|
||||
|
||||
## Overview
|
||||
Agent install and configuration scripts for systems that report into Observium.
|
||||
|
||||
## Contents
|
||||
- `agent.conf.sh`
|
||||
- `observium-agent-install.sh`
|
||||
|
||||
## Usage
|
||||
Run these scripts on monitored hosts after confirming the destination configuration path and service requirements.
|
||||
|
||||
## Notes
|
||||
Agent-based monitoring may require firewall allowances and compatible SNMP or agent polling settings.
|
||||
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
SNMP_COMMUNITY="yates-network"
|
||||
SYSCONTACT="Traver Yates"
|
||||
SYSLOCATION="Home Network"
|
||||
|
||||
SVN_USER=""
|
||||
SVN_PASS=""
|
||||
|
||||
OBSERVIUM_HOST="rasp1"
|
||||
|
||||
# Fill with a list of modules you would like to use from /opt/observium/scripts/agent-local
|
||||
# at the time of writing available options are:
|
||||
#
|
||||
# apache areca-hw asterisk bind crashplan dmi
|
||||
# dpkg drbd edac exim-mailqueue.sh freeradius hdarray hddtemp ipmitool-sensor jvm-over-jmx ksm
|
||||
# lmsensors memcached munin munin-scripts mysql mysql.cnf nfs nfsd nginx ntpd nvidia-smi
|
||||
# postfix_mailgraph postfix_qshape postgresql.conf postgresql.pl powerdns powerdns-recursor
|
||||
# raspberrypi README rpm sabnzbd-qstatus shoutcast shoutcast.conf shoutcast.default.conf
|
||||
# temperature unbound varnish vmwaretools zimbra
|
||||
MODULES=()
|
||||
@@ -0,0 +1,136 @@
|
||||
#!/bin/bash
|
||||
|
||||
CONFIG="agent.conf.sh"
|
||||
ENTERPRISE=false
|
||||
PKG_MANAGERS=(apt-get zypper yum)
|
||||
|
||||
if [ ! -f $CONFIG ]; then
|
||||
echo "agent.conf.sh not found or not readable"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source $CONFIG
|
||||
|
||||
# Which Distro are we running on...
|
||||
if [ -z "$PKG_MANAGERS" ] || [ ${#PKG_MANAGERS[@]} -eq 0 ]; then
|
||||
echo "Error! No package managers specified"
|
||||
exit 1
|
||||
else
|
||||
for pkg in ${PKG_MANAGERS[@]}; do
|
||||
TEST=`which $pkg`
|
||||
if [ $? -eq 0 ]; then
|
||||
PKG_MAN=$pkg
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -z "$PKG_MAN" ]; then
|
||||
echo "No package manager found on this system!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$SYSCONTACT" ]; then
|
||||
echo "No system contact specified"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$SYSLOCATION" ]; then
|
||||
echo "No system location specified"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$SNMP_COMMUNITY" ]; then
|
||||
echo "No SNMP Community specified"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$OBSERVIUM_HOST" ]; then
|
||||
echo "No Observium Server IP or hostname specified"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$SVN_USER" ] || [ -z "$SVN_PASS" ]; then
|
||||
$ENTERPRISE = false
|
||||
fi
|
||||
|
||||
if [ "$ENTERPRISE" = true ]; then
|
||||
echo "Installing Enterprise Agent..."
|
||||
echo
|
||||
$PKG_MAN install subversion snmpd xinetd
|
||||
else
|
||||
echo "Installing Community Agent..."
|
||||
echo
|
||||
$PKG_MAN install snmpd xinetd
|
||||
fi
|
||||
|
||||
cd /opt
|
||||
|
||||
if [ "$ENTERPRISE" = true ]; then
|
||||
svn --username $SVN_USER --password $SVN_PASS co http://svn.observium.org/svn/observium/branches/stable observium
|
||||
else
|
||||
mkdir -p /opt/observium && cd /opt
|
||||
|
||||
wget http://www.observium.org/observium-community-latest.tar.gz
|
||||
tar zxvf observium-community-latest.tar.gz
|
||||
fi
|
||||
|
||||
if [ -f "/etc/defaults/snmpd" ]; then
|
||||
sed -e "/SNMPDOPTS=/ s/^#*/SNMPDOPTS='-Lsd -Lf \/dev\/null -u snmp -p \/var\/run\/snmpd.pid'\n#/" -i /etc/default/snmpd
|
||||
fi
|
||||
|
||||
if [ -f "/etc/sysconfig/snmpd.options" ]; then
|
||||
sed -e "/SNMPDOPTS=/ s/^#*/SNMPDOPTS='-Lsd -Lf \/dev\/null -u snmp -p \/var\/run\/snmpd.pid'\n#/" -i /etc/sysconfig/snmpd.options
|
||||
fi
|
||||
|
||||
mv /opt/observium/scripts/distro /usr/bin/distro
|
||||
chmod 755 /usr/bin/distro
|
||||
|
||||
mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak
|
||||
cat >/etc/snmp/snmpd.conf <<EOL
|
||||
com2sec readonly default $SNMP_COMMUNITY
|
||||
group MyROGroup v1 readonly
|
||||
group MyROGroup v2c readonly
|
||||
group MyROGroup usm readonly
|
||||
view all included .1 80
|
||||
access MyROGroup "" any noauth exact all none none
|
||||
syslocation $SYSLOCATION
|
||||
syscontact $SYSCONTACT
|
||||
#This line allows Observium to detect the host OS if the distro script is installed
|
||||
extend .1.3.6.1.4.1.2021.7890.1 distro /usr/bin/distro
|
||||
EOL
|
||||
|
||||
cat >/etc/xinetd.d/observium_agent <<EOL
|
||||
service observium_agent
|
||||
{
|
||||
type = UNLISTED
|
||||
port = 36602
|
||||
socket_type = stream
|
||||
protocol = tcp
|
||||
wait = no
|
||||
user = root
|
||||
server = /usr/bin/observium_agent
|
||||
# configure the IPv[4|6] address(es) of your Observium server here:
|
||||
only_from = $OBSERVIUM_HOST
|
||||
# Don't be too verbose. Don't log every check. This might be
|
||||
# commented out for debugging. If this option is commented out
|
||||
# the default options will be used for this service.
|
||||
log_on_success =
|
||||
disable = no
|
||||
}
|
||||
EOL
|
||||
|
||||
cp observium/scripts/observium_agent /usr/bin/observium_agent
|
||||
|
||||
mkdir -p /usr/lib/observium_agent/local
|
||||
|
||||
if [ -z "$MODULES" ] || [ ${#MODULES[@]} -eq 0 ]; then
|
||||
echo "No modules specified skipping..."
|
||||
else
|
||||
for mod in ${MODULES[@]}; do
|
||||
cp observium/scripts/agent-local/$mod /usr/lib/observium_agent/local/
|
||||
done
|
||||
fi
|
||||
|
||||
/etc/init.d/xinetd restart
|
||||
/etc/init.d/snmpd restart
|
||||
@@ -0,0 +1,18 @@
|
||||
# snmp
|
||||
|
||||
## Overview
|
||||
SNMP setup scripts for Linux, macOS, and OpenWrt along with default configuration references.
|
||||
|
||||
## Contents
|
||||
- `Setup_snmp_macos.sh`
|
||||
- `openwrt_snmp_defaults.txt`
|
||||
- `setup_snmp.sh`
|
||||
- `setup_snmp_openwrt.sh`
|
||||
- `setup_snmp_openwrt_publicv2.sh`
|
||||
- `setup_snmp_openwrt_v2.sh`
|
||||
|
||||
## Usage
|
||||
Use the script that matches the target platform and validate the SNMP version and community or credential model first.
|
||||
|
||||
## Notes
|
||||
SNMP settings expose monitoring data, so align them with the security posture of the network.
|
||||
@@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Check if the script is running on macOS
|
||||
if [[ "$(uname)" != "Darwin" ]]; then
|
||||
echo "This script is designed to run on macOS."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if Homebrew is installed
|
||||
if ! command -v brew &> /dev/null; then
|
||||
echo "Homebrew is not installed. Installing Homebrew..."
|
||||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||
fi
|
||||
|
||||
# Install SNMP tools
|
||||
echo "Installing SNMP tools via Homebrew..."
|
||||
brew install net-snmp
|
||||
|
||||
# Prompt for user input
|
||||
echo "Enter the SNMPv3 username (e.g., admin):"
|
||||
read SNMP_USER
|
||||
echo "Enter the SNMPv3 password:"
|
||||
read -s SNMP_PASSWORD
|
||||
echo "Re-enter the SNMPv3 password:"
|
||||
read -s SNMP_PASSWORD_CONFIRM
|
||||
|
||||
# Verify password confirmation
|
||||
if [ "$SNMP_PASSWORD" != "$SNMP_PASSWORD_CONFIRM" ]; then
|
||||
echo "Passwords do not match. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Enter the system location (e.g., Office):"
|
||||
read SYS_LOCATION
|
||||
echo "Enter the system contact (e.g., admin@example.com):"
|
||||
read SYS_CONTACT
|
||||
|
||||
# Configure SNMPv3
|
||||
echo "Configuring SNMPv3..."
|
||||
SNMP_CONF="/usr/local/etc/snmp/snmpd.conf"
|
||||
sudo mkdir -p /usr/local/etc/snmp
|
||||
|
||||
cat <<EOT | sudo tee $SNMP_CONF
|
||||
# SNMPv3 Configuration
|
||||
createUser $SNMP_USER MD5 $SNMP_PASSWORD AES $SNMP_PASSWORD
|
||||
rouser $SNMP_USER priv
|
||||
agentAddress udp:161,udp6:[::1]:161
|
||||
view all included .1 80
|
||||
access notConfigGroup "" any noauth exact all none none
|
||||
sysLocation "$SYS_LOCATION"
|
||||
sysContact "$SYS_CONTACT"
|
||||
EOT
|
||||
|
||||
# Restrict permissions on the configuration file
|
||||
echo "Setting proper permissions for SNMP configuration..."
|
||||
sudo chmod 600 $SNMP_CONF
|
||||
|
||||
# Start SNMP service
|
||||
echo "Starting SNMP service..."
|
||||
sudo launchctl load -w /Library/LaunchDaemons/org.net-snmp.snmpd.plist
|
||||
|
||||
# Verify SNMP configuration
|
||||
echo "Verifying SNMP service..."
|
||||
snmpwalk -v3 -u $SNMP_USER -a MD5 -A $SNMP_PASSWORD -x AES -X $SNMP_PASSWORD -l authPriv localhost
|
||||
|
||||
echo "SNMPv3 installation and configuration complete on macOS."
|
||||
@@ -0,0 +1,130 @@
|
||||
config agent
|
||||
option agentaddress UDP:161,UDP6:161
|
||||
|
||||
config agentx
|
||||
option agentxsocket /var/run/agentx.sock
|
||||
|
||||
config com2sec public
|
||||
option secname ro
|
||||
option source default
|
||||
option community public
|
||||
|
||||
config com2sec private
|
||||
option secname rw
|
||||
option source localhost
|
||||
option community private
|
||||
|
||||
config com2sec6 public6
|
||||
option secname ro
|
||||
option source default
|
||||
option community public
|
||||
|
||||
config com2sec6 private6
|
||||
option secname rw
|
||||
option source localhost
|
||||
option community private
|
||||
|
||||
config group public_v1
|
||||
option group public
|
||||
option version v1
|
||||
option secname ro
|
||||
|
||||
config group public_v2c
|
||||
option group public
|
||||
option version v2c
|
||||
option secname ro
|
||||
|
||||
config group public_usm
|
||||
option group public
|
||||
option version usm
|
||||
option secname ro
|
||||
|
||||
config group private_v1
|
||||
option group private
|
||||
option version v1
|
||||
option secname rw
|
||||
|
||||
config group private_v2c
|
||||
option group private
|
||||
option version v2c
|
||||
option secname rw
|
||||
|
||||
config group private_usm
|
||||
option group private
|
||||
option version usm
|
||||
option secname rw
|
||||
|
||||
config view all
|
||||
option viewname all
|
||||
option type included
|
||||
option oid .1
|
||||
|
||||
config access public_access
|
||||
option group public
|
||||
option context none
|
||||
option version any
|
||||
option level noauth
|
||||
option prefix exact
|
||||
option read all
|
||||
option write none
|
||||
option notify none
|
||||
|
||||
config access private_access
|
||||
option group private
|
||||
option context none
|
||||
option version any
|
||||
option level noauth
|
||||
option prefix exact
|
||||
option read all
|
||||
option write all
|
||||
option notify all
|
||||
|
||||
config system
|
||||
option sysLocation 'Mothers'
|
||||
option sysContact 'alerts@tyates.one'
|
||||
option sysName 'Mothers Router'
|
||||
# option sysServices 72
|
||||
# option sysDescr 'adult playground'
|
||||
# option sysObjectID '1.2.3.4'
|
||||
|
||||
config exec
|
||||
option name filedescriptors
|
||||
option prog /bin/cat
|
||||
option args /proc/sys/fs/file-nr
|
||||
# option miboid 1.2.3.4
|
||||
|
||||
config engineid
|
||||
# option engineid 'LEDE'
|
||||
option engineidtype '3'
|
||||
option engineidnic 'eth0'
|
||||
|
||||
#config trapcommunity 'trapcommunity'
|
||||
# option community 'public'
|
||||
|
||||
#config trapsink
|
||||
# option host 'nms.system.com'
|
||||
# option community 'public'
|
||||
# option port '162'
|
||||
|
||||
#config trap2sink
|
||||
# option host 'nms.system.com'
|
||||
# option community 'secret'
|
||||
# option port '162'
|
||||
|
||||
#config informsink
|
||||
# option host 'nms.sytem.com'
|
||||
# option community 'public'
|
||||
# option port '162'
|
||||
|
||||
#config authtrapenable 'authtrapenable'
|
||||
# option enable '1'
|
||||
|
||||
#config v1trapaddress 'v1trapaddress'
|
||||
# option host '1.2.3.4'
|
||||
|
||||
#config trapsess 'trapsess'
|
||||
# option trapsess '-v 3 -e 0x80001f88808c18d3f7b0000 -u trapuser -a MD5 -A administrator -l authPriv -x DES -X rootpasswd udp:127.0.0.1:162'
|
||||
|
||||
config snmpd general
|
||||
option enabled '1'
|
||||
# list network 'wan'
|
||||
@@ -0,0 +1,64 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Prompt for user input
|
||||
echo "Enter the SNMPv3 username (e.g., admin):"
|
||||
read SNMP_USER
|
||||
echo "Enter the SNMPv3 password:"
|
||||
read -s SNMP_PASSWORD
|
||||
echo "Re-enter the SNMPv3 password:"
|
||||
read -s SNMP_PASSWORD_CONFIRM
|
||||
|
||||
# Verify password confirmation
|
||||
if [ "$SNMP_PASSWORD" != "$SNMP_PASSWORD_CONFIRM" ]; then
|
||||
echo "Passwords do not match. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Enter the system location (e.g., Data Center):"
|
||||
read SYS_LOCATION
|
||||
echo "Enter the system contact (e.g., admin@example.com):"
|
||||
read SYS_CONTACT
|
||||
|
||||
# Update the system
|
||||
echo "Updating system packages..."
|
||||
apt update -y && apt upgrade -y
|
||||
|
||||
# Install SNMP and related packages
|
||||
echo "Installing SNMP and dependencies..."
|
||||
apt install -y snmpd snmp libsnmp-dev
|
||||
|
||||
# Stop SNMP service to configure it
|
||||
echo "Stopping SNMP service..."
|
||||
systemctl stop snmpd
|
||||
|
||||
# Backup the original SNMP configuration file
|
||||
echo "Backing up the original configuration file..."
|
||||
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak
|
||||
|
||||
# Configure SNMPv3
|
||||
echo "Configuring SNMPv3..."
|
||||
cat <<EOT > /etc/snmp/snmpd.conf
|
||||
# SNMPv3 Configuration
|
||||
createUser $SNMP_USER MD5 $SNMP_PASSWORD AES $SNMP_PASSWORD
|
||||
rouser $SNMP_USER priv
|
||||
agentAddress udp:161,udp6:[::1]:161
|
||||
view all included .1 80
|
||||
access notConfigGroup "" any noauth exact all none none
|
||||
sysLocation "$SYS_LOCATION"
|
||||
sysContact "$SYS_CONTACT"
|
||||
EOT
|
||||
|
||||
# Restrict access to the configuration file
|
||||
echo "Restricting access to the configuration file..."
|
||||
chmod 600 /etc/snmp/snmpd.conf
|
||||
|
||||
# Start and enable SNMP service
|
||||
echo "Starting and enabling SNMP service..."
|
||||
systemctl enable snmpd
|
||||
systemctl start snmpd
|
||||
|
||||
# Verify SNMP configuration
|
||||
echo "Verifying SNMP service..."
|
||||
snmpstatus -v3 -u $SNMP_USER -a MD5 -A $SNMP_PASSWORD -x AES -X $SNMP_PASSWORD -l authPriv localhost
|
||||
|
||||
echo "SNMPv3 installation and configuration complete."
|
||||
@@ -0,0 +1,85 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Check if the script is running on OpenWrt
|
||||
if ! grep -q "OpenWrt" /etc/os-release; then
|
||||
echo "This script is designed to run on OpenWrt."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Prompt for user input
|
||||
echo "Enter the SNMPv3 username (e.g., admin):"
|
||||
read SNMP_USER
|
||||
echo "Enter the SNMPv3 password:"
|
||||
read -s SNMP_PASSWORD
|
||||
echo "Re-enter the SNMPv3 password:"
|
||||
read -s SNMP_PASSWORD_CONFIRM
|
||||
|
||||
# Verify password confirmation
|
||||
if [ "$SNMP_PASSWORD" != "$SNMP_PASSWORD_CONFIRM" ]; then
|
||||
echo "Passwords do not match. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Enter the system location (e.g., Router Closet):"
|
||||
read SYS_LOCATION
|
||||
echo "Enter the system contact (e.g., admin@example.com):"
|
||||
read SYS_CONTACT
|
||||
|
||||
# Update opkg and install SNMP
|
||||
echo "Updating package list..."
|
||||
opkg update
|
||||
|
||||
echo "Installing SNMP daemon..."
|
||||
opkg install snmpd snmp-utils
|
||||
|
||||
# Stop SNMP service to configure it
|
||||
echo "Stopping SNMP service..."
|
||||
/etc/init.d/snmpd stop
|
||||
|
||||
# Backup the original SNMP configuration file
|
||||
echo "Backing up the original configuration file..."
|
||||
cp /etc/config/snmpd /etc/config/snmpd.bak
|
||||
|
||||
# Configure SNMPv3
|
||||
echo "Configuring SNMPv3..."
|
||||
cat <<EOT > /etc/config/snmpd
|
||||
config agent
|
||||
option agentaddress 161
|
||||
option agentxsocket /var/agentx/master
|
||||
|
||||
config view
|
||||
option name all
|
||||
option type included
|
||||
option subtree .1
|
||||
|
||||
config access
|
||||
option groupname notConfigGroup
|
||||
option context ""
|
||||
option version v3
|
||||
option level authPriv
|
||||
option readview all
|
||||
option writeviewe
|
||||
option notifyview none
|
||||
|
||||
config user
|
||||
option name $SNMP_USER
|
||||
option authproto MD5
|
||||
option authpass $SNMP_PASSWORD
|
||||
option privproto AES
|
||||
option privpass $SNMP_PASSWORD
|
||||
|
||||
config system
|
||||
option location "$SYS_LOCATION"
|
||||
option contact "$SYS_CONTACT"
|
||||
EOT
|
||||
|
||||
# Restart and enable SNMP service
|
||||
echo "Starting and enabling SNMP service..."
|
||||
/etc/init.d/snmpd enable
|
||||
/etc/init.d/snmpd start
|
||||
|
||||
# Verify SNMP configuration
|
||||
echo "Verifying SNMP service..."
|
||||
snmpwalk -v3 -u $SNMP_USER -a MD5 -A $SNMP_PASSWORD -x AES -X $SNMP_PASSWORD -l authPriv localhost
|
||||
|
||||
echo "SNMPv3 installation and configuration complete on OpenWrt."
|
||||
@@ -0,0 +1,76 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Ensure the script is run as root
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
echo "This script must be run as root. Use sudo or run as root."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Starting SNMPv2 configuration on OpenWRT..."
|
||||
|
||||
# Install SNMP if not installed
|
||||
opkg update
|
||||
opkg install snmpd
|
||||
|
||||
# Define SNMP configuration file location
|
||||
SNMP_CONFIG="/etc/config/snmpd"
|
||||
|
||||
# Backup existing SNMP configuration
|
||||
if [ -f "$SNMP_CONFIG" ]; then
|
||||
echo "Backing up existing SNMP configuration..."
|
||||
cp "$SNMP_CONFIG" "$SNMP_CONFIG.bak"
|
||||
fi
|
||||
|
||||
# Create SNMPv2 configuration with public community
|
||||
echo "Configuring SNMPv2 with public community..."
|
||||
|
||||
cat <<EOL > "$SNMP_CONFIG"
|
||||
config system
|
||||
option enable '1'
|
||||
|
||||
config agent
|
||||
option agentaddress 'udp:161'
|
||||
|
||||
config com2sec
|
||||
option secname 'public'
|
||||
option source 'default'
|
||||
option community 'public'
|
||||
|
||||
config group
|
||||
option groupname 'publicGroup'
|
||||
option securitymodel 'v2c'
|
||||
option secname 'public'
|
||||
|
||||
config view
|
||||
option viewname 'all'
|
||||
option type 'included'
|
||||
option oid '.1'
|
||||
|
||||
config access
|
||||
option groupname 'publicGroup'
|
||||
option securitymodel 'v2c'
|
||||
option context 'none'
|
||||
option level 'noAuthNoPriv'
|
||||
option prefix 'exact'
|
||||
option read 'all'
|
||||
option write 'none'
|
||||
option notify 'none'
|
||||
EOL
|
||||
|
||||
# Restart the SNMP service to apply changes
|
||||
echo "Restarting SNMP service..."
|
||||
/etc/init.d/snmpd restart
|
||||
|
||||
# Verify if SNMP is running
|
||||
if pgrep snmpd > /dev/null; then
|
||||
echo "SNMP service is running."
|
||||
else
|
||||
echo "Failed to start SNMP service."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Test SNMPv2 configuration
|
||||
echo "Testing SNMPv2 configuration with snmpwalk..."
|
||||
snmpwalk -v2c -c public localhost system
|
||||
|
||||
echo "SNMPv2 configuration on OpenWRT completed successfully!"
|
||||
@@ -0,0 +1,93 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Exit on error
|
||||
set -e
|
||||
|
||||
# Confirm OpenWrt OS
|
||||
if ! grep -q "OpenWrt" /etc/os-release; then
|
||||
echo "❌ This script must be run on an OpenWrt device."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✔ OpenWrt detected: $(. /etc/os-release && echo $PRETTY_NAME)"
|
||||
|
||||
# Get SNMPv3 user info
|
||||
read -p "Enter SNMPv3 username (e.g., admin): " SNMP_USER
|
||||
read -s -p "Enter SNMPv3 password: " SNMP_PASSWORD
|
||||
echo
|
||||
read -s -p "Re-enter SNMPv3 password: " SNMP_PASSWORD_CONFIRM
|
||||
echo
|
||||
|
||||
if [ "$SNMP_PASSWORD" != "$SNMP_PASSWORD_CONFIRM" ]; then
|
||||
echo "❌ Passwords do not match. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
read -p "Enter SNMP system location (e.g., Router Closet): " SYS_LOCATION
|
||||
read -p "Enter SNMP system contact (e.g., admin@example.com): " SYS_CONTACT
|
||||
|
||||
# Install SNMP
|
||||
echo "📦 Installing snmpd and snmp-utils..."
|
||||
opkg update
|
||||
opkg install snmpd snmp-utils
|
||||
|
||||
# Stop service before config
|
||||
echo "🛑 Stopping SNMP service..."
|
||||
/etc/init.d/snmpd stop
|
||||
|
||||
# Backup config
|
||||
cp /etc/config/snmpd /etc/config/snmpd.bak.$(date +%s)
|
||||
|
||||
# Write SNMP config
|
||||
cat <<EOF > /etc/config/snmpd
|
||||
config agent
|
||||
option agentaddress '161'
|
||||
option agentxsocket '/var/agentx/master'
|
||||
|
||||
config system
|
||||
option location '$SYS_LOCATION'
|
||||
option contact '$SYS_CONTACT'
|
||||
|
||||
config view
|
||||
option name 'all'
|
||||
option type 'included'
|
||||
option subtree '.1'
|
||||
|
||||
config access
|
||||
option groupname 'notConfigGroup'
|
||||
option context ''
|
||||
option version 'v3'
|
||||
option level 'authPriv'
|
||||
option readview 'all'
|
||||
option writeview 'all'
|
||||
option notifyview 'all'
|
||||
|
||||
config user
|
||||
option name '$SNMP_USER'
|
||||
option authproto 'MD5'
|
||||
option authpass '$SNMP_PASSWORD'
|
||||
option privproto 'AES'
|
||||
option privpass '$SNMP_PASSWORD'
|
||||
EOF
|
||||
|
||||
# Enable and start SNMP
|
||||
echo "🚀 Starting SNMP service..."
|
||||
/etc/init.d/snmpd enable
|
||||
/etc/init.d/snmpd start
|
||||
|
||||
# Configure firewall
|
||||
echo "🔐 Adding firewall rule to allow SNMP on LAN (UDP/161)..."
|
||||
uci add firewall rule
|
||||
uci set firewall.@rule[-1].name='Allow-SNMP'
|
||||
uci set firewall.@rule[-1].src='lan'
|
||||
uci set firewall.@rule[-1].proto='udp'
|
||||
uci set firewall.@rule[-1].dest_port='161'
|
||||
uci set firewall.@rule[-1].target='ACCEPT'
|
||||
uci commit firewall
|
||||
/etc/init.d/firewall restart
|
||||
|
||||
# Test SNMP locally
|
||||
echo "🧪 Running SNMPv3 test on localhost..."
|
||||
snmpwalk -v3 -u "$SNMP_USER" -l authPriv -a MD5 -A "$SNMP_PASSWORD" -x AES -X "$SNMP_PASSWORD" localhost
|
||||
|
||||
echo "✅ SNMPv3 successfully configured on OpenWrt ${PRETTY_NAME}"
|
||||
@@ -0,0 +1,16 @@
|
||||
# system_command_run
|
||||
|
||||
## Overview
|
||||
Tools for running commands across multiple machines using shell and Python helpers with a shared machine list.
|
||||
|
||||
## Contents
|
||||
- `Run_command_on_machines.sh`
|
||||
- `machines.txt`
|
||||
- `run_command_on_machines.py'`
|
||||
- `run_command_on_machines_Keys.py'`
|
||||
|
||||
## Usage
|
||||
Review the machine list and command runner settings before using this folder on a live environment.
|
||||
|
||||
## Notes
|
||||
Remote command execution can be high impact, so start with safe commands and verify connectivity assumptions.
|
||||
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
|
||||
MACHINE_FILE="machines.txt"
|
||||
LOG_FILE="ssh_command_log.txt"
|
||||
|
||||
echo -n "Enter command to execute: "
|
||||
read COMMAND
|
||||
|
||||
echo "Executing on all machines..."
|
||||
echo "Execution Log - $(date)" > "$LOG_FILE"
|
||||
|
||||
while IFS=" " read -r HOST USER PASS; do
|
||||
echo "Running on $HOST..."
|
||||
if [[ -z "$PASS" ]]; then
|
||||
ssh "$USER@$HOST" "$COMMAND" >> "$LOG_FILE" 2>&1
|
||||
else
|
||||
sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no "$USER@$HOST" "$COMMAND" >> "$LOG_FILE" 2>&1
|
||||
fi
|
||||
done < "$MACHINE_FILE"
|
||||
|
||||
echo "Execution complete. Logs saved in $LOG_FILE."
|
||||
@@ -0,0 +1 @@
|
||||
docker1 root
|
||||
Whitespace-only changes.
@@ -0,0 +1,30 @@
|
||||
def execute_command(hostname, username, command):
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
|
||||
try:
|
||||
ssh.connect(hostname, username=username, key_filename="~/.ssh/id_rsa", timeout=5)
|
||||
stdin, stdout, stderr = ssh.exec_command(command)
|
||||
output = stdout.read().decode().strip()
|
||||
error = stderr.read().decode().strip()
|
||||
|
||||
with open(LOG_FILE, "a") as log:
|
||||
log.write(f"----- {hostname} ({username}) -----\n")
|
||||
log.write(f"Command: {command}\n")
|
||||
log.write(f"Output:\n{output}\n")
|
||||
if error:
|
||||
log.write(f"Errors:\n{error}\n")
|
||||
log.write("\n")
|
||||
|
||||
print(f"[{hostname}] Command executed successfully.")
|
||||
if error:
|
||||
print(f"[{hostname}] ERROR: {error}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"[{hostname}] Connection failed: {e}")
|
||||
with open(LOG_FILE, "a") as log:
|
||||
log.write(f"----- {hostname} ({username}) -----\n")
|
||||
log.write(f"ERROR: {e}\n\n")
|
||||
|
||||
finally:
|
||||
ssh.close()
|
||||
@@ -0,0 +1,14 @@
|
||||
# telegraf-setup-scripts
|
||||
|
||||
## Overview
|
||||
Scripts for installing or updating Telegraf clients, including variants that work with key material.
|
||||
|
||||
## Contents
|
||||
- `install-client.sh`
|
||||
- `update-telegraf-w-keys.sh`
|
||||
|
||||
## Usage
|
||||
Use these scripts to bootstrap or refresh Telegraf on monitored clients.
|
||||
|
||||
## Notes
|
||||
Agent rollout normally requires valid output configuration and reachable monitoring backends.
|
||||
@@ -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