Table of Contents

Class Messenger

Namespace
Lextm.SharpSnmpLib.Messaging
Assembly
SharpSnmpLib.dll

Messenger class contains all static helper methods you need to send out SNMP messages. Static methods in Manager or Agent class will be removed in the future.

public static class Messenger
Inheritance
Messenger
Inherited Members

Remarks

SNMP v3 is not supported in many methods of this class. Please use ISnmpMessage derived classes directly if you want to do v3 operations.

Properties

AuthenticationFailure

If the authentication module returns failure, then the message cannot be trusted, so the usmStatsWrongDigests counter is incremented and an error indication (authenticationFailure) together with the OID and value of the incremented counter is returned to the calling module.

public static ObjectIdentifier AuthenticationFailure { get; }

Property Value

ObjectIdentifier

DecryptionError

If the privacy module returns failure, then the message can not be processed, so the usmStatsDecryptionErrors counter is incremented and an error indication (decryptionError) together with the OID and value of the incremented counter is returned to the calling module.

public static ObjectIdentifier DecryptionError { get; }

Property Value

ObjectIdentifier

MaxMessageSize

Max message size used in #SNMP.

public static int MaxMessageSize { get; set; }

Property Value

int

Remarks

You can use any value for your own application. Also this value may be changed in #SNMP in future releases.

NextMessageId

Gets the message counter.

public static int NextMessageId { get; }

Property Value

int

The message counter.

NextRequestId

Gets the request counter.

public static int NextRequestId { get; }

Property Value

int

The request counter.

NotInTimeWindow

If the message is considered to be outside of the Time Window then the usmStatsNotInTimeWindows counter is incremented and an error indication (notInTimeWindow) together with the OID, the value of the incremented counter, and an indication that the error must be reported with a securityLevel of authNoPriv, is returned to the calling module

public static ObjectIdentifier NotInTimeWindow { get; }

Property Value

ObjectIdentifier

RequestCounter

The universal counter for request IDs and other IDs.

public static NumberGenerator RequestCounter { get; set; }

Property Value

NumberGenerator

UnknownEngineId

If the value of the msgAuthoritativeEngineID field in the securityParameters is unknown then the usmStatsUnknownEngineIDs counter is incremented, and an error indication (unknownEngineID) together with the OID and value of the incremented counter is returned to the calling module.

public static ObjectIdentifier UnknownEngineId { get; }

Property Value

ObjectIdentifier

UnknownSecurityName

Information about the value of the msgUserName and msgAuthoritativeEngineID fields is extracted from the Local Configuration Datastore (LCD, usmUserTable). If no information is available for the user, then the usmStatsUnknownUserNames counter is incremented and an error indication (unknownSecurityName) together with the OID and value of the incremented counter is returned to the calling module.

public static ObjectIdentifier UnknownSecurityName { get; }

Property Value

ObjectIdentifier

UnsupportedSecurityLevel

If the information about the user indicates that it does not support the securityLevel requested by the caller, then the usmStatsUnsupportedSecLevels counter is incremented and an error indication (unsupportedSecurityLevel) together with the OID and value of the incremented counter is returned to the calling module.

public static ObjectIdentifier UnsupportedSecurityLevel { get; }

Property Value

ObjectIdentifier

UseFullRange

A flag to control request ID range.

public static bool UseFullRange { get; set; }

Property Value

bool

Remarks

Default is

true
. Should be set to
false
when SNMP devices might not support negative request ID values.

Methods

BulkWalk(VersionCode, IPEndPoint, OctetString, OctetString, ObjectIdentifier, IList<Variable>, int, int, WalkMode, IPrivacyProvider?, ISnmpMessage?)

Walks (based on GET BULK).

public static int BulkWalk(VersionCode version, IPEndPoint endpoint, OctetString community, OctetString contextName, ObjectIdentifier table, IList<Variable> list, int timeout, int maxRepetitions, WalkMode mode, IPrivacyProvider? privacy, ISnmpMessage? report)

Parameters

version VersionCode

Protocol version.

endpoint IPEndPoint

Endpoint.

community OctetString

Community name (v2c) or user name (v3).

contextName OctetString

Context name.

table ObjectIdentifier

OID.

list IList<Variable>

A list to hold the results.

timeout int

