Sunday, April 27, 2014

Configuring and testing SNMP traps in esxi server

I am fond of and very comfortable with powercli when doing activities on vsphere environment, but this time I thought let’s try vsphere cli for as a automation tool. My monitoring team asked to configure SNMP on all esxi servers in my organization, I generally follow vmware kb and found I will require to use vsphere cli for the same (It is possible to configure SNMP from Powercli as well I have posted the script in the end)

What is SNMP - is a standard protocol for network monitoring and network devices management. Almost all active network devices support SNMP. Moreover, SNMP is supported by the majority of operational systems and by many network applications.

I downloaded and installed vsphere cli from

Once you open the command prompt for vsphere cli, change the directory to bin, if you dir you will find Perl scripts.

Below command shows current SNMP configuration on the esxi server --server –username root –password Computer@1 --show

This will set snmp server settings on the esxi server --server –username root –password Computer@1 –t -c vcloud -E
In the screenshot I already have mentioned what the parameters are

Final show command to view the configured settings.

How do you quick test SNMP whether setting or working or not?
Here I have downloaded snmpwalk tool from and extracted to one of windows server in the network

Open command prompt on the server and run the utility with parameters. Good help is available about the tool.

snmpWalk.exe –r: –c:vcloud

-r: = esxi server where settings are configured
-c:vcloud = Community string.

If everything is fine it will get response from the esxi server.
(In the case you are using linux run command snmpwalk -v2c -c rageesx

On the esxi server you can verify connection success 

Configuring SNMP on esxi host with powercli
Run get-vmhostsnmp to fetch information

And below screenshot command will set the configuration.

If you have lots of esxi server and want to automate it (esxi server with same password), you can use below script to automate on all esxi servers.

Add-PSSnapin vmware.vimautomation.core
$root = "root"
$password = "Password"
$Listofesxi = "esxi001.vcloud.lab", "esxi002.vcloud.lab", "esxi003.vcloud.lab"

foreach ($esxi in $Listofesxi) {
    Connect-VIServer $esxi -User $root -Password $password
    Set-VMHostSnmp (Get-VMHostSnmp) -ReadOnlyCommunity vcloud -Enabled $true
    Disconnect-VIServer * -Confirm $false

No comments: