VMware Cloud Community
Fjorko
Contributor
Contributor

Enable SNMP via POWERCLi - almost there, need help to start it...

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

0 Kudos
9 Replies
LucD
Leadership
Leadership

Updated: sorry wrong answer


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Fjorko
Contributor
Contributor

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 configuration
Set-VMHostSnmp -HostSnmp $snmpObj -ReadOnlyCommunity @() -RemoveTarget -TrapTargetToRemove $snmpObj.TrapTargets[0]
# Enable snmp
Set-VMHostSnmp -HostSnmp $snmpObj -Enabled:$true
# Set read-only community
Set-VMHostSnmp -HostSnmp $snmpObj -ReadOnlyCommunity $trapCommunity
# Define trap target
Set-VMHostSnmp -HostSnmp $snmpObj -AddTarget -TargetCommunity $trapCommunity -TargetPort '162' -TargetHost $trapDestination
# Test snmp
Test-VMHostSnmp -HostSnmp $snmpObj
#Enable Firewall Rule
Get-VMHostFirewallException | ?{$_.Name.StartsWith('SNMP')} | Set-VMHostFirewallException -Enabled $true
#Start SNMP HERE ????? SNMPD Service shows STOPPED on the server......
# Disconnect from ESX server
Disconnect-VIServer -Server $esxConnect -Confirm:$false

0 Kudos
Fjorko
Contributor
Contributor

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.

0 Kudos
LucD
Leadership
Leadership

What does

Get-VMHostFirewallException -VMHost $esx | where {$_.Name -like "SNMP*"}

return ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Fjorko
Contributor
Contributor

Name                 Enabled IncomingPorts  OutgoingPorts  Protocols  ServiceRunning
----                 ------- -------------  -------------  ---------  --------------
SNMP Server          False   161            162            UDP

I 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

0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
Fjorko
Contributor
Contributor

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 ?

0 Kudos
LucD
Leadership
Leadership

I just asked because in your last output the Enabled property shows $false.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
fmash
Contributor
Contributor

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
0 Kudos