The time-out value, in milliseconds. The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period.

maxRepetitions int

The max repetitions.

mode WalkMode

Walk mode.

privacy IPrivacyProvider

The privacy provider.

report ISnmpMessage

The report.

Returns

int

Returns row count if the OID is a table. Otherwise this value is meaningless.

Remarks

This method supports SNMP v2c and v3.

BulkWalkAsync(VersionCode, IPEndPoint, OctetString, OctetString, ObjectIdentifier, IList<Variable>, int, WalkMode, IPrivacyProvider, ISnmpMessage)

Walks (based on GET BULK).

public static Task<int> BulkWalkAsync(VersionCode version, IPEndPoint endpoint, OctetString community, OctetString contextName, ObjectIdentifier table, IList<Variable> list, int maxRepetitions, WalkMode mode, IPrivacyProvider privacy, ISnmpMessage report)

Parameters

version VersionCode

Protocol version.

endpoint IPEndPoint

Endpoint.

community OctetString

Community name (v2c) or user name (v3).

contextName OctetString

Context name.

table ObjectIdentifier

OID.

list IList<Variable>

A list to hold the results.

maxRepetitions int

The max repetitions.

mode WalkMode

Walk mode.

privacy IPrivacyProvider

The privacy provider.

report ISnmpMessage

The report.

Returns

Task<int>

Returns row count if the OID is a table. Otherwise this value is meaningless.

Remarks

This method only supports SNMP v2c and v3.

BulkWalkAsync(VersionCode, IPEndPoint, OctetString, OctetString, ObjectIdentifier, IList<Variable>, int, WalkMode, IPrivacyProvider, ISnmpMessage, CancellationToken)

Walks (based on GET BULK).

public static Task<int> BulkWalkAsync(VersionCode version, IPEndPoint endpoint, OctetString community, OctetString contextName, ObjectIdentifier table, IList<Variable> list, int maxRepetitions, WalkMode mode, IPrivacyProvider privacy, ISnmpMessage report, CancellationToken token)

Parameters

version VersionCode

Protocol version.

endpoint IPEndPoint

Endpoint.

community OctetString

Community name (v2c) or user name (v3).

contextName OctetString

Context name.

table ObjectIdentifier

OID.

list IList<Variable>

A list to hold the results.

maxRepetitions int

The max repetitions.

mode WalkMode

Walk mode.

privacy IPrivacyProvider

The privacy provider.

report ISnmpMessage

The report.

token CancellationToken

The cancellation token.

Returns

Task<int>

Returns row count if the OID is a table. Otherwise this value is meaningless.

Remarks

This method only supports SNMP v2c and v3.

Get(VersionCode, IPEndPoint, OctetString, IList<Variable>, int)

Gets a list of variable binds.

public static IList<Variable> Get(VersionCode version, IPEndPoint endpoint, OctetString community, IList<Variable> variables, int timeout)

Parameters

version VersionCode

Protocol version.

endpoint IPEndPoint

Endpoint.

community OctetString

Community name.

variables IList<Variable>

Variable binds.

timeout int

The time-out value, in milliseconds. The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period.

Returns

IList<Variable>

Remarks

This method supports SNMP v1 and v2c.

GetAsync(VersionCode, IPEndPoint, OctetString, IList<Variable>)

Gets a list of variable binds.

public static Task<IList<Variable>> GetAsync(VersionCode version, IPEndPoint endpoint, OctetString community, IList<Variable> variables)

Parameters

version VersionCode

Protocol version.

endpoint IPEndPoint

Endpoint.

community OctetString

Community name.

variables IList<Variable>

Variable binds.

Returns

Task<IList<Variable>>

GetAsync(VersionCode, IPEndPoint, OctetString, IList<Variable>, CancellationToken)

Gets a list of variable binds.

public static Task<IList<Variable>> GetAsync(VersionCode version, IPEndPoint endpoint, OctetString community, IList<Variable> variables, CancellationToken token)

Parameters

version VersionCode

Protocol version.

endpoint IPEndPoint

Endpoint.

community OctetString

Community name.

variables IList<Variable>

Variable binds.

token CancellationToken

The cancellation token.

Returns

Task<IList<Variable>>

GetErrorMessage(ObjectIdentifier)

