PowerCLI

 View Only
  • 1.  Enable SNMP via POWERCLi - almost there, need help to start it...

    Posted Sep 14, 2011 07:14 AM

    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



  • 2.  RE: Enable SNMP via POWERCLi - almost there, need help to start it...

    Posted Sep 14, 2011 07:42 AM

    Updated: sorry wrong answer



  • 3.  RE: Enable SNMP via POWERCLi - almost there, need help to start it...

    Posted Sep 14, 2011 07:55 AM

    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



  • 4.  RE: Enable SNMP via POWERCLi - almost there, need help to start it...

    Posted Sep 14, 2011 11:21 AM

    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.



  • 5.  RE: Enable SNMP via POWERCLi - almost there, need help to start it...

    Posted Sep 14, 2011 01:27 PM

    What does

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

    return ?



  • 6.  RE: Enable SNMP via POWERCLi - almost there, need help to start it...

    Posted Sep 14, 2011 02:49 PM

    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



  • 7.  RE: Enable SNMP via POWERCLi - almost there, need help to start it...

    Posted Sep 14, 2011 03:29 PM

    The SNMP service is not enabled.

    Does a

    $esxSNMP = Get-VMHostSnmp
    Set-VMHostSNMP $esxSNMP -Enabled:$true

    change this ?



  • 8.  RE: Enable SNMP via POWERCLi - almost there, need help to start it...

    Posted Sep 15, 2011 08:49 AM

    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 ?



  • 9.  RE: Enable SNMP via POWERCLi - almost there, need help to start it...

    Posted Sep 15, 2011 08:51 AM

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



  • 10.  RE: Enable SNMP via POWERCLi - almost there, need help to start it...

    Posted Sep 16, 2011 06:58 PM

    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