I am trying to configure snmp v2 on a ESXi server through vSphere Power CLI 5.0. I tried to use the following cmd
$hostSNMP = Get-VMHostSNMP
$hostSNMP = Set-VMHostSNMP $hostSNMP -Enabled:$true -ReadOnlyCommunity 'public'
but i am unable to get the output for "Get-VMHostSNMP" cmd, so as to execute the above cmd.
snippet:
-----------
Does it mean snmp is not configured in the ESXi server or am i mising smething here ?
Also please let me know the cmd to configure snmpv2 on an ESXi server ?
Check firewall SNMP uses incoming port 161,,
First of all welcome to community
As far as I know, when you running commands like "$hostSNMP = Get-VMHostSNMP" the result would be inserted to the variable ($hostSNMP) and would not be shown unless you call or use them.
If it's possible run "Get-VMHostSNMP" and if you got the result you looked for run two bellow lines.
$hostSNMP = Get-VMHostSNMP
$hostSNMP
The output would be the same but while runnning second commands you have the result in variable which you can use later on.
And don't forget to check firewall on your host, you might enable the service and defined a community string for SNMP but it will not be useful unless you open the firewall port for it.
* Also, "Get-VMHostSNMP | Select *" would show you if SNMP is configured on the host and the current config like trap target and community string
I would think the reason why you are getting no results is because "Get-VMHostSnmp" runs against ESX/ESXi hosts not vCenter Servers.let me explain
..if you login to vCenter and expect things to be ok, you will get nothing
[vSphere PowerCLI] C:\> Get-VC vcenterserver
[vSphere PowerCLI] C:\> Get-VMHostSnmp
-> Empty/not results
..now if you connect to one or more of your ESX hosts directly, you should get results
[vSphere PowerCLI] C:\> Connect-VIServer esxserver1
[vSphere PowerCLI] C:\> Get-VMhostSnmp
Enabled Port ReadOnly Communities
------- ---- --------------------
True 161 {myrocomstr}
I hope this helps.
Teiva
I'm experiencing the same issue while connected directly to my ESXi 5.1 hosts using PowerCLI. I execute the command...
get-vmhostsnmp
No results
I am also surprise at the results. At minimum it should show that it's is not enabled like this
Enabled Port ReadOnly Communities
------- ---- --------------------
False 161 {}
How about if you do this store the connection into a variable like this
[vSphere PowerCLI] C:\> $esxhost = get-vc <yourhostname>
..login.
[vSphere PowerCLI] C:\> Get-VMHostSnmp -server $esxhost
if that doesn't work, try with the Perl script instead of the Powershell command and see if they work ?
~~~~~~~~ example ~~~~~~~~~~~~~
C:\Program Files (x86)\VMware\VMware vSphere CLI\bin>vicfg-snmp.pl -s -server <servername>
Enter username: root
Enter password:
Let me know what you find. I am also interested in know what the outcome of this is.
Good luck.
Teiva
Login to your host via ssh and check the `esxcli system snmp get` command. Do you receive an error instead of a list of SNMP service values? If so that is your problem, mine was:
"Community string was not specified in trap target: A.B.C.D"
It turned that while adding a target with Set-VMHostSnmp somehow it took the -TargetHost but did not properly set the -TargetCommunity. Even though I received an error it appears it still changed the /etc/vmware/snmp.xml file. Specifically setting a target without its port and community (eg. <targets>192.168.1.1</targets> instead of <targets>192.168.1.1@162 public</targets>). This appeared to lock every form of snmp management (PowerCLI, vSphere CLI/vicfg-snmp & esxcli). When I attempted to perform a factory reset with `esxcli system snmp set --reset` it still errors about the target missing its community, and then fails to reset properly. I had to manually edit the config file to repair (or just remove the target) and then restart snmpd. Afterwords the error is cleared up and you can once again perform a Get-VMHostSnmp and store the object within PowerCLI.
However seeing as there was an issue in PowerCLI that somehow set an invalid configuration, I decided to instead use `esxcli system snmp {cmd} [cmd options]` to configure any ESXi VM Host with SNMP service/configuration issues.
Hope this helps,
Trevor