View Source snmpa_local_db (snmp v5.16)
The SNMP built-in database
The module snmpa_local_db
contains functions for implementing tables (and
variables) using the SNMP built-in database. The database exists in two
instances, one volatile and one persistent. The volatile database is implemented
with ets. The persistent database is implemented with dets.
There is a scaling problem with this database.
- Insertions and deletions are inefficient for large tables.
This problem is best solved by using Mnesia instead.
The following functions describe the interface to snmpa_local_db
. Each
function has a Mnesia equivalent. The argument NameDb
is a tuple {Name, Db}
where Name
is the symbolic name of the managed object (as defined in the MIB),
and Db
is either volatile
or persistent
. mnesia
is not possible since
all these functions are snmpa_local_db
specific.
Common Data Types
In the functions defined below, the following limitation applies:
Db = volatile | persistent
See Also
ets(3), dets(3), snmp_generic(3)
Summary
Functions
This function can be used to manually dump the database to file.
Performs an ets/dets matching on the table.
Equivalent to print/2
.
Prints the contents of the database on screen. This is useful for debugging
since the STANDARD-MIB
and OTP-SNMPEA-MIB
(and maybe your own MIBs) are
stored in snmpa_local_db
.
Creates a table. If the table already exist, the old copy is destroyed.
Creates a row in a table. Row
is a tuple with values for all columns,
including the index columns.
Deletes a table.
Deletes the row in the table.
Checks if a table exists.
Get a column value (element) from a row of the table.
Row
is a tuple with values for all columns, including the index columns.
Update the specified columnar objects of the row of this table.
Functions
-spec dump() -> ok | {error, Reason} when Reason :: term().
This function can be used to manually dump the database to file.
-spec match(Table, Pattern) -> [Match] when Table :: snmpa:name_db() | snmpa:name(), Pattern :: ets:match_pattern(), Match :: term().
Performs an ets/dets matching on the table.
See ets:match/2
for a description of Pattern
and the return values.
-spec print() -> term().
Equivalent to print/2
.
-spec print(Table) -> term() when Table :: snmpa:name().
Equivalent to print/2
.
-spec print(Table, Db) -> term() when Table :: snmpa:name(), Db :: volatile | persistent.
Prints the contents of the database on screen. This is useful for debugging
since the STANDARD-MIB
and OTP-SNMPEA-MIB
(and maybe your own MIBs) are
stored in snmpa_local_db
.
Table
is an atom for a table in the database. When no name is supplied, the
whole database is shown.
Note that these functions does not actually print, using io:format/2, instead they (just) return the information. If executed in a shell, the information will then be displayed (probably truncated) there.
A better use would be:
io:format("~p~n", [snmpa_local_db:print()]).
-spec table_create(Table) -> boolean() when Table :: snmpa:name_db() | snmpa:name().
Creates a table. If the table already exist, the old copy is destroyed.
Returns false
if the NameDb
argument is incorrectly specified, true
otherwise.
Database (only table name specified) defaults to volatile
.
-spec table_create_row(Table, RowIndex, Row) -> boolean() when Table :: snmpa:name_db() | snmpa:name(), RowIndex :: snmp:row_index(), Row :: tuple().
Creates a row in a table. Row
is a tuple with values for all columns,
including the index columns.
Database (only table name specified) defaults to volatile
.
-spec table_delete(Table) -> true when Table :: snmpa:name_db() | snmpa:name().
Deletes a table.
Database (only table name specified) defaults to volatile
.
-spec table_delete_row(Table, RowIndex) -> boolean() when Table :: snmpa:name_db() | snmpa:name(), RowIndex :: snmp:row_index().
Deletes the row in the table.
Database (only table name specified) defaults to volatile
.
-spec table_exists(Table) -> boolean() when Table :: snmpa:name_db() | snmpa:name().
Checks if a table exists.
Database (only table name specified) defaults to volatile
.
-spec table_get_element(Table, RowIndex, Col) -> {value, Value} | undefined when Table :: snmpa:name_db() | snmpa:name(), RowIndex :: snmp:row_index(), Col :: snmp:column(), Value :: term().
Get a column value (element) from a row of the table.
Database (only table name specified) defaults to volatile
.
This function has existed for long time, but not had a proper since tag, so to simplify we set the since tag to when it was documented.
-spec table_get_row(Table, RowIndex) -> Row | undefined when Table :: snmpa:name_db() | snmpa:name(), RowIndex :: snmp:row_index(), Row :: tuple().
Row
is a tuple with values for all columns, including the index columns.
Database (only table name specified) defaults to volatile
.
-spec table_set_elements(Table, RowIndex, Cols) -> boolean() when Table :: snmpa:name_db() | snmpa:name(), RowIndex :: snmp:row_index(), Cols :: [{Col, Value}], Col :: snmp:column(), Value :: term().
Update the specified columnar objects of the row of this table.
Database (only table name specified) defaults to volatile
.
This function has existed for long time, but not had a proper since tag, so to simplify we set the since tag to when it was documented.