Setup SNMP: VMware ESXi via vMA

Do you have an SNMP monitor you would like to tie together with your VMware infrastructure? Do you want to set this up quickly and efficiently?

If you answered ‘yes’ to both of those questions then continue reading this post!

There are 2 ways to do this – one is to loop through requesting the password from the user for each host (if each host has a different root password), or using the vifp and vifptarget commands (which come in handy for other scriptable items). using vifp/viptarget is another subject, possibly for a different blog post.

First – let me push out a shameless plug for LogicMonitor – the best tool I have found for doing monitoring and measurement of my hosts since 2011. I don’t work there and I get nothing for mentioning their name; I just feel that they are the best so far and deserve the kudos.

Second, create a text file with either host names or IP addresses, like so:

and we will use this as input to the for loop.


# set username for authentication, normally this is 'root'

# set SNMP community string - don't use public

# SNMP trap receiver IP address

# within the for loop it will prompt you for each host's
# root password. This section could be commented out if
# you have already set up vifp parameters

for host in `cat that-text-file.txt` ; do
  echo -n "Enter ${host} root password: "

  # now the good parts

  # set the port and community
  esxcfg-snmp -server ${host} -p 161 -c $COMMUNITY

  # enable SNMP
  esxcfg-snmp -server ${host} -E

  # send traps to your SNMP trap receiver
  esxcfg-snmp -server ${host} -t ${TRAPRECV}@162/${COMMUNITY}

  # SNMP can be a bit noisy about things, so map out some OIDs
  # that you probably don't wanna see anyway as I haven't seen
  # these being useful at all
  esxcfg-snmp --server ${host} -n \,,\,,\


There you have it, simple, quick, efficient.

Updated: Setting trap receiver uses ‘-t’ (lowercase) instead of ‘-T’ (uppercase) from vMA 5.1 to ESXi v5.1. Hat tip to @vglen_mpls (Glen) for finding this so I could update this post!