snmp_local_db(3)

MODULE
snmp_local_db - The SNMP built-in database

DESCRIPTION

The module snmp_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 a module, pets (Persistent ets (Erlang Term Store)), that keeps an ets database in memory for speed, and on disk for persistent storage. At start-up, the ets database is initialized from disk. All readings from the database go to the ets. Writings go also to the ets, and a note is made in a log file. When the database is closed, the entire ets database is dumped, and the log file is cleared. If a crash occurs, the log file will always contain the latest changes. At start-up, the dumped ets is read, and then the database is recovered using the log file. It is also possible to manually dump the database, in which case the entire ets is dumped, and the log file is cleared.

There are three scaling problems with this database.

    *   If the database is never dumped, there are a lot of modifications to the database and the log file will grow rapidly. This can be solved by regularly dumping the database.

    *   The second problem occurs if the database is large, dumping the entire database may take some considerable time and it may slow down the system.

    *   The third problem is that insertions and deletions are inefficient for large tables.

All these problems are best solved by using Mnesia instead.

In order to know when the content of the database should be dumped, it is possible to register/unregister a notification client. This client will be notified of all persistent/permanent changes to the database by a call to:

Module:notify(Client, What)

Where the arguments are:

    *   Client = term()

    *   What = insert | delete | close

  Note:

The snmp local db does not initiate the dump! Instead, this could be initiated by the "notify client" as a result of the received db change information!

See register_notify_client/2 and unregister_notify_client/2 below for further information.

The following functions describe the interface to snmp_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 snmp_local_db specific.

Common Data Types

In the functions defined below, the following types are used:

    *   NameDb = {Name, Db}

    *   Name = atom(), Db = volatile | persistent

    *   RowIndex = [int()]

    *   Cols = [Col] | [{Col, Value}], Col = int(), Value = term()

where RowIndex denotes the last part of the OID, that specifies the index of the row in tha table. Cols is a list of column numbers in case of a get operation, and a list of column numbers and values in case of a set operation.

EXPORTS

dump() -> ok | {error, Reason}

    This function can be used to dump the database at any time. The entire ets database is dumped to disk, and the log file is cleared. This might be useful if the log file grows rapidly. Returns {error, Reason} if a file system error occured.

match(NameDb,Pattern)

    Performs an ets matching on the table. See Stdlib documentation, module ets, for a description of Pattern and the return values.

print()
print(TableName)
print(TableName, Db)

    Types
        TableName = atom()

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

    TableName is an atom for a table in the database. When no name is supplied, the whole database is shown.

table_create(NameDb) -> bool()

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

    Returns false if the NameDb argument is incorrectly specified, true otherwise.

table_create_row(NameDb,RowIndex,Row) -> bool()

    Types
        Row = {Val1, Val2, ..., ValN}
        Val1 = Val2 = ... = ValN = term()

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

table_delete(NameDb) -> void()

    Deletes a table.

table_delete_row(NameDb,RowIndex) -> bool()

    Deletes the row in the table.

table_exists(NameDb) -> bool()

    Checks if a table exists.

table_get_row(NameDb,RowIndex) -> Row | undefined

    Types
        Row = {Val1, Val2, ..., ValN}
        Val1 = Val2 = ... = ValN = term()

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

register_notify_client(Client,Module) -> ok | {error,Reason}

    Types
        Client = term()
        Module = atom()
        Reason = {already_registered, CurrentModule}
        CurrentModule = atom()

    Register Client as notification client to snmp_local_db. Client is actually just used as an identity, but could e.g. be a pid(). When changes are made to the database (insert, delete or stop) notify clients will be notified.

unregister_notify_client(Client) -> ok | {error,Reason}

    Types
        Client = term()
        Reason = not_registered

    Unregister Client as notification client to snmp_local_db.

See Also

ets(3), snmp_generic(3)

AUTHORS
Martin Björklund - support@erlang.ericsson.se
Klas Eriksson - support@erlang.ericsson.se