SnmpTrapAction

The SnmpTrapAction function sends a trap (for SNMP v1) or a notification (for SNMP v2) to an SNMP manager. Sending or traps or notifications is not supported for SNMP v3.

Syntax

The following is the syntax for SnmpTrapAction:

SnmpTrapAction(HostId, Port, [VarIdList], [ValueList], [Community], [Timeout], [Version], [SysUpTime], [Enterprise], [GenericTrap], [SpecificTrap], [SnmpTrapOid])

Parameters

The following table shows the parameters for SnmpTrapAction.

Parameter

Format

Description

HostId

String

Hostname or IP address of the system where the SNMP manager is running.

Port

Integer

Port where the SNMP manager is running.

VarIdList

Array

Optional. Array of strings containing the OIDs of SNMP variables to send to the manager.

ValueList

Array

Optional. Array of strings containing the values you want to send to the manager. You must specify these values in the same order that the OIDs appear in the VarIdList variable.

Community

String

Optional. Name of the SNMP write community string. Default is public.

Timeout

Integer

Optional. Number of seconds to wait for a response from the SNMP agent before timing out. Default is 15.

Version

Integer

Optional. SNMP version number. Possible values are 1 and 2. Default is 1.

SysUpTime

Integer

Optional. Number of milliseconds since the system started. Default is the current system time in milliseconds.

Enterprise

String

Required for SNMP v1 only. Enterprise ID.

GenericTrap

String

Required for SNMP v1 only. Generic trap ID.

SpecificTrap

String

Required for SNMP v1 only. Specific trap ID.

SnmpTrapOid

String

Optional for SNMP v1. Required for SNMP v2. SNMP trap OID.

Example 1

The following example shows how to send an SNMP v1 trap to a manager using SnmpTrapAction.

// Call SnmpTrapAction

HostId = "localhost";
Port = 162;
Version = 1;
Community = "public";
Timeout = 15;
SysUpTime = 1001;
Enterprise = ".1.3.6.1.2.1.11";
GenericTrap = 3;
SpecificTrap = 0;
VarIdList = {".1.3.6.1.2.1.2.2.1.1.0", "sysDescr"};
ValueList = {"2", "My system"};

SnmpTrapAction(HostId, Port, VarIdList, ValueList, Community, Timeout, Version, SysUpTime, 
Enterprise, GenericTrap, SpecificTrap, NULL);

Example 2

The following example shows how to send an SNMP v2 notification to a manager using SnmpTrapAction. SNMP v2 requires that you specify an SNMP trap OID when you call this function.

// Call SnmpTrapAction

HostId = "localhost";
Port = 162;
Version = 1;
Community = "public";
Timeout = 15;
SysUpTime = 1001;
Enterprise = ".1.3.6.1.2.1.11";
GenericTrap = 3;
SpecificTrap = 0;
VarIdList = {".1.3.6.1.2.1.2.2.1.1.0", "sysDescr"};
ValueList = {"2", "My system"};
SnmpTrapOid = ".1.3.6.1.2.4.1.11";

SnmpTrapAction(HostId, Port, VarIdList, ValueList, Community, Timeout, Version, SysUpTime, 
Enterprise, GenericTrap, SpecificTrap, SnmpTrapOid);