From 39540e7c380f6cb218a2ec6324f6296fa8327dba Mon Sep 17 00:00:00 2001 From: Micael Karlberg Date: Thu, 23 May 2013 12:35:38 +0200 Subject: [snmp/agent] Updated open options for the mnesia mib-storage module Updated the snmpa_mib_storage_mnesia module to handle alias atoms for the nodes option. Also, (git) added mib-storage behaviour ref-man. --- lib/snmp/doc/src/snmp_app.xml | 29 ++- lib/snmp/doc/src/snmp_config.xml | 29 ++- lib/snmp/doc/src/snmpa_mib_storage.xml | 292 ++++++++++++++++++++++++ lib/snmp/src/agent/snmpa_mib_storage_mnesia.erl | 31 ++- 4 files changed, 373 insertions(+), 8 deletions(-) create mode 100644 lib/snmp/doc/src/snmpa_mib_storage.xml (limited to 'lib') diff --git a/lib/snmp/doc/src/snmp_app.xml b/lib/snmp/doc/src/snmp_app.xml index c62c8f1541..f5a6de1099 100644 --- a/lib/snmp/doc/src/snmp_app.xml +++ b/lib/snmp/doc/src/snmp_app.xml @@ -329,7 +329,7 @@ behaviour.

Several entities (mib-server via the its data module and the symbolic-store) of the snmp agent uses this for storage - of miscelaneous mib data.

+ of miscelaneous mib related data retrieved while loading a mib.

There are several implementations provided with the agent: snmpa_mib_storage_ets, snmpa_mib_storage_dets and snmpa_mib_storage_mnesia.

@@ -340,7 +340,8 @@ ]]>

This is implementattion depended. That is, it depends on the - module. For each module a specific set of options are valid:

+ module. For each module a specific set of options are valid. + For the module provided with the app, these options are supported:

snmpa_mib_storage_ets: {dir, filename()} | {action, keep | clear}, {checksum, boolean()}

@@ -395,7 +396,29 @@

Default is keep.

-

nodes - Defines where to open the table.

+

nodes - A list of node names (or an atom + describing a list of nodes) defining where to open the table. + Its up to the user to ensure that mnesia is actually running + on the specified nodes.

+

The following distinct values are recognised:

+ + +

[] - Translated into a list of the own node: [node()]

+
+ +

all - erlang:nodes()

+
+ +

visible - erlang:nodes(visible)

+
+ +

connected - erlang:nodes(connected)

+
+ +

db_nodes - mnesia:system_info(db_nodes)

+
+
+

Default is the result of the call: erlang:nodes().

diff --git a/lib/snmp/doc/src/snmp_config.xml b/lib/snmp/doc/src/snmp_config.xml index a88111085f..f1acebf2f7 100644 --- a/lib/snmp/doc/src/snmp_config.xml +++ b/lib/snmp/doc/src/snmp_config.xml @@ -326,7 +326,7 @@ behaviour.

Several entities (mib-server via the its data module and the symbolic-store) of the snmp agent uses this for storage - of miscelaneous mib data.

+ of miscelaneous mib related data dataretrieved while loading a mib.

There are several implementations provided with the agent: snmpa_mib_storage_ets, snmpa_mib_storage_dets and snmpa_mib_storage_mnesia.

@@ -337,7 +337,8 @@ ]]>

This is implementattion depended. That is, it depends on the - module. For each module a specific set of options are valid:

+ module. For each module a specific set of options are valid. + For the module provided with the app, these options are supported:

snmpa_mib_storage_ets: {dir, filename()} | {action, keep | clear}, {checksum, boolean()}

@@ -392,7 +393,29 @@

Default is keep.

-

nodes - Defines where to open the table.

+

nodes - A list of node names (or an atom + describing a list of nodes) defining where to open the table. + Its up to the user to ensure that mnesia is actually running + on the specified nodes.

+

The following distinct values are recognised:

+ + +

[] - Translated into a list of the own node: [node()]

+
+ +

all - erlang:nodes()

+
+ +

visible - erlang:nodes(visible)

+
+ +

connected - erlang:nodes(connected)

+
+ +

db_nodes - mnesia:system_info(db_nodes)

+
+
+

Default is the result of the call: erlang:nodes().

diff --git a/lib/snmp/doc/src/snmpa_mib_storage.xml b/lib/snmp/doc/src/snmpa_mib_storage.xml new file mode 100644 index 0000000000..a857ce79e8 --- /dev/null +++ b/lib/snmp/doc/src/snmpa_mib_storage.xml @@ -0,0 +1,292 @@ + + + + +
+ + 20132013 + Ericsson AB. All Rights Reserved. + + + The contents of this file are subject to the Erlang Public License, + Version 1.1, (the "License"); you may not use this file except in + compliance with the License. You should have received a copy of the + Erlang Public License along with this software. If not, it can be + retrieved online at http://www.erlang.org/. + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + the License for the specific language governing rights and limitations + under the License. + + + + snmpa_mib_storage + + + + + snmpa_mib_storage.xml +
+ + snmpa_mib_storage + + Behaviour module for the SNMP agent mib storage. + + +

This module defines the behaviour of the SNMP agent mib storage.

+

The mib storage is used by the agent to store internal mib- + related information. The mib storage module is used by several entities, + not just the mib-server.

+ +

A snmpa_mib_storage compliant module + must export the following functions:

+ + + open/5 + + + close/1 + + + read/2 + + + write/2 + + + delete/1 + + + delete/2 + + + match_object/2 + + + match_delete/2 + + + tab2list/1 + + + info/1 + + + sync/1 + + + backup/2 + + + +

The semantics of them and their exact signatures are + explained below.

+ +
+ +
+ CALLBACK FUNCTIONS +

The following functions must be exported from a + mib-server data callback module:

+ + +
+ + + + Module:open(Name, RecordName, Fields, Type, Options) -> {ok, TabId} | {error, Reason} + Create new (mib-server) data instance + + Name = atom() + RecordName = atom() + Fields = [atom()] + Type = set | bag() + Options = list() + TabId = term() + Reason = term() + + +

Create or open a mib storage table.

+

Note that the RecordName and Fields arguments + my not be used in all implementations (they are actually only + needed for mnesia-based implementations).

+ +

Note also that the Options argument comes from + the options config option of the mib-storage config option, + and is passed on as is.

+ + +
+
+ + + Module:close(TabId) -> void() + Close the mib-storage table + + State = term() + + +

Close the mib-storage table.

+ + +
+
+ + + Module:read(TabId, Key) -> false | {value, Record} + Read a record from the mib-storage table + + TabId = term() + Key = term() + Record = tuple() + + +

Read a record from the mib-storage table.

+ + +
+
+ + + Module:write(TabId, Record) -> ok | {error, Reason} + Write a record to the mib-storage table + + TabId = term() + Record = tuple() + Reason = term() + + +

Write a record to the mib-storage table.

+ + +
+
+ + + Module:delete(TabId) -> void() + Delete an entire mib-storage table + + TabId = term() + + +

Delete an entire mib-storage table.

+ + +
+
+ + + Module:delete(TabId, Key) -> ok | {error, Reason} + Delete a record from the mib-storage table + + TabId = term() + Key = term() + Reason = term() + + +

Delete a record from the mib-storage table.

+ + +
+
+ + + Module:match_object(TabId, Pattern) -> {ok, Recs} | {error, Reason} + Search the mib-storage table for record matching pattern + + TabId = term() + Pattern = match_pattern() + Recs = [tuple()] + Reason = term() + + +

Search the mib-storage table for record that match the + specified pattern.

+ + +
+
+ + + Module:match_delete(TabId, Pattern) -> {ok, Recs} | {error, Reason} + Delete records in the mib-storage table matching pattern + + TabId = term() + Pattern = match_pattern() + Recs = [tuple()] + Reason = term() + + +

Search the mib-storage table for record that match the + specified pattern and then delete them. The records deleted are + also returned.

+ + +
+
+ + + Module:tab2list(TabId) -> Recs + Return all records of the mib-storage table + + TabId = term() + Recs = [tuple()] + + +

Return all records in the mib-storage table in the form + of a list.

+ + +
+
+ + + Module:info(TabId) -> {ok, Info} | {error, Reason} + Returns information about the mib-storage table. + + TabId = term() + Info = term() + Reason = term() + + +

Retrieve implementation dependent mib-storage table + information.

+ + +
+
+ + + Module:sync(TabId) -> void() + Synchronize mib-storage table + + TabId = term() + + +

Synchronize the mib-storage table.

+

What this means, if anything, is implementation dependent.

+ + +
+
+ + + Module:backup(TabId, BackupDir) -> ok | {error, Reason} + Perform a backup of the mib-storage table + + TabId = term() + BackupDir = string() + Reason = term() + + +

Perform a backup of the mib-storage table.

+

What this means, if anything, is implementation dependent.

+ +
+
+ +
+ +
+ diff --git a/lib/snmp/src/agent/snmpa_mib_storage_mnesia.erl b/lib/snmp/src/agent/snmpa_mib_storage_mnesia.erl index dca44d3c33..192b5aa26e 100644 --- a/lib/snmp/src/agent/snmpa_mib_storage_mnesia.erl +++ b/lib/snmp/src/agent/snmpa_mib_storage_mnesia.erl @@ -63,8 +63,8 @@ open(Name, RecName, Fields, Type, Opts) -> ?vtrace("open ~p table ~p for record ~p", [Type, Name, RecName]), - Action = snmp_misc:get_option(action, Opts, keep), - Nodes = snmp_misc:get_option(nodes, Opts, erlang:nodes()), + Action = get_action(Opts), + Nodes = get_nodes(Opts), case table_exists(Name) of true when (Action =:= keep) -> ?vtrace("open table ~p - exist (keep)", [Name]), @@ -271,5 +271,32 @@ backup(_, _) -> %%---------------------------------------------------------------------- +get_action(Opts) -> + snmp_misc:get_option(action, Opts, keep). + +get_nodes(Opts) -> + case snmp_misc:get_option(nodes, Opts, erlang:nodes()) of + [] -> + [node()]; + Nodes when is_list(Nodes) -> + Nodes; + all -> + erlang:nodes(); + visible -> + erlang:nodes(visible); + connected -> + erlang:nodes(connected); + db_nodes -> + try mnesia:system_info(db_nodes) of + DbNodes when is_list(DbNodes) -> + DbNodes; + _ -> + erlang:nodes() + catch + _:_ -> + erlang:nodes() + end + end. + %% user_err(F, A) -> %% snmpa_error:user_err(F, A). -- cgit v1.2.3