Search documentation of snmp

# View Source snmpa_local_db (snmp v5.18.2)

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

dump()

This function can be used to manually dump the database to file.

match(Table, Pattern)

Performs an ets/dets matching on the table.

print()

Equivalent to `print/2`.

print(Table)

Equivalent to `print/2`.

print(Table, Db)

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_create(Table)

Creates a table. If the table already exist, the old copy is destroyed.

table_create_row(Table, RowIndex, Row)

Creates a row in a table. `Row` is a tuple with values for all columns, including the index columns.

table_delete(Table)

Deletes a table.

table_delete_row(Table, RowIndex)

Deletes the row in the table.

table_exists(Table)

Checks if a table exists.

table_get_element(Table, RowIndex, Col)

Get a column value (element) from a row of the table.

table_get_row(Table, RowIndex)

`Row` is a tuple with values for all columns, including the index columns.

table_set_elements(Table, RowIndex, Cols)

Update the specified columnar objects of the row of this table.

# Functions

# dump()

    -spec dump() -> ok | {error, Reason} when Reason :: term().

This function can be used to manually dump the database to file.

# match(Table, Pattern)

    -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.

# print()

    -spec print() -> term().

Equivalent to `print/2`.

# print(Table)

    -spec print(Table) -> term() when Table :: snmpa:name().

Equivalent to `print/2`.

# print(Table, Db)

    -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()]).

# table_create(Table)

    -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`.

# table_create_row(Table, RowIndex, Row)

    -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`.

# table_delete(Table)

    -spec table_delete(Table) -> true when Table :: snmpa:name_db() | snmpa:name().

Deletes a table.

Database (only table name specified) defaults to `volatile`.

# table_delete_row(Table, RowIndex)

    -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`.

# table_exists(Table)

    -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`.

# table_get_element(Table, RowIndex, Col)

(since OTP 27.0)

    -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.

# table_get_row(Table, RowIndex)

    -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`.

# table_set_elements(Table, RowIndex, Cols)

(since OTP 27.0)

    -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.