Returns error message for the specific ObjectIdentifier.

public static string GetErrorMessage(this ObjectIdentifier id)

Parameters

id ObjectIdentifier

The OID.

Returns

string

Error message.

GetNextDiscovery(SnmpType)

Returns a new discovery request.

public static Discovery GetNextDiscovery(SnmpType type)

Parameters

type SnmpType

Message type.

Returns

Discovery

GetTable(VersionCode, IPEndPoint, OctetString, ObjectIdentifier, int, int)

Gets a table of variables.

[CLSCompliant(false)]
[Obsolete("This method only works for a few scenarios. Might be replaced by new methods in the future. If it does not work for you, parse WALK result on your own.")]
public static Variable[,] GetTable(VersionCode version, IPEndPoint endpoint, OctetString community, ObjectIdentifier table, int timeout, int maxRepetitions)

Parameters

version VersionCode

Protocol version.

endpoint IPEndPoint

Endpoint.

community OctetString

Community name.

table ObjectIdentifier

Table OID.

timeout int

The time-out value, in milliseconds. The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period.

maxRepetitions int

The max repetitions.

Returns

Variable[,]

Remarks

This method supports SNMP v2c and v3.

SendInform(int, VersionCode, IPEndPoint, OctetString, OctetString, ObjectIdentifier, uint, IList<Variable>, int, IPrivacyProvider, ISnmpMessage)

Sends INFORM message.

[CLSCompliant(false)]
public static void SendInform(int requestId, VersionCode version, IPEndPoint receiver, OctetString community, OctetString contextName, ObjectIdentifier enterprise, uint timestamp, IList<Variable> variables, int timeout, IPrivacyProvider privacy, ISnmpMessage report)

Parameters

requestId int

The request ID.

version VersionCode

Protocol version.

receiver IPEndPoint

Receiver.

community OctetString

Community name (v2c) or user name (v3).

contextName OctetString

Context name.

enterprise ObjectIdentifier

Enterprise OID.

timestamp uint

Timestamp.

variables IList<Variable>

Variable bindings.

timeout int

The time-out value, in milliseconds. The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period.

privacy IPrivacyProvider

The privacy provider.

report ISnmpMessage

The report.

Remarks

This method supports SNMP v2c and v3.

SendInformAsync(int, VersionCode, IPEndPoint, OctetString, OctetString, ObjectIdentifier, uint, IList<Variable>, IPrivacyProvider, ISnmpMessage)

Sends INFORM message.

[CLSCompliant(false)]
public static Task SendInformAsync(int requestId, VersionCode version, IPEndPoint receiver, OctetString community, OctetString contextName, ObjectIdentifier enterprise, uint timestamp, IList<Variable> variables, IPrivacyProvider privacy, ISnmpMessage report)

Parameters

requestId int

The request ID.

version VersionCode

Protocol version.

receiver IPEndPoint

Receiver.

community OctetString

Community name.

contextName OctetString

Context name.

enterprise ObjectIdentifier

Enterprise OID.

timestamp uint

Timestamp.

variables IList<Variable>

Variable bindings.

privacy IPrivacyProvider

The privacy provider.

report ISnmpMessage

The report.

Returns

Task

Remarks

This method supports SNMP v2c and v3.

SendInformAsync(int, VersionCode, IPEndPoint, OctetString, OctetString, ObjectIdentifier, uint, IList<Variable>, IPrivacyProvider, ISnmpMessage, CancellationToken)

Sends INFORM message.

[CLSCompliant(false)]
public static Task SendInformAsync(int requestId, VersionCode version, IPEndPoint receiver, OctetString community, OctetString contextName, ObjectIdentifier enterprise, uint timestamp, IList<Variable> variables, IPrivacyProvider privacy, ISnmpMessage report, CancellationToken token)

Parameters

requestId int

The request ID.

version VersionCode

Protocol version.

receiver IPEndPoint

Receiver.

community OctetString

Community name.

contextName OctetString

Context name.

enterprise ObjectIdentifier

Enterprise OID.

timestamp uint

Timestamp.

variables IList<Variable>

Variable bindings.

privacy IPrivacyProvider

The privacy provider.

report ISnmpMessage

The report.

token CancellationToken

The cancellation token.

Returns

Task

Remarks

This method supports SNMP v2c and v3.

