Aus aktuellem Anlass habe ich mir zwei kleine Skripte geschrieben, die SNMP auf Windows bzw. Debian/Ubuntu aktivieren und die passenden Konfigurationsparameter in der Konfiguration bzw. Registry setzten.

PowerShell Variante

Ebenfalls zu finden als Github Gist.

#
# Author: Jan Gilla
# Company: level66.network UG (haftungsbeschränkt)
# Description: PowerShell script to install snmpd daemon on windows systems, generate the configuration and reload the service.
#
 
# Define variables here.
$SNMPD_COMMUNITY = "public"
$SNMPD_LOCATION = "Milki Way"
$SNMPD_CONTACT = "test@example.com"
 
# Do not change anything below here!
Write-Host "Installing snmpd service via Windows Features ..."
Import-Module ServerManager
Install-WindowsFeature SNMP-Service | Out-Null
Install-WindowsFeature SNMP-WMI-Provider | Out-Null
 
Write-Host "Deploy configuration to service ..."
Set-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\RFC1156Agent -Name sysLocation -Type String -Value $SNMPD_LOCATION
Set-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\RFC1156Agent -Name sysContact -Type String -Value $SNMPD_CONTACT
Set-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\ValidCommunities -Name $SNMPD_COMMUNITY -Type DWord -Value 0x4
try {
    if(Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\PermittedManagers -Name 1 -eq true){
        Remove-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\PermittedManagers -Name 1
    }
}catch {}
 
Write-Host "Restart snmpd service via systemd ..."
Restart-Service -Name SNMP

BASH Variante (Github Gist)

Ebenfalls zu finden als Github Gist.

#!/bin/bash
#
# Author: Jan Gilla
# Company: level66.network UG (haftungsbeschränkt)
# Description: BASH script to install snmpd daemon on Debian/Ubuntu based linux systems, generate the configuration and reload the service by using systemd.
#
 
# Define variables here.
SNMPD_COMMUNITY=public
SNMPD_LOCATION="Milki Way"
SNMPD_CONTACT=test@example.com
 
# Do not change anything below here!
echo "Installing snmpd service via apt-get ..."
/usr/bin/apt-get update
/usr/bin/apt-get install snmpd lm-sensors --yes
 
echo "Deploy configuration to /etc/snmp/snmpd.conf ..."
cat <<EOF > /etc/snmp/snmpd.conf
# Listen on all ips
agentAddress udp:161,udp6:[::]:161
 
# Device information
syslocation $SNMPD_LOCATION
syscontact $SNMPD_CONTACT
 
# SNMPv2
rocommunity $SNMPD_COMMUNITY
rocommunity6 $SNMPD_COMMUNITY
EOF
 
echo "Restart snmpd service via systemd ..."
/usr/bin/systemctl restart snmpd.service
/usr/bin/systemctl status snmpd.service --plain