Send SNMP trap by halr9000 27 months ago
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1413"></script>download | new post
This will send an SNMP trap to the specified manager (hostname). The script isn’t very flexible, but it’s a good example of how to build traps using SharpSNMPLib. External requirementss:
- Two DLLs (see below) from SharpSNMPLib project: http://sharpsnmplib.codeplex.com/
- New-GenericObject.ps1 script from http://www.leeholmes.com/blog/CreatingGenericTypesInPowerShell.aspx (also in poshcode)
- Param ( $DestinationHost )
- Add-Type -Path "C:\Program Files\LeXtudio Software\sharpsnmplib.dll"
- Add-Type -Path "C:\Program Files\LeXtudio Software\SharpSnmpLib.Controls.dll"
- $manager = [system.Net.Dns]::Resolve( $DestinationHost ).AddressList[0]
- $TrapDest = New-Object Net.IPEndPoint( $manager, 162 )
- [Lextm.SharpSnmpLib.Messaging.Messenger]::SendTrapV1( $TrapDest,
- [IPAddress]::Loopback,
- [Lextm.SharpSnmpLib.OctetString]"public",
- [Lextm.SharpSnmpLib.ObjectIdentifier]"1.3.6",
- [Lextm.SharpSnmpLib.GenericCode]::ColdStart,
- 0,
- 0,
- ( New-GenericObject.ps1 system.collections.generic.list lextm.sharpsnmplib.variable )
- )
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
PowerShell Code Repository