SendTrapV1(EndPoint, IPAddress, OctetString, ObjectIdentifier, GenericCode, int, uint, IList<Variable>)

Sends a TRAP v1 message.

[CLSCompliant(false)]
public static void SendTrapV1(EndPoint receiver, IPAddress agent, OctetString community, ObjectIdentifier enterprise, GenericCode generic, int specific, uint timestamp, IList<Variable> variables)

Parameters

receiver EndPoint

Receiver.

agent IPAddress

Agent.

community OctetString

Community name.

enterprise ObjectIdentifier

Enterprise OID.

generic GenericCode

Generic code.

specific int

Specific code.

timestamp uint

Timestamp.

variables IList<Variable>

Variable bindings.

Remarks

This method supports SNMP v1.

SendTrapV1Async(EndPoint, IPAddress, OctetString, ObjectIdentifier, GenericCode, int, uint, IList<Variable>)

Sends a TRAP v1 message.

[CLSCompliant(false)]
public static Task SendTrapV1Async(EndPoint receiver, IPAddress agent, OctetString community, ObjectIdentifier enterprise, GenericCode generic, int specific, uint timestamp, IList<Variable> variables)

Parameters

receiver EndPoint

Receiver.

agent IPAddress

Agent.

community OctetString

Community name.

enterprise ObjectIdentifier

Enterprise OID.

generic GenericCode

Generic code.

specific int

Specific code.

timestamp uint

Timestamp.

variables IList<Variable>

Variable bindings.

Returns

Task

Remarks

This method only supports SNMP v1.

SendTrapV1Async(EndPoint, IPAddress, OctetString, ObjectIdentifier, GenericCode, int, uint, IList<Variable>, CancellationToken)

Sends a TRAP v1 message.

[CLSCompliant(false)]
public static Task SendTrapV1Async(EndPoint receiver, IPAddress agent, OctetString community, ObjectIdentifier enterprise, GenericCode generic, int specific, uint timestamp, IList<Variable> variables, CancellationToken token)

Parameters

receiver EndPoint

Receiver.

agent IPAddress

Agent.

community OctetString

Community name.

enterprise ObjectIdentifier

Enterprise OID.

generic GenericCode

Generic code.

specific int

Specific code.

timestamp uint

Timestamp.

variables IList<Variable>

Variable bindings.

token CancellationToken

The cancellation token.

Returns

Task

Remarks

This method only supports SNMP v1.

SendTrapV2(int, VersionCode, EndPoint, OctetString, ObjectIdentifier, uint, IList<Variable>)

Sends TRAP v2 message.

[CLSCompliant(false)]
public static void SendTrapV2(int requestId, VersionCode version, EndPoint receiver, OctetString community, ObjectIdentifier enterprise, uint timestamp, IList<Variable> variables)

Parameters

requestId int

Request ID.

version VersionCode

Protocol version.

receiver EndPoint

Receiver.

community OctetString

Community name.

enterprise ObjectIdentifier

Enterprise OID.

timestamp uint

Timestamp.

variables IList<Variable>

Variable bindings.

Remarks

This method supports SNMP v2c.

SendTrapV2Async(int, VersionCode, EndPoint, OctetString, ObjectIdentifier, uint, IList<Variable>)

Sends TRAP v2 message.

[CLSCompliant(false)]
public static Task SendTrapV2Async(int requestId, VersionCode version, EndPoint receiver, OctetString community, ObjectIdentifier enterprise, uint timestamp, IList<Variable> variables)

Parameters

requestId int

Request ID.

version VersionCode

Protocol version.

receiver EndPoint

Receiver.

community OctetString

Community name.

enterprise ObjectIdentifier

Enterprise OID.

timestamp uint

Timestamp.

variables IList<Variable>

Variable bindings.

Returns

Task

Remarks

This method only supports SNMP v2c.

SendTrapV2Async(int, VersionCode, EndPoint, OctetString, ObjectIdentifier, uint, IList<Variable>, CancellationToken)

Sends TRAP v2 message.

[CLSCompliant(false)]
public static Task SendTrapV2Async(int requestId, VersionCode version, EndPoint receiver, OctetString community, ObjectIdentifier enterprise, uint timestamp, IList<Variable> variables, CancellationToken token)

