Class SNMP4JSettings
java.lang.Object
org.snmp4j.SNMP4JSettings
The
SNMP4JSettings class implements a central configuration class of the SNMP4J framework. As a rule of
thumb, changes to the default configuration should be made before any other classes of the SNMP4J API are
instantiated or referenced by the application code.- Since:
- 1.5
- Version:
- 3.13.0
- Author:
- Frank Fock
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumSpecifies how the security level of retry requests after a REPORT PDU is set.static enumstatic enum -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe enterprise ID of AGENT++ which is the root OID also for SNMP4J. -
Method Summary
Modifier and TypeMethodDescriptionstatic CharacterGets the default non-printable character escape character.static intGet the default number of retries for packet-oriented transport mappings.static longGet the default timeout forAbstractTarget.Retrieves the strategy used for handling empty context engine IDs within SNMP4J confirmed requests.static intGets the enterprise OID used for creating SNMP engine IDs and other enterprise-specific identifiers.static intGets the maximum number of engine IDs to be hold in the cache of theMPv3.static intGets the maximum length of themsgAuthoritativeEngineIDaccepted in a received SNMPv3 message.static intstatic OIDTextFormatGets the OID text format for textual representation of OIDs.Get the SNMP4J statistics level.static ThreadFactoryGets the thread factory.static longGets the Thread join timeout used to join threads if no explicit timeout is set.static TimerFactoryGets the timer factory.static VariableTextFormatGets the variable text format for textual representation of variable bindings.static booleanstatic booleanstatic booleanDetermines if the boolean result of aTlsTmSecurityCallbackis enforced by the (D)TLS trust manager.static booleanTests if the extensibility feature is enabled.static booleanIndicates whether runtime exceptions should be thrown on thread boundaries controlled by SNMP4J and related APIs.static booleanstatic BooleanCheck if logging secrets with their secret value in any debug level is allowed (true) or not (false).static booleanDetermines if the system trusts the time provided by an unauthenticated engine.static booleanDetermines if a response has to be received from the transport address of the target it has been sent to, in order to be accepted for an outstanding request.static voidsetAllowSNMPv2InV1(boolean allowSNMPv2InV1) Sets the compatibility flag for Counter64 usage in SNMPv1 PDUs and the ability to decode SNMPv2 traps in SNMPv1 version PDUs.static voidsetCheckUsmUserPassphraseLength(boolean checkUsmUserPassphraseLength) static voidsetDefaultNonPrintableEscapeCharacter(Character defaultNonPrintableEscapeCharacter) Gets the default non-printable character escape character.static voidsetDefaultRetries(int defaultRetries) Set the default number of retries for packet oriented transport mappings, default is 0.static voidsetDefaultTimeoutMillis(long defaultTimeoutMillis) Set the default timeout forAbstractTarget.static voidsetEmptyContextEngineIdStrategy(SNMP4JSettings.Snmp4jConfirmedRequestEmptyContextEngineIdStrategy emptyContextEngineIdStrategy) Sets the strategy to be used when handling empty context engine IDs in SNMP4J confirmed requests.static voidsetEnforceTlsSecurityCallbackResult(boolean enforceTlsSecurityCallbackResult) Sets whether the boolean result of aTlsTmSecurityCallbackis enforced by the (D)TLS trust manager.static voidsetEnterpriseID(int enterpriseID) Sets the enterprise OID used for creating SNMP engine IDs and other enterprise-specific identifiers.static voidsetExtensibilityEnabled(boolean enable) Enables (or disables) the extensibility feature of SNMP4J.static voidsetForwardRuntimeExceptions(boolean forwardExceptions) Enables or disables runtime exception forwarding.static voidsetMaxEngineIdCacheSize(int maxEngineIdCacheSize) Sets the maximum number of engine IDs that can be cached by theMPv3.static voidsetMaxInboundEngineIdLength(int maxInboundEngineIdLength) Sets the maximum length of themsgAuthoritativeEngineIDaccepted in a received SNMPv3 message.static voidsetMaxSizeRequestPDU(int maxSizeRequestPDU) Sets the maximum size of a request PDU.static voidsetNoGetBulk(boolean noGetBulk) static voidsetOIDTextFormat(OIDTextFormat newOidTextFormat) Sets the OID text format to be used by SNMP4J.static voidsetReportSecurityLevelStrategy(SNMP4JSettings.ReportSecurityLevelStrategy reportSecurityLevelStrategy) static booleansetSecretLoggingEnabled(boolean enableSecretLogging) Activates or deactivates the secret logging.static voidsetSnmp4jStatistics(SNMP4JSettings.Snmp4jStatistics snmp4jStatistics) Sets the SNMP4J statistics level.static voidsetThreadFactory(ThreadFactory newThreadFactory) Sets the thread factory for creating new threads of execution.static voidsetThreadJoinTimeout(long millis) Sets the Thread join timeout used to join threads if no explicit timeout is set.static voidsetTimerFactory(TimerFactory newTimerFactory) Sets the timer factory for creating new timer instances.static voidsetTrustUnauthenticatedEngineTime(boolean trustUnauthenticatedEngineTime) Sets whether the system should trust the time provided by an unauthenticated engine.static voidsetVariableTextFormat(VariableTextFormat newVariableTextFormat) Sets the variable text format to be used by SNMP4J.static voidsetVerifyResponsePeerAddress(boolean verifyResponsePeerAddress) Sets whether a response has to be received from the transport address of the target it has been sent to, in order to be accepted for an outstanding request.
-
Field Details
-
AGENTPP_ENTERPRISE_ID
public static final int AGENTPP_ENTERPRISE_IDThe enterprise ID of AGENT++ which is the root OID also for SNMP4J.- See Also:
-
-
Method Details
-
getMaxSizeRequestPDU
public static int getMaxSizeRequestPDU() -
setMaxSizeRequestPDU
public static void setMaxSizeRequestPDU(int maxSizeRequestPDU) Sets the maximum size of a request PDU. This value must be betweenSnmpConstants.MIN_PDU_LENGTHand 65536 bytes (including).- Parameters:
maxSizeRequestPDU- a value greater or equal to 494 and less or equal to 65535.- Since:
- 3.5.0
-
getDefaultRetries
public static int getDefaultRetries()Get the default number of retries for packet-oriented transport mappings.- Returns:
- the default number of retries should be greater than or equal to zero.
- Since:
- 3.5.0
-
setDefaultRetries
public static void setDefaultRetries(int defaultRetries) Set the default number of retries for packet oriented transport mappings, default is 0.- Parameters:
defaultRetries- the number maximum of retries before a request is timed out. Must be greater than or equal to zero.
-
setExtensibilityEnabled
public static void setExtensibilityEnabled(boolean enable) Enables (or disables) the extensibility feature of SNMP4J. When enabled, SNMP4J checks certain properties files that describe which transport mappings, address types, SMI syntaxes, security protocols, etc. should be supported by SNMP4J.By default, the extensibility feature is disabled which provides a faster startup and since no system properties are read, it ensures that SNMP4J can be used also in secure environments like applets.
- Parameters:
enable- iftrueactivates extensibility or iffalsedisables it. In the latter case, SNMP4J's default configuration will be used with all available features.- Since:
- 1.2.2
-
isExtensibilityEnabled
public static boolean isExtensibilityEnabled()Tests if the extensibility feature is enabled.- Returns:
- if
truethe extensibility is enabled otherwise it is disabled. In the latter case, SNMP4J's default configuration will be used with all available features. - Since:
- 1.2.2
-
setForwardRuntimeExceptions
public static void setForwardRuntimeExceptions(boolean forwardExceptions) Enables or disables runtime exception forwarding.- Parameters:
forwardExceptions-trueruntime exceptions are thrown on thread boundaries controlled by SNMP4J and related APIs. Default isfalse.- Since:
- 1.8.1
- See Also:
-
isForwardRuntimeExceptions
public static boolean isForwardRuntimeExceptions()Indicates whether runtime exceptions should be thrown on thread boundaries controlled by SNMP4J and related APIs.- Returns:
trueruntime exceptions are thrown on thread boundaries controlled by SNMP4J and related APIs. Default isfalse.- Since:
- 1.8.1
-
getThreadFactory
Gets the thread factory.- Returns:
- a ThreadFactory.
- Since:
- 1.9
-
setThreadFactory
Sets the thread factory for creating new threads of execution.- Parameters:
newThreadFactory- a ThreadFactory (must not benull).- Since:
- 1.9
-
getTimerFactory
Gets the timer factory.- Returns:
- a TimerFactory.
- Since:
- 1.9
-
setTimerFactory
Sets the timer factory for creating new timer instances.- Parameters:
newTimerFactory- a TimerFactory (must not benull).- Since:
- 1.9
-
getOIDTextFormat
Gets the OID text format for textual representation of OIDs.- Returns:
- an
OIDTextFormatinstance. - Since:
- 1.10
-
setOIDTextFormat
Sets the OID text format to be used by SNMP4J.- Parameters:
newOidTextFormat- the newOIDTextFormat(must not benull).- Since:
- 1.10
-
getVariableTextFormat
Gets the variable text format for textual representation of variable bindings.- Returns:
- an
VariableTextFormatinstance. - Since:
- 1.10
-
setVariableTextFormat
Sets the variable text format to be used by SNMP4J.- Parameters:
newVariableTextFormat- the newVariableTextFormat(must not benull).- Since:
- 1.10
-
getThreadJoinTimeout
public static long getThreadJoinTimeout()Gets the Thread join timeout used to join threads if no explicit timeout is set.- Returns:
- the timeout millis.
- Since:
- 1.10.2
-
setThreadJoinTimeout
public static void setThreadJoinTimeout(long millis) Sets the Thread join timeout used to join threads if no explicit timeout is set.- Parameters:
millis- the maximum time in milliseconds to wait for a Thread to join if no explicit timeout has been set.- Since:
- 1.10.2
-
isAllowSNMPv2InV1
public static boolean isAllowSNMPv2InV1() -
setAllowSNMPv2InV1
public static void setAllowSNMPv2InV1(boolean allowSNMPv2InV1) Sets the compatibility flag for Counter64 usage in SNMPv1 PDUs and the ability to decode SNMPv2 traps in SNMPv1 version PDUs. The default isfalse. Note: By setting this totrueyou disable SNMP standard conformity.- Parameters:
allowSNMPv2InV1- if set totrue, SNMP4J will allow Counter64 objects in SNMPv1 PDUs although the SNMPv1 standard does not allow this. There are several buggy implementations that send such v1 PDUs.- Since:
- 2.2
-
getReportSecurityLevelStrategy
-
setReportSecurityLevelStrategy
public static void setReportSecurityLevelStrategy(SNMP4JSettings.ReportSecurityLevelStrategy reportSecurityLevelStrategy) -
isNoGetBulk
public static boolean isNoGetBulk() -
setNoGetBulk
public static void setNoGetBulk(boolean noGetBulk) -
getEnterpriseID
public static int getEnterpriseID()Gets the enterprise OID used for creating SNMP engine IDs and other enterprise-specific identifiers.- Returns:
- an enterprise ID. For example, 4976 as enterprise ID (IANA number) for AGENT++ (SNMP4J). This value should be changed for other enterprises (i.e., companies or organizations).
-
setEnterpriseID
public static void setEnterpriseID(int enterpriseID) Sets the enterprise OID used for creating SNMP engine IDs and other enterprise-specific identifiers.- Parameters:
enterpriseID- the new enterprise ID.
-
getMaxEngineIdCacheSize
public static int getMaxEngineIdCacheSize()Gets the maximum number of engine IDs to be hold in the cache of theMPv3. A upper limit is necessary to avoid DoS attacks with unconfirmed SNMPv3 PDUs.- Returns:
- the maximum number, by default 50.000 (~2MB of cached data).
- Since:
- 2.3.4
-
setMaxEngineIdCacheSize
public static void setMaxEngineIdCacheSize(int maxEngineIdCacheSize) Sets the maximum number of engine IDs that can be cached by theMPv3.- Parameters:
maxEngineIdCacheSize- the maximum number of engine IDs in the cache, by default 50.000 (~2MB of cached data).- Since:
- 2.3.4
-
getSnmp4jStatistics
Get the SNMP4J statistics level.- Returns:
- the Snmp4jStatistics enum value.
- Since:
- 2.4.2
-
setSnmp4jStatistics
Sets the SNMP4J statistics level.- Parameters:
snmp4jStatistics- the level of statistics to be collected by SNMP4J and provided throughCounterEvents.- Since:
- 2.4.2
-
isCheckUsmUserPassphraseLength
public static boolean isCheckUsmUserPassphraseLength() -
setCheckUsmUserPassphraseLength
public static void setCheckUsmUserPassphraseLength(boolean checkUsmUserPassphraseLength) -
getDefaultTimeoutMillis
public static long getDefaultTimeoutMillis()Get the default timeout forAbstractTarget.- Returns:
- the default timeout in milliseconds.
- Since:
- 3.5.0
-
setDefaultTimeoutMillis
public static void setDefaultTimeoutMillis(long defaultTimeoutMillis) Set the default timeout forAbstractTarget. The default of the default value is 1000 milliseconds (= one second).- Parameters:
defaultTimeoutMillis- the default timeout forTargets in milliseconds.- Since:
- 3.5.0
-
getDefaultNonPrintableEscapeCharacter
Gets the default non-printable character escape character. Ifnullnon-printableOctetStringand otherVariablewill be printed/formatted withVariable#toString()as hexadecimal string. If nonnullnon-printable characters (seeOctetString.isPrintable()) will be replaced by the given character in the output.- Returns:
- the escape character for non-printable characters.
- Since:
- 3.6.1
-
setDefaultNonPrintableEscapeCharacter
public static void setDefaultNonPrintableEscapeCharacter(Character defaultNonPrintableEscapeCharacter) Gets the default non-printable character escape character. Ifnullnon-printableOctetStringand otherVariablewill be printed/formatted withVariable#toString()as hexadecimal string. If nonnullnon-printable characters (seeOctetString.isPrintable()) will be replaced by the given character in the output.- Parameters:
defaultNonPrintableEscapeCharacter- the escape character for non-printable characters.nulldisables escaping.- Since:
- 3.6.1
-
isSecretLoggingEnabled
Check if logging secrets with their secret value in any debug level is allowed (true) or not (false). This value isfalseby default.- Returns:
trueif secret logging is enabled,falseotherwise.
-
setSecretLoggingEnabled
public static boolean setSecretLoggingEnabled(boolean enableSecretLogging) Activates or deactivates the secret logging. Note: Disabling secret logging is possible at any time, but enabling it is only possible if it has not yet been disabled.- Parameters:
enableSecretLogging-truefor enabling secret logging,falseotherwise. Enabling will work only initially.- Returns:
- the new status (
trueif secret logging is enabled,falseotherwise). - Since:
- 3.6.1
-
getEmptyContextEngineIdStrategy
public static SNMP4JSettings.Snmp4jConfirmedRequestEmptyContextEngineIdStrategy getEmptyContextEngineIdStrategy()Retrieves the strategy used for handling empty context engine IDs within SNMP4J confirmed requests.- Returns:
- an instance of Snmp4jConfirmedRequestEmptyContextEngineIdStrategy representing the configured strategy for managing empty context engine IDs.
- Since:
- 3.9.6
-
setEmptyContextEngineIdStrategy
public static void setEmptyContextEngineIdStrategy(SNMP4JSettings.Snmp4jConfirmedRequestEmptyContextEngineIdStrategy emptyContextEngineIdStrategy) Sets the strategy to be used when handling empty context engine IDs in SNMP4J confirmed requests.- Parameters:
emptyContextEngineIdStrategy- the strategy to use for managing empty context engine IDs in SNMP4J confirmed requests- Since:
- 3.9.6
-
isTrustUnauthenticatedEngineTime
public static boolean isTrustUnauthenticatedEngineTime()Determines if the system trusts the time provided by an unauthenticated engine.- Returns:
trueif the system trusts the unauthenticated engine's time;falseotherwise which is the default.- Since:
- 3.13.0
-
setTrustUnauthenticatedEngineTime
public static void setTrustUnauthenticatedEngineTime(boolean trustUnauthenticatedEngineTime) Sets whether the system should trust the time provided by an unauthenticated engine.- Parameters:
trustUnauthenticatedEngineTime-trueto trust the unauthenticated engine's time;falseto not trust the unauthenticated engine's time.- Since:
- 3.13.0
-
isVerifyResponsePeerAddress
public static boolean isVerifyResponsePeerAddress()Determines if a response has to be received from the transport address of the target it has been sent to, in order to be accepted for an outstanding request.- Returns:
trueif the peer address of a response is verified against the target address,falseotherwise which is the default.- Since:
- 3.13.0
-
setVerifyResponsePeerAddress
public static void setVerifyResponsePeerAddress(boolean verifyResponsePeerAddress) Sets whether a response has to be received from the transport address of the target it has been sent to, in order to be accepted for an outstanding request. Do not enable this in networks where devices reply from another address than the one that has been polled (for example because of asource-interface/management VRF configuration or NAT).- Parameters:
verifyResponsePeerAddress-trueto verify the peer address of a response against the target address.- Since:
- 3.13.0
-
getMaxInboundEngineIdLength
public static int getMaxInboundEngineIdLength()Gets the maximum length of themsgAuthoritativeEngineIDaccepted in a received SNMPv3 message.- Returns:
- the maximum accepted engine ID length in bytes, or 0 if the length is not checked. The default
is 32, the upper bound of
SnmpEngineIDas defined by RFC 3411. - Since:
- 3.13.0
-
setMaxInboundEngineIdLength
public static void setMaxInboundEngineIdLength(int maxInboundEngineIdLength) Sets the maximum length of themsgAuthoritativeEngineIDaccepted in a received SNMPv3 message. A message with a longer engine ID is discarded with a parse error, which stops a peer from using oversized engine IDs to inflate the USM tables that are keyed by the engine ID.Note that the lower bound of
SnmpEngineID(5 bytes) is intentionally not enforced on receive: a zero length engine ID is required for engine discovery, and other implementations, net-snmp among them, do not check the size of a received engine ID at all.- Parameters:
maxInboundEngineIdLength- the maximum accepted engine ID length in bytes, or 0 to not check the length (the behavior before 3.13.0).- Since:
- 3.13.0
-
isEnforceTlsSecurityCallbackResult
public static boolean isEnforceTlsSecurityCallbackResult()Determines if the boolean result of aTlsTmSecurityCallbackis enforced by the (D)TLS trust manager.- Returns:
trueif a peer rejected by the security callback is rejected, which is the default.- Since:
- 3.13.0
-
setEnforceTlsSecurityCallbackResult
public static void setEnforceTlsSecurityCallbackResult(boolean enforceTlsSecurityCallbackResult) Sets whether the boolean result of aTlsTmSecurityCallbackis enforced by the (D)TLS trust manager. Set this tofalseto restore the pre 3.13.0 behavior where the result ofisServerCertificateAcceptedwas ignored.- Parameters:
enforceTlsSecurityCallbackResult-trueto reject peers that are rejected by the security callback.- Since:
- 3.13.0
-