Setup SNMP on VMware ESXi Hosts

You are here:
< Back

Goal / Scope

Enable the ability to monitor and report on ESXi servers using SNMP

Background

By default the SNMP functionality is disabled in ESXi servers.  Also, simply attempting to start the service via the GUI interface fails with an error.  A little tweaking is required to get the SNMP service up and running on an ESXi host.

Methodology / Process Steps

Running the following commands on individual ESX hosts from a console session will allow SNMP service to be started. Replace [STRING] with the community string to be used. The first commands set the community strings (or names) and enables SNMP on the system.  The next commands set the firewall to allow everything to poll SNMP.  The last command restarts the snmp daemon, but the service still needs to be started in the GUI.

esxcli system snmp set --communities [STRING]
esxcli system snmp set --enable true
esxcli network firewall ruleset set --ruleset-id snmp --allowed-all true
esxcli network firewall ruleset set --ruleset-id snmp --enabled true
/etc/init.d/snmpd restart

The firewall rules can be changed so only a specific subnet or host will be allowed if required.

esxcli network firewall ruleset set --ruleset-id snmp --allowed-all false
esxcli network firewall ruleset allowedip add --ruleset-id snmp --ip-address 10.0.1.0/24
esxcli network firewall ruleset set --ruleset-id snmp --enabled true
/etc/init.d/snmpd restart

Below is code borrowed from everythingshouldbevirtual.com to use PowerCLI.  The PowerCLI allows setup / configuration of SNMP on all hosts configured in vCenter.

# PowerCLI Script for adding syslogserver to hosts
# @mrlesmithjr
# EverythingShouldBeVirtual.com
# Change the following to match your environment
# vi_server is your vCenter
$vi_server = “vcenterservername”
$vcuser = "vcenterserverusername"
$vcpass = "vcenterserverpassword"
$communities = "public"
$syslocation = "Atlanta"

Connect-VIServer -Server $vi_server -User $vcuser -Password $vcpass

# Setup variable to use in script for all hosts in vCenter
$vmhosts = @(Get-VMHost)

# Configure syslog on each host in vCenter
foreach ($vmhost in $vmhosts) {
Write-Host ‘$vmhost = ‘ $vmhost
$esxcli = Get-EsxCli -VMHost $vmhost
$esxcli.system.snmp.set($null,$communities,"true",$null,$null,$null,$null,$null,$null,$null,$null,$null,$syslocation)
$esxcli.system.snmp.get()
}

Disconnect-VIServer * -Confirm:$false

 

Known Issues / Troubleshooting

This section is for the issues that have well defined and tested solutions.

Problem: | SNMP service is not an option on the virtual host
Solution: | still working on a resolution
 
Problem: |
Solution: |

References

PowerCLI Script

http://www.everythingshouldbevirtual.com

Last Updated On October 24, 2017