|
SendTrap
int
SendTrap(string
ipAddress, string enterpriseOid,
inttrapCode,
snmppdu
pdu)
Return
Value
Returns
OK if success. Otherwise returns FAIL.
Parameters
ipAddress
–the IP address
of the SNMP manager.
Note: The
following syntax of ipAddress provides the ability to specify the
SNMP trap port value: ipAddress:Port
Example:
“65.35.64.170:3000”
If SNMP trap
port is not specified explicitly, default value (162) is
considered.
enterpriseOid
–the enterprise
object identifier of the trap.
trapCode
–the trap
code.
pdu
–the SNMP
PDU.
Remarks
Call this
function to send SNMPv1 trap.
Example
snmpvar
var1
snmppdu
pdu, response
int
iVarCount
int
iIndex
snmpvar
var_tmp
string
sOid
string
sValue
snmpvar
var_trap
snmppdu
pdu_trap
int
iTimeout
var1 =
CreateVar("1.3.6.1.2.1.2.1.0")
pdu =
CreatePdu(var1)
response =
SnmpGet("65.35.64.170",
"public",
2,
3000,
pdu)
iVarCount =
GetVarCount(response)
for
(iIndex =
0;
iIndex<iVarCount; iIndex++)
var_tmp =
GetVarAt(response,
iIndex)
sOid =
GetVarOID(var_tmp)
if(sOid
==
"1.3.6.1.2.1.2.1.0")
sValue
=
GetVarValue(var_tmp)
if
sValue ==
"2"
Println("Send
trap")
var_trap =
CreateVar("1.3.6.1.2.1.1.1.0",
"OCTET STRING",
"It is a test"
)
pdu_trap =
CreatePdu(var_trap)
Println(pdu_trap)
SendTrap("127.0.0.1",
"1.3.6.1.4.290",
12,
pdu_trap)
endif
endif
endfor
Output of the example script will look
like:
Send trap
OID: 1.3.6.1.2.1.1.1.0
Syntax: OCTET STRING
Value: It is a test
|