Hi All
Found a code snippet from LucD on here to enable SNMP on a Vsphere 4 host. I then tacked on the firewall exceptions to allow SNMP through the firewall, that works...not I need to make PowerCLi start the SNMP deamon on the server
How is that accomplished ?
If I do a Get-VMHostService -Host myhost , SNMP is not listed as a service to start ?
What Am I missing please ?
Thanks
Updated: sorry wrong answer
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It is already set LucD ( I borrowed your code with a few minor modifications - thanks !).
The firewall exception is added at the bottom. Please comment on what I'm missing and if this is sufficient to set up SNMP to a fully functional state
Clear$esxName = Read-Host "Name of ESX Server"$esxImpl = Get-VMHost -Name $esxName$trapDestination = Read-Host "SNMP Management Server ?"$trapCommunity = Read-Host "Community String ?"# Connect to the ESX server$esxConnect = Connect-VIServer -Server $esxName -Credential (Get-Credential)# Get snmp object$snmpObj = Get-VMHostSnmp -Server $defaultViServer# Clear snmp configurationSet-VMHostSnmp -HostSnmp $snmpObj -ReadOnlyCommunity @() -RemoveTarget -TrapTargetToRemove $snmpObj.TrapTargets[0]# Enable snmpSet-VMHostSnmp -HostSnmp $snmpObj -Enabled:$true# Set read-only communitySet-VMHostSnmp -HostSnmp $snmpObj -ReadOnlyCommunity $trapCommunity# Define trap targetSet-VMHostSnmp -HostSnmp $snmpObj -AddTarget -TargetCommunity $trapCommunity -TargetPort '162' -TargetHost $trapDestination# Test snmpTest-VMHostSnmp -HostSnmp $snmpObj#Enable Firewall RuleGet-VMHostFirewallException | ?{$_.Name.StartsWith('SNMP')} | Set-VMHostFirewallException -Enabled $true#Start SNMP HERE ????? SNMPD Service shows STOPPED on the server......# Disconnect from ESX serverDisconnect-VIServer -Server $esxConnect -Confirm:$false
I just compared this host to others that do work ( not configured with PowerCLI ), and the Firewall has not been opened for those hosts, so the firewall exception may be moot.
I'm a bit stuck now.
What does
Get-VMHostFirewallException -VMHost $esx | where {$_.Name -like "SNMP*"}
return ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Name Enabled IncomingPorts OutgoingPorts Protocols ServiceRunning---- ------- ------------- ------------- --------- --------------SNMP Server False 161 162 UDPI must say that Our management server ( Solarwinds ) only polls the servers, they do not need to send traps....
I managed to get it to work using the vicfg-snmp.pl script in the VsphereCLI ( even without having to allow the firewall ports ), but don't know why it did not want to work with POWERCLI.....
Thanks
The SNMP service is not enabled.
Does a
$esxSNMP = Get-VMHostSnmp
Set-VMHostSNMP $esxSNMP -Enabled:$true
change this ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
If you look at the original script it is there...., and when I run a Get-VMHostSNMP afterwards - it shows that the Agent is enabled.
EDIT: Just a thought , but should the agent not be enabled AFTER all the community strings and such are added. ? In the original script - I notice it is enabled before all this happens ?
I just asked because in your last output the Enabled property shows $false.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I also made a quick and dirty with vicfg-snmp as well and use command line variables for the specifics.
/usr/bin/vicfg-snmp --server $1 -c public --username root --password $3
/usr/bin/vicfg-snmp --server $1 -E --username root --password $3
/usr/bin/vicfg-snmp --server $1 -t $2@162/public --username root --password $3
/usr/bin/vicfg-snmp --server $1 -T --username root --password $3