PoshCode Archive  Artifact Content

Artifact 657f4bda2a700971c5557e7d9606c2da0a47f193ae94081f3c715bbdb54a4857:

  • File Send-SNMP-trap.ps1 — part of check-in [f2639ddf2a] at 2018-06-10 14:18:34 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: amber size: 1269)

# 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: amber
# license: CC0
# x-poshcode-id: 6622
# x-archived: 2017-03-15T18:59:01
# x-published: 2017-11-12T16:31: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 )
)