Skip to content
Snippets Groups Projects

SNMP Install - Ubuntu

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Adphi
    sh -c "$(curl -fsSL https://gitlab.bertha.cloud/snippets/14/raw)"
    Edited
    snmp-install.sh 1.84 KiB
    #!/usr/bin/env bash
    
    set -e
    
    SNMP_COMMUNITY="${SNMP_COMMUNITY:-partitio}"
    SNMP_CONTACT_NAME="${SNMP_CONTACT_NAME:-partitio}"
    SNMP_CONTACT_ADDRESS="${SNMP_CONTACT_ADDRESS:-assistance@partitio.com}"
    SNMP_ENABLE_EXTENSIONS="${SNMP_ENABLE_EXTENSIONS:-}"
    
    sudo apt-get update && sudo apt-get install -y curl snmpd
    cat << EOF | sudo tee /etc/snmp/snmpd.conf
    com2sec readonly  default         ${SNMP_COMMUNITY}
    
    group ReadOnly v2c        readonly
    view all    included  .1                               80
    access ReadOnly ""      any       noauth    exact  all    none   none
    
    syslocation Rack, Room, Building, City, Country [GPSX,Y]
    syscontact ${SNMP_CONTACT_NAME} ${SNMP_CONTACT_ADDRESS}
    
    #Distro Detection
    extend .1.3.6.1.4.1.2021.7890.1 distro /usr/bin/distro
    EOF
    
    if [[ -n "${SNMP_ENABLE_EXTENSIONS}" ]]; then
      cat << EOF | sudo tee -a /etc/snmp/snmpd.conf
    #Hardware Detection
    extend .1.3.6.1.4.1.2021.7890.2 hardware '/bin/cat /sys/devices/virtual/dmi/id/product_name'
    extend .1.3.6.1.4.1.2021.7890.3 manufacturer '/bin/cat /sys/devices/virtual/dmi/id/sys_vendor'
    extend .1.3.6.1.4.1.2021.7890.4 serial '/bin/cat /sys/devices/virtual/dmi/id/product_serial'
    EOF
    fi
    
    sudo curl -o /usr/bin/distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro
    sudo chmod +x /usr/bin/distro
    sudo systemctl restart snmpd
    
    REGISTER_HOSTNAME="$(hostname -I|cut -d' ' -f1)"
    SNMP_COMMUNITY="${COMMUNITY:-partitio}"
    SNMP_VERSION="${SNMP_VERSION:-v2c}"
    LIBRENMS="${LIBRENMS:-192.168.52.117}"
    
    echo "Registering to LibreNMS($LIBRENMS) $REGISTER_HOSTNAME Community: $SNMP_COMMUNITY VERSION: $SNMP_VERSION"
    
    curl --header "Content-Type: application/json" \
       --header "X-Auth-Token: a2096d515787040a9cacab57e8cded18" \
       --request POST \
       --data "{\"hostname\":\"$REGISTER_HOSTNAME\",\"version\":\"$SNMP_VERSION\",\"community\":\"$SNMP_COMMUNITY\"}" \
       http://$LIBRENMS/api/v0/devices
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment