PoshCode Archive  Artifact [a073579aa6]

Artifact a073579aa6c34430d08e9665324379bbe30ff13993d52a33ddd324b91753c724:

  • File Send-SNMP-trap.ps1 — part of check-in [70a2ccfd4b] at 2018-06-10 13:46:32 on branch trunk — 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: (user: halr9000 size: 1272)

# encoding: ascii
# api: powershell
# title: Send SNMP trap
# description: 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:
# version: 1.3.6
# author: halr9000
# license: CC0
# x-poshcode-id: 4835
# x-archived: 2015-07-20T04:32:25
# x-published: 2015-01-23T18:29:00
#
# 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 )
)