我试图发送SNMP陷阱用PowerShell脚本(它必须是一个PowerShell脚本,它会在Windows服务器上运行)。 我有了一个陷阱reciever测试环境中运行。
我一直在关注这个教程http://www.activexperts.com/network-component/howto/snmpts/powershell10/ ,但我还没有得到它的工作。
下面是我的代码,脚本运行罚款
$objSnmpTrapManager = new-object -comobject AxNetwork.DnsServer #create object
# Create a SnmpTrapOut instance
$objSnmpTrapManager = new-object -comobject AxNetwork.SnmpTrapManager
$objSnmpTrap = new-object -comobject AxNetwork.SnmpTrap
$objSnmpObject = new-object -comobject AxNetwork.SnmpObject
$objConstants = new-object -comobject AxNetwork.NwConstants
# Initialize SNMP
$objSnmpTrapManager.Initialize()
$res = "Initialize, result: " + $objSnmpTrapManager.LastError + " (" + $objSnmpTrapManager.GetErrorDescription( $objSnmpTrapManager.LastError ) + ")"
Write-Host $res
If($objSnmpTrapManager.LastError -ne 0 )
{
exit
}
# Get Host, community name and optionally a MIB file
$strHostName = "*******"
$strCommunity = "public"
# Set trap properties
$objSnmpTrap.Clear()
$objSnmpTrap.Host = $strHostName
$objSnmpTrap.Community = $strCommunity
$objSnmpTrap.Port = 80 #is this the port that my trap reciever is looking at? or should it be the default 162
# Add first variable to trap
$objSnmpObject.Clear()
$objSnmpObject.OID = ".1.3.6.1.2.1.1.5.0"
$objSnmpObject.Type = $objConstants.nwSNMP_TYPE_OCTETSTRING
$objSnmpObject.Value = "test"
$objSnmpTrap.AddObject($objSnmpObject)
# Send the trap.
$objSnmpTrapManager.Send($objSnmpTrap)
$res = "Send, result: " + $objSnmpTrapManager.LastError + " (" + $objSnmpTrapManager.GetErrorDescription($objSnmpTrapManager.LastError) + ")"
Write-Host $res
# Shutdown SNMP
$objSnmpTrapManager.Shutdown()
$res = "Shutdown, result: " + $objSnmpTrapManager.LastError + " (" + $objSnmpTrapManager.GetErrorDescription($objSnmpTrapManager.LastError) + ")"
Write-Host $res
说的一切成功,我想我的问题是定义在哪里送我的陷阱的位置(如果有人可以提供这将是真棒一个例子!)
没有人有任何帮助或资源,他们会很愿意分享?
谢谢!