SnmpGetAction

The SnmpGetAction function retrieves a set of SNMP variables from the specified agent and stores the values in a Netcool/Impact variable named ValueList and any error messages in a variable named ErrorString. This function sends an SNMP GET command to the specified agent.

When you call SnmpGetAction, you pass an SNMP data type and, for SNMP v3, any authorization parameters that are required. If you want to override the variable information specified in the SNMP data type, you can also pass a list of OIDs and other information needed to retrieve the data.

Syntax

The following is the syntax for SnmpGetAction:

SnmpGetAction(TypeName, [HostId], [Port], [VarIdList], [Community], [Timeout], [Version], [UserId], [AuthProtocol], [AuthPassword], [PrivPassword], [ContextId], [ContextName])

Parameters

The following table shows the parameters for SnmpGetAction.

Parameter

Format

Description

TypeName

String

Name of the SNMP data type that specifies the hostname, port, OIDs and other information needed to retrieve the SNMP data.

HostId

String

Hostname or IP address of the system where the SNMP agent is running. Overrides value specified in the SNMP data type.

Port

Integer

Port where the SNMP agent is running. Overrides value specified in the SNMP data type.

VarIdList

Array

Optional. Array of strings containing the OIDs of SNMP variables to retrieve from the agent. Overrides values specified in the SNMP data type.

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.

Version

Integer

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

UserId

String

Required for SNMP v3 authentication. If using SNMP v1 or v2, or v3 without authentication, pass a NULL value for this parameter.

AuthProtocol

String

Optional. For use with SNMP v3 authentication only. Possible values are MD5_AUTH, NO_AUTH, SHA_AUTH. NO_AUTH is the default.

AuthPassword

String

Optional. For use with SNMP v3 authentication only. Authentication password associated with the specified SNMP User ID.

PrivPassword

String

Optional. For use with SNMP v3 authentication only. Privacy password associated with the specified SNMP User ID.

ContextId

String

Optional. For use with SNMP v3 authentication only. Authentication context ID.

ContextName

String

Optional. For use with SNMP v3 authentication only. Authentication context name.

Return Values

When you call SnmpGetAction, it sets the following variables in the policy context: ValueList and ErrorString.

The ValueList variable is an array of strings, each of which stores the value of one variable retrieved from the SNMP agent. The strings in the array are assigned in the order that the variable OIDs are specified in the SNMP data type or the VarIdList parameter.

ErrorString is a string variable that contains any error messages generated while attempting to perform the SNMP GET command.

Example 1

The following example shows how to retrieve a set of SNMP variables by calling SnmpGetAction and passing the name of an SNMP data type as an input parameter. In this example, the SNMP data type is named SNMP_PACKED. The data type configuration specifies the OIDs of the variables you want to retrieve.

// Call SnmpGetAction and pass the name of the SNMP data type that contains
// configuration information required to perform the SNMP GET

TypeName = "SNMP_PACKED";
HostId = "192.168.1.1";
Port = "161";

SnmpGetAction(TypeName, HostId, Port, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \
    NULL, NULL, NULL);

// Print the results of the SNMP GET to the policy log

Count = 0;

While (Count < Length(ValueList)) {
    Log(ValueList[Index]);
    Count = Count + 1;
}

Example 2

The following example shows how to retrieve a set of SNMP variables by calling SnmpGetAction and explicitly overriding the OIDs and other configuration information specified in the data type.

// Call SnmpGetAction and pass the name of the SNMP data type that contains
// configuration information required to perform the SNMP GET

TypeName = "SNMP_PACKED";
HostId = "192.168.1.1";
Port = "161";
VarIdList =  {".1.3.6.1.2.1.1.5.0", ".1.3.6.1.2.1.1.6.0"};
Community = "private";
Timeout = 15;

SnmpGetAction(TypeName, HostId, Port, VarIdList, Community, Timeout, NULL, NULL, \
    NULL, NULL, NULL, NULL, NULL);

// Print the results of the SNMP GET to the policy log

Count = 0;

While (Count < Length(ValueList)) {
    Log(ValueList[Index]);
    Count = Count + 1;
}

Example 3

The following example shows how to retrieve a set of SNMP variables using SNMP v3 authentication.

// Call SnmpGetAction and pass the name of the SNMP data type that contains
// configuration information required to perform the SNMP GET

TypeName = "SNMP_PACKED";
HostId = "192.168.1.1";
Port = "161";
VarIdList =  {".1.3.6.1.2.1.1.5.0", ".1.3.6.1.2.1.1.6.0"};
Community = "private";
Timeout = 15;
Version = 3;
UserId = "snmpusr";
AuthProtocol = "MD5_AUTH";
AuthPassword = "snmppwd";
ContextId = "ctx";

SnmpGetAction(TypeName, HostId, Port, VarIdList, Community, Timeout, Version, UserId, \
    AuthProtocol, AuthPassword, NULL, ContextId, NULL);

// Print the results of the SNMP GET to the policy log

Count = 0;

While (Count < Length(ValueList)) {
    Log(ValueList[Index]);
    Count = Count + 1;
}