#!/bin/bash # install snmp monitoring and configures it # createUser SHA "" AES "" # rouser # #rwuser # make sure we are running as sudo if [ "$EUID" -ne 0 ]; then echo "Please run as root" exit fi if [ -f /etc/debian_version ]; then apt update apt install -y snmpd curl elif [ -f /etc/redhat-release ]; then dnf install -y net-snmp net-snmp-utils curl firewall-cmd --zone=public --add-service=snmp --permanent firewall-cmd --reload else echo "You are running an unsupported OS" echo "Support OSes: Debian, Ubuntu, CentOS/Rocky 8/9" echo "Your OS: ${OS} ${OS_VER}" exit fi # back the original config file mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak # generate useranme/auth/enc passwords username=$(openssl rand -hex 8) authPassword=$(openssl rand -hex 32) encPassword=$(openssl rand -hex 32) # create new config file cat <> /etc/snmp/snmpd.conf CreateUser ${username} SHA ${authPassword} AES ${encPassword} rouser ${username} priv .1 syslocation Rack, Room, Building, City, Country [GPSX,Y] syscontact Your Name #Distro Detection extend .1.3.6.1.4.1.2021.7890.1 distro /usr/bin/distro EOF # download distro script curl -o /usr/bin/distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro chmod +x /usr/bin/distro systemctl restart snmpd systemctl enable snmpd echo "#########################################################################" echo "## Encryption Details ##" echo "## Please enter the Username and Auth/Enc Passwords on Libernms Server ##" echo "#########################################################################" echo "Username = ${username}" echo "Auth (SHA) Password = ${authPassword}" echo "Enc (AES) Password = ${encPassword}"