Class PropertyMOInput
java.lang.Object
org.snmp4j.agent.io.prop.PropertyMOInput
- All Implemented Interfaces:
MOInput
The
PropertyMOInput can be used to load MIB data from a properties file.
The format of the properties file is as follows:
snmp4j.agent.cfg.contexts={s|x}<context1>[,{s|x}<context2>...]
snmp4j.agent.cfg.oid[.ctx.<context>].<oid>=[<numRows>:<numCols>]
snmp4j.agent.cfg.oid[.ctx.<context>].<oid>=[{<format>}<value>]
snmp4j.agent.cfg.index[.ctx.<context>].oid.<rowIndex>={o}<index>
snmp4j.agent.cfg.value[.ctx.<context>].oid.<rowIndex>.<colIndex>=[{<format>}<value>]
where text enclosed in [] is optional and
- context1 - is a SNMPv3 context name as UTF-8 string (format {s}) or a hexadecimal string (format {x}).
- context - is a SNMPv3 context name as UTF-8 string if that string does not contain any ISO control characters, otherwise a hexdecimal representation separated by a colon (:).
- format - one of
- u - an Unsigned32 value.
- i - an Integer32 value.
- s - an OctetString value.
- x - an OctetString value in hexadecimal format (separated by :).
- R[:LENGTH] - an OctetString value generated randomly.
- r[:LENGTH] - a printable OctetString value generated randomly with a specified length. The value is used as an index for generated random values, thus the first random value with that name can be reused in later configurations. The random values will be printed to stdout on INFO level in clear text ('r' or hex 'R'). If the SNMP4JSettings.isSecretLoggingEnabled() is false, the random values will be printed to stderr in clear text.
- d - an OctetString value in decimal format (separated by .).
- b - an OctetString value in decimal format (separated by ' ' per byte).
- n - a Null value.
- o - an OID value as dotted string where string parts may be specified
directly enclosed in single quotes (') and the to an OID converted value of a variable/oid instance may be specified
in the format
[#]{<name/oid>}. The value of the variable will be included into the OID with prependend length if the # is used in the format string otherwise no length will be included. - t - a TimeTicks value as an unsigned long value.
- a - a IpAddress value.
- $ - gets the value from the variable or object instance specified by the name/oid following the $.
- value - a variable value in the format specified by
format. - numRows - the number of rows in the table.
- numCols - the number of columns in the table.
- rowIndex - the row index as a zero based unsigned integer.
- colIndex - the column index as a zero based unsigned integer.
- index - the OID value of the row's index.
An example properties file is:
snmp4j.agent.cfg.contexts=
snmp4j.agent.cfg.oid.1.3.6.1.2.1.1.2.0={o}1.3.6.1.4.1.4976
snmp4j.agent.cfg.oid.1.3.6.1.2.1.1.4.0={s}System Administrator
snmp4j.agent.cfg.oid.1.3.6.1.2.1.1.6.0={s}<edit location>
snmp4j.agent.cfg.oid.1.3.6.1.2.1.1.7.0={i}10
snmp4j.agent.cfg.oid.1.3.6.1.2.1.1.9.1=1:2
snmp4j.agent.cfg.index.1.3.6.1.2.1.1.9.1.0={o}1
snmp4j.agent.cfg.value.1.3.6.1.2.1.1.9.1.0.0={o}1.3.6.1.4.1.4976.10.1.1.100.4.1
snmp4j.agent.cfg.value.1.3.6.1.2.1.1.9.1.0.1=
## VACM MIB
# security2Group
snmp4j.agent.cfg.oid.1.3.6.1.6.3.16.1.2.1=2:3
snmp4j.agent.cfg.index.1.3.6.1.6.3.16.1.2.1.0={o}2.6.'public'
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.2.1.0.0={s}v1v2cgroup
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.2.1.0.1={i}4
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.2.1.0.2={i}1
snmp4j.agent.cfg.index.1.3.6.1.6.3.16.1.2.1.1={o}3.6.'SHADES'
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.2.1.1.0={s}v3group
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.2.1.1.1={i}4
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.2.1.1.2={i}1
# access
snmp4j.agent.cfg.oid.1.3.6.1.6.3.16.1.4.1=2:6
snmp4j.agent.cfg.index.1.3.6.1.6.3.16.1.4.1.0={o}10.'v1v2cgroup'.0.2.1
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.4.1.0.0={i}1
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.4.1.0.1={s}unrestrictedReadView
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.4.1.0.2={s}unrestrictedWriteView
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.4.1.0.3={s}unrestrictedNotifyView
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.4.1.0.4={i}4
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.4.1.0.5={i}1
snmp4j.agent.cfg.index.1.3.6.1.6.3.16.1.4.1.1={o}7.'v3group'.0.3.3
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.4.1.1.0={i}1
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.4.1.1.1={s}unrestrictedReadView
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.4.1.1.2={s}unrestrictedWriteView
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.4.1.1.3={s}unrestrictedNotifyView
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.4.1.1.4={i}4
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.4.1.1.5={i}1
# view trees
snmp4j.agent.cfg.oid.1.3.6.1.6.3.16.1.5.2.1=3:4
snmp4j.agent.cfg.index.1.3.6.1.6.3.16.1.5.2.1.0={o}20.'unrestrictedReadView'.3.1.3.6
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.5.2.1.0.0={s}
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.5.2.1.0.1={i}1
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.5.2.1.0.2={i}4
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.5.2.1.0.3={i}1
snmp4j.agent.cfg.index.1.3.6.1.6.3.16.1.5.2.1.1={o}21.'unrestrictedWriteView'.3.1.3.6
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.5.2.1.1.0={s}
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.5.2.1.1.1={i}1
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.5.2.1.1.2={i}4
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.5.2.1.1.3={i}1
snmp4j.agent.cfg.index.1.3.6.1.6.3.16.1.5.2.1.2={o}22.'unrestrictedNotifyView'.3.1.3.6
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.5.2.1.2.0={s}
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.5.2.1.2.1={i}1
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.5.2.1.2.2={i}4
snmp4j.agent.cfg.value.1.3.6.1.6.3.16.1.5.2.1.2.3={i}1
## SNMP community MIB
snmp4j.agent.cfg.oid.1.3.6.1.6.3.18.1.1.1=1:7
snmp4j.agent.cfg.index.1.3.6.1.6.3.18.1.1.1.0={o}'public'
snmp4j.agent.cfg.value.1.3.6.1.6.3.18.1.1.1.0.0={s}public
snmp4j.agent.cfg.value.1.3.6.1.6.3.18.1.1.1.0.1={s}public
snmp4j.agent.cfg.value.1.3.6.1.6.3.18.1.1.1.0.2={$1.3.6.1.6.3.10.2.1.1.0}
snmp4j.agent.cfg.value.1.3.6.1.6.3.18.1.1.1.0.3={s}
snmp4j.agent.cfg.value.1.3.6.1.6.3.18.1.1.1.0.4={s}
snmp4j.agent.cfg.value.1.3.6.1.6.3.18.1.1.1.0.5={i}4
snmp4j.agent.cfg.value.1.3.6.1.6.3.18.1.1.1.0.6={i}1
## USM MIB
snmp4j.agent.cfg.oid.1.3.6.1.6.3.15.1.2.2.1=1:14
snmp4j.agent.cfg.index.1.3.6.1.6.3.15.1.2.2.1.0={o}$#{1.3.6.1.6.3.10.2.1.1.0}.6.'SHADES'
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.0={s}SHADES
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.1={o}
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.2={o}1.3.6.1.6.3.10.1.1.3
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.3={s}
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.4={s}
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.5={o}1.3.6.1.6.3.10.1.2.2
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.6={s}
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.7={s}
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.8={s}
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.9={i}4
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.10={i}1
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.11={r:16}
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.12={s}SHADESPrivPassword
snmp4j.agent.cfg.value.1.3.6.1.6.3.15.1.2.2.1.0.13=
- Version:
- 3.12.0
- Author:
- Frank Fock
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPropertyMOInput(Properties props) PropertyMOInput(Properties props, VariableProvider variables) PropertyMOInput(Properties props, VariableProvider variables, ImportMode importMode) PropertyMOInput(Properties props, VariableProvider variables, org.snmp4j.util.OIDTextFormat oidTextFormat) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()org.snmp4j.smi.VariablecreateVariableFromString(String value, Class<? extends org.snmp4j.smi.Variable> returnType) Parses a string of the formatintReturns the update mode, which might be one of the constants defined byImportMode.intorg.snmp4j.smi.OctetStringgetRandomValue(String name) Returns the (predefined or generated) named random value with the given name.Returns an unmodifiable view of all named random values (predefined and generated so far).Reads and returns aContextfrom the input source.Reads and returns anIndexedVariablesinstance from the input source.Reads and returns aMOInfoobject from the input source.Reads and returns aSequencefrom the input source.org.snmp4j.smi.VariableReads aVariablefrom the input source.voidsetImportMode(int importMode) Sets theImportModeto be used when importing.voidsetOidTextFormat(org.snmp4j.util.OIDTextFormat oidTextFormat) Sets the OID text format to be used when parsing OIDs from properties files.voidsetRandomOctetStringDefaultLength(int randomOctetStringDefaultLength) voidsetRandomValue(String name, org.snmp4j.smi.OctetString value) Predefines a named random value (secret) that will be used instead of generating a new randomOctetStringwhen a{r}nameor{R}namevalue with the samenameis encountered while parsing the configuration.voidskipContext(Context context) Skips the specifiedContextduring the reading process.voidSkips to the end of the specified managed object's configuration.
-
Field Details
-
CONFIG_PREFIX
- See Also:
-
CONTEXTS_ID
- See Also:
-
OID_ID
- See Also:
-
INDEX_ID
- See Also:
-
VERSION_ID
- See Also:
-
CTX_ID
- See Also:
-
VALUE_ID
- See Also:
-
-
Constructor Details
-
PropertyMOInput
-
PropertyMOInput
-
PropertyMOInput
public PropertyMOInput(Properties props, VariableProvider variables, org.snmp4j.util.OIDTextFormat oidTextFormat) -
PropertyMOInput
-
-
Method Details
-
setOidTextFormat
public void setOidTextFormat(org.snmp4j.util.OIDTextFormat oidTextFormat) Sets the OID text format to be used when parsing OIDs from properties files. Default isSimpleOIDTextFormat- Parameters:
oidTextFormat- an OID text format.- Since:
- 3.5.4
-
getImportMode
public int getImportMode()Returns the update mode, which might be one of the constants defined byImportMode. By default,ImportMode.RESTORE_CHANGESis returned.- Specified by:
getImportModein interfaceMOInput- Returns:
- the constant denoting the update mode that should be used by a
SerializableManagedObjectto import its content from persistent storage.
-
setImportMode
public void setImportMode(int importMode) Sets theImportModeto be used when importing. By default,ImportMode.RESTORE_CHANGESis used.- Parameters:
importMode- one of the integer constants defined byImportModedefining howSerializableManagedObjectshould import its content from properties.- Since:
- 3.5.4
-
readContext
Description copied from interface:MOInputReads and returns aContextfrom the input source.- Specified by:
readContextin interfaceMOInput- Returns:
- a
Contextinstance representing the context information extracted from the input source. - Throws:
IOException- if an error occurs while reading theContext.
-
readIndexedVariables
Description copied from interface:MOInputReads and returns anIndexedVariablesinstance from the input source. AnIndexedVariablesobject encapsulates an index and an array of variables, providing a structured representation of indexed row data.- Specified by:
readIndexedVariablesin interfaceMOInput- Returns:
- an
IndexedVariablesinstance representing the indexed row data read from the input. - Throws:
IOException- if an I/O error occurs while reading the input source.
-
readManagedObject
Description copied from interface:MOInputReads and returns aMOInfoobject from the input source. AMOInfoinstance encapsulates information about a managed object, including its unique identifier (OID) and version details.- Specified by:
readManagedObjectin interfaceMOInput- Returns:
- a
MOInfoinstance representing the managed object information read from the input source. - Throws:
IOException- if an I/O error occurs while reading the managed object.
-
readSequence
Description copied from interface:MOInputReads and returns aSequencefrom the input source.- Specified by:
readSequencein interfaceMOInput- Returns:
- a
Sequenceobject representing the data read from the input source. - Throws:
IOException- if an I/O error occurs while reading theSequence.
-
readVariable
Description copied from interface:MOInputReads aVariablefrom the input source.- Specified by:
readVariablein interfaceMOInput- Returns:
- a
Variableobject representing the data read from the input source. - Throws:
IOException- if an I/O error occurs while reading theVariable.
-
skipContext
Description copied from interface:MOInputSkips the specifiedContextduring the reading process. This method is used to bypass a context in the input stream without processing it.- Specified by:
skipContextin interfaceMOInput- Parameters:
context- theContextinstance to be skipped. This represents specific context information that is available in the input.- Throws:
IOException- if an I/O error occurs while attempting to skip the context in the input stream.
-
skipManagedObject
Description copied from interface:MOInputSkips to the end of the specified managed object's configuration.- Specified by:
skipManagedObjectin interfaceMOInput- Parameters:
mo- a MOInfo instance.- Throws:
IOException- if the input stream cannot be read.
-
createVariableFromString
public org.snmp4j.smi.Variable createVariableFromString(String value, Class<? extends org.snmp4j.smi.Variable> returnType) Parses a string of the formatOID={type}value where <type> is one of the following single characters enclosed by '{' and '}': i Integer32 u UnsignedInteger32, Gauge32 s OCTET STRING x OCTET STRING specified as hex string where bytes separated by colons (':'). r[:length] Random (printable) OctetString with specified length. R[:length] Random (full 8bit) OctetString with specified length. d OCTET STRING specified as decimal string where bytes are separated by dots ('.'). n Null o OBJECT IDENTIFIER t TimeTicks a IpAddress b OCTET STRING specified as binary string where bytes are separated by spaces. $<variableName> where <variableName> is the name of a predefined variable or the OID of a variable of the agent's MIB.and returns the corresponding variable.- Parameters:
value- the variable value string.returnType- the expected Variable class to return.- Returns:
nullifvalueisnulland theVariablecorresponding tovalueotherwise.
-
close
- Specified by:
closein interfaceMOInput- Throws:
IOException
-
getRandomOctetStringDefaultLength
public int getRandomOctetStringDefaultLength() -
setRandomOctetStringDefaultLength
public void setRandomOctetStringDefaultLength(int randomOctetStringDefaultLength) -
setRandomValue
Predefines a named random value (secret) that will be used instead of generating a new randomOctetStringwhen a{r}nameor{R}namevalue with the samenameis encountered while parsing the configuration. This method has to be called before the deserialization (reading) process begins, i.e., before thisPropertyMOInputis passed to aMOServerPersistenceorAgentConfigManager.This allows externally provided secrets (for example pass keys supplied on the command line) to be injected into the configuration by referencing them by name in the properties file.
- Parameters:
name- the name of the random value as referenced by a{r}name/{R}namevalue.value- the predefined value to use for that name. Anullvalue removes any predefined value.- Since:
- 3.9.0
-
getRandomValue
Returns the (predefined or generated) named random value with the given name.- Parameters:
name- the name of the random value.- Returns:
- the
OctetStringassociated withname, ornullif no such value has been predefined or generated yet. - Since:
- 3.9.0
-
getRandomValues
-