Parameters

requestId int

Request ID.

version VersionCode

Protocol version.

receiver EndPoint

Receiver.

community OctetString

Community name.

enterprise ObjectIdentifier

Enterprise OID.

timestamp uint

Timestamp.

variables IList<Variable>

Variable bindings.

token CancellationToken

The cancellation token.

Returns

Task

Remarks

This method only supports SNMP v2c.

Set(VersionCode, IPEndPoint, OctetString, IList<Variable>, int)

Sets a list of variable binds.

public static IList<Variable> Set(VersionCode version, IPEndPoint endpoint, OctetString community, IList<Variable> variables, int timeout)

Parameters

version VersionCode

Protocol version.

endpoint IPEndPoint

Endpoint.

community OctetString

Community name.

variables IList<Variable>

Variable binds.

timeout int

The time-out value, in milliseconds. The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period.

Returns

IList<Variable>

Remarks

This method supports SNMP v1 and v2c.

SetAsync(VersionCode, IPEndPoint, OctetString, IList<Variable>)

Sets a list of variable binds.

public static Task<IList<Variable>> SetAsync(VersionCode version, IPEndPoint endpoint, OctetString community, IList<Variable> variables)

Parameters

version VersionCode

Protocol version.

endpoint IPEndPoint

Endpoint.

community OctetString

Community name.

variables IList<Variable>

Variable binds.

Returns

Task<IList<Variable>>

SetAsync(VersionCode, IPEndPoint, OctetString, IList<Variable>, CancellationToken)

Sets a list of variable binds.

public static Task<IList<Variable>> SetAsync(VersionCode version, IPEndPoint endpoint, OctetString community, IList<Variable> variables, CancellationToken token)

Parameters

version VersionCode

Protocol version.

endpoint IPEndPoint

Endpoint.

community OctetString

Community name.

variables IList<Variable>

Variable binds.

token CancellationToken

The cancellation token.

Returns

Task<IList<Variable>>

Walk(VersionCode, IPEndPoint, OctetString, ObjectIdentifier, IList<Variable>, int, WalkMode)

Walks (based on GET NEXT).

public static int Walk(VersionCode version, IPEndPoint endpoint, OctetString community, ObjectIdentifier table, IList<Variable> list, int timeout, WalkMode mode)

Parameters

version VersionCode

Protocol version.

endpoint IPEndPoint

Endpoint.

community OctetString

Community name.

table ObjectIdentifier

OID.

list IList<Variable>

A list to hold the results.

timeout int

The time-out value, in milliseconds. The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period.

mode WalkMode

Walk mode.

Returns

int

Returns row count if the OID is a table. Otherwise this value is meaningless.

Remarks

This method supports SNMP v1 and v2c.

WalkAsync(VersionCode, IPEndPoint, OctetString, ObjectIdentifier, IList<Variable>, WalkMode)

Walks (based on GET NEXT).

public static Task<int> WalkAsync(VersionCode version, IPEndPoint endpoint, OctetString community, ObjectIdentifier table, IList<Variable> list, WalkMode mode)

Parameters

version VersionCode

Protocol version.

endpoint IPEndPoint

Endpoint.

community OctetString

Community name.

table ObjectIdentifier

OID.

list IList<Variable>

A list to hold the results.

mode WalkMode

Walk mode.

Returns

Task<int>

Returns row count if the OID is a table. Otherwise this value is meaningless.

Remarks

This method only supports SNMP v1 and v2c.

WalkAsync(VersionCode, IPEndPoint, OctetString, ObjectIdentifier, IList<Variable>, WalkMode, CancellationToken)

Walks (based on GET NEXT).

public static Task<int> WalkAsync(VersionCode version, IPEndPoint endpoint, OctetString community, ObjectIdentifier table, IList<Variable> list, WalkMode mode, CancellationToken token)

Parameters

version VersionCode

Protocol version.

endpoint IPEndPoint

Endpoint.

community OctetString

Community name.

table ObjectIdentifier

OID.

list IList<Variable>

A list to hold the results.

mode WalkMode

Walk mode.

token CancellationToken

The cancellation token.

Returns

Task<int>

Returns row count if the OID is a table. Otherwise this value is meaningless.

Remarks

This method only supports SNMP v1 and v2c.