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
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
MaxMessageSize
Max message size used in #SNMP.
public static int MaxMessageSize { get; set; }
Property Value
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
RequestCounter
The universal counter for request IDs and other IDs.
public static NumberGenerator RequestCounter { get; set; }
Property Value
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
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
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
UseFullRange
A flag to control request ID range.
public static bool UseFullRange { get; set; }
Property Value
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
VersionCodeProtocol version.
endpoint
IPEndPointEndpoint.
community
OctetStringCommunity name (v2c) or user name (v3).
contextName
OctetStringContext name.
table
ObjectIdentifierOID.
list
IList<Variable>A list to hold the results.
timeout
intThe 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
intThe max repetitions.
mode
WalkModeWalk mode.
privacy
IPrivacyProviderThe privacy provider.
report
ISnmpMessageThe 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
VersionCodeProtocol version.
endpoint
IPEndPointEndpoint.
community
OctetStringCommunity name (v2c) or user name (v3).
contextName
OctetStringContext name.
table
ObjectIdentifierOID.
list
IList<Variable>A list to hold the results.
maxRepetitions
intThe max repetitions.
mode
WalkModeWalk mode.
privacy
IPrivacyProviderThe privacy provider.
report
ISnmpMessageThe report.
Returns
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
VersionCodeProtocol version.
endpoint
IPEndPointEndpoint.
community
OctetStringCommunity name (v2c) or user name (v3).
contextName
OctetStringContext name.
table
ObjectIdentifierOID.
list
IList<Variable>A list to hold the results.
maxRepetitions
intThe max repetitions.
mode
WalkModeWalk mode.
privacy
IPrivacyProviderThe privacy provider.
report
ISnmpMessageThe report.
token
CancellationTokenThe cancellation token.
Returns
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
VersionCodeProtocol version.
endpoint
IPEndPointEndpoint.
community
OctetStringCommunity name.
variables
IList<Variable>Variable binds.
timeout
intThe 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
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
VersionCodeProtocol version.
endpoint
IPEndPointEndpoint.
community
OctetStringCommunity name.
variables
IList<Variable>Variable binds.
Returns
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
VersionCodeProtocol version.
endpoint
IPEndPointEndpoint.
community
OctetStringCommunity name.
variables
IList<Variable>Variable binds.
token
CancellationTokenThe cancellation token.
Returns
GetErrorMessage(ObjectIdentifier)
Returns error message for the specific ObjectIdentifier.
public static string GetErrorMessage(this ObjectIdentifier id)
Parameters
id
ObjectIdentifierThe OID.
Returns
- string
Error message.
GetNextDiscovery(SnmpType)
Returns a new discovery request.
public static Discovery GetNextDiscovery(SnmpType type)
Parameters
type
SnmpTypeMessage type.
Returns
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
VersionCodeProtocol version.
endpoint
IPEndPointEndpoint.
community
OctetStringCommunity name.
table
ObjectIdentifierTable OID.
timeout
intThe 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
intThe 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
intThe request ID.
version
VersionCodeProtocol version.
receiver
IPEndPointReceiver.
community
OctetStringCommunity name (v2c) or user name (v3).
contextName
OctetStringContext name.
enterprise
ObjectIdentifierEnterprise OID.
timestamp
uintTimestamp.
variables
IList<Variable>Variable bindings.
timeout
intThe 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
IPrivacyProviderThe privacy provider.
report
ISnmpMessageThe 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
intThe request ID.
version
VersionCodeProtocol version.
receiver
IPEndPointReceiver.
community
OctetStringCommunity name.
contextName
OctetStringContext name.
enterprise
ObjectIdentifierEnterprise OID.
timestamp
uintTimestamp.
variables
IList<Variable>Variable bindings.
privacy
IPrivacyProviderThe privacy provider.
report
ISnmpMessageThe report.
Returns
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
intThe request ID.
version
VersionCodeProtocol version.
receiver
IPEndPointReceiver.
community
OctetStringCommunity name.
contextName
OctetStringContext name.
enterprise
ObjectIdentifierEnterprise OID.
timestamp
uintTimestamp.
variables
IList<Variable>Variable bindings.
privacy
IPrivacyProviderThe privacy provider.
report
ISnmpMessageThe report.
token
CancellationTokenThe cancellation token.
Returns
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
EndPointReceiver.
agent
IPAddressAgent.
community
OctetStringCommunity name.
enterprise
ObjectIdentifierEnterprise OID.
generic
GenericCodeGeneric code.
specific
intSpecific code.
timestamp
uintTimestamp.
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
EndPointReceiver.
agent
IPAddressAgent.
community
OctetStringCommunity name.
enterprise
ObjectIdentifierEnterprise OID.
generic
GenericCodeGeneric code.
specific
intSpecific code.
timestamp
uintTimestamp.
variables
IList<Variable>Variable bindings.
Returns
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
EndPointReceiver.
agent
IPAddressAgent.
community
OctetStringCommunity name.
enterprise
ObjectIdentifierEnterprise OID.
generic
GenericCodeGeneric code.
specific
intSpecific code.
timestamp
uintTimestamp.
variables
IList<Variable>Variable bindings.
token
CancellationTokenThe cancellation token.
Returns
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
intRequest ID.
version
VersionCodeProtocol version.
receiver
EndPointReceiver.
community
OctetStringCommunity name.
enterprise
ObjectIdentifierEnterprise OID.
timestamp
uintTimestamp.
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
intRequest ID.
version
VersionCodeProtocol version.
receiver
EndPointReceiver.
community
OctetStringCommunity name.
enterprise
ObjectIdentifierEnterprise OID.
timestamp
uintTimestamp.
variables
IList<Variable>Variable bindings.
Returns
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
intRequest ID.
version
VersionCodeProtocol version.
receiver
EndPointReceiver.
community
OctetStringCommunity name.
enterprise
ObjectIdentifierEnterprise OID.
timestamp
uintTimestamp.
variables
IList<Variable>Variable bindings.
token
CancellationTokenThe cancellation token.
Returns
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
VersionCodeProtocol version.
endpoint
IPEndPointEndpoint.
community
OctetStringCommunity name.
variables
IList<Variable>Variable binds.
timeout
intThe 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
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
VersionCodeProtocol version.
endpoint
IPEndPointEndpoint.
community
OctetStringCommunity name.
variables
IList<Variable>Variable binds.
Returns
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
VersionCodeProtocol version.
endpoint
IPEndPointEndpoint.
community
OctetStringCommunity name.
variables
IList<Variable>Variable binds.
token
CancellationTokenThe cancellation token.
Returns
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
VersionCodeProtocol version.
endpoint
IPEndPointEndpoint.
community
OctetStringCommunity name.
table
ObjectIdentifierOID.
list
IList<Variable>A list to hold the results.
timeout
intThe 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
WalkModeWalk 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
VersionCodeProtocol version.
endpoint
IPEndPointEndpoint.
community
OctetStringCommunity name.
table
ObjectIdentifierOID.
list
IList<Variable>A list to hold the results.
mode
WalkModeWalk mode.
Returns
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
VersionCodeProtocol version.
endpoint
IPEndPointEndpoint.
community
OctetStringCommunity name.
table
ObjectIdentifierOID.
list
IList<Variable>A list to hold the results.
mode
WalkModeWalk mode.
token
CancellationTokenThe cancellation token.
Returns
Remarks
This method only supports SNMP v1 and v2c.