Enabling SNMP on your VMware host

If you’re like me, you like to have monitoring running against, well, pretty much everything.  vSphere vCenter has pretty good alerting but I also have an SNMP monitor that I can use.  Today, I’m going to show you how to enable SNMP on your ESXi hosts.

Enabling SNMPd

In this section, I’m using the VIC against 5.1, but you can do it in the web client on 5.5 just as easily.  On your host’s configuration tab in the Security Profile section you’ll find the SNMPd service.  Click properties, select SNMPd and then click the Options button.  You’ll want to make sure that it’s set to either start with the host or start if the firewall ports are open, depending on your security model and requirements.



When you click the “Start” button, you may receive an error similar to this one:

 system.start for object serviceSystem-10 on vcenter server <your server name here> failed

If that happens, fire up your SSH utility and jump onto the host.  You’ll want to edit /etc/vmware/snmpd.xml (be sure to back it up first!)  At the beginning of the line, change “false” to “true”, save the file, and then start the SNMPd service again:

<?xml version="1.0"?>

You can also do this with esxcli:

esxcli system snmp set --enable true

Defining SNMP communities

Ok, so your SNMPd service is running.  Big deal.  You still need to set your community strings.

With esxcli from your SSH session:

 esxcli system snmp set --communities <your strings separated by commas>

You can also use this command to set SNMPv3 authentication, targets, traps, and so forth.  Use esxcli system snmp set –help  for the complete syntax and list of options.

Oh, what’s that you say?  You have lots of hosts and you want to use Powershell to do them all at once?  Frank’s Tech Support and Pretty Good Sandwiches has got you covered.  Here’s a little tasty scripty script, right from the oven!

# PowerCLI Script for Enabling SNMP and setting Community Strings
# In the variable lines, keep the quotes but lose the < and >.
$vis = "<your vCenter Server>"
$user = "<your vCenter User>"
$pass = "<your vCenter Pass>"
$communities = "<your Community string>"
$syslocation = "<your syslocation>"

Connect-VIServer -Server $vis -User $user -Password $pass
$hosts = @(Get-VMHost)

# Configure SNMP on each host in vCenter
foreach ($host in $hosts) {
Write-Host ‘$host = ‘ $host
$esxcli = Get-EsxCli -VMHost $host

Disconnect-VIServer * -Confirm:$false

Stay frosty, my friends!