aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/snmp/src/agent/snmp_view_based_acm_mib.erl20
-rw-r--r--lib/snmp/src/agent/snmpa.erl18
-rw-r--r--lib/snmp/src/agent/snmpa_mib_lib.erl44
3 files changed, 63 insertions, 19 deletions
diff --git a/lib/snmp/src/agent/snmp_view_based_acm_mib.erl b/lib/snmp/src/agent/snmp_view_based_acm_mib.erl
index f98b799631..659babaf94 100644
--- a/lib/snmp/src/agent/snmp_view_based_acm_mib.erl
+++ b/lib/snmp/src/agent/snmp_view_based_acm_mib.erl
@@ -782,32 +782,30 @@ split_cols(Cols, PreCols) ->
{PreCols, Cols}.
vacmViewSpinLock(print) ->
- case vacmViewSpinLock(get) of
- {value, Val} -> io:format("vacmViewSpinLock => ~p~n", [Val]);
- Error -> io:format("vacmViewSpinLock => ERROR: ~p~n", [Error])
- end;
+ VarAndValue = [{vacmViewSpinLock, vacmViewSpinLock(get)}],
+ snmpa_mib_lib:print_variables(VarAndValue);
vacmViewSpinLock(new) ->
- snmp_generic:variable_func(new, {vacmViewSpinLock, volatile}),
+ snmp_generic:variable_func(new, volatile_db(vacmViewSpinLock)),
{A1,A2,A3} = erlang:now(),
random:seed(A1,A2,A3),
Val = random:uniform(2147483648) - 1,
- snmp_generic:variable_func(set, Val, {vacmViewSpinLock, volatile});
+ snmp_generic:variable_func(set, Val, volatile_db(vacmViewSpinLock));
vacmViewSpinLock(delete) ->
ok;
vacmViewSpinLock(get) ->
- snmp_generic:variable_func(get, {vacmViewSpinLock, volatile}).
+ snmp_generic:variable_func(get, volatile_db(vacmViewSpinLock)).
vacmViewSpinLock(is_set_ok, NewVal) ->
- case snmp_generic:variable_func(get, {vacmViewSpinLock, volatile}) of
+ case snmp_generic:variable_func(get, volatile_db(vacmViewSpinLock)) of
{value, NewVal} -> noError;
_ -> inconsistentValue
end;
vacmViewSpinLock(set, NewVal) ->
snmp_generic:variable_func(set, (NewVal + 1) rem 2147483648,
- {vacmViewSpinLock, volatile}).
+ volatile_db(vacmViewSpinLock)).
vacmViewTreeFamilyTable(print) ->
@@ -942,7 +940,9 @@ do_get_vacmAccessTable(Key0, Acc) ->
-db(X) -> snmpa_agent:db(X).
+db(X) -> snmpa_agent:db(X).
+volatile_db(X) -> {X, volatile}.
+
fa(vacmSecurityToGroupTable) -> ?vacmGroupName;
fa(vacmViewTreeFamilyTable) -> ?vacmViewTreeFamilyMask.
diff --git a/lib/snmp/src/agent/snmpa.erl b/lib/snmp/src/agent/snmpa.erl
index 88417b19fe..8ad2a83de4 100644
--- a/lib/snmp/src/agent/snmpa.erl
+++ b/lib/snmp/src/agent/snmpa.erl
@@ -328,8 +328,8 @@ print_mib_info() ->
print_mib_info([{Mod, Tables, Variables} | MibsInfo]) ->
io:format("~n** ~s ** ~n~n", [make_pretty_mib(Mod)]),
- print_variables(Mod, Variables),
- print_tables(Mod, Tables),
+ print_mib_variables2(Mod, Variables),
+ print_mib_tables2(Mod, Tables),
print_mib_info(MibsInfo).
@@ -339,7 +339,8 @@ print_mib_tables() ->
print_mib_tables([]) ->
ok;
-print_mib_tables([{Mod, Tabs}|MibTabs]) when is_atom(Mod) andalso is_list(Tabs) ->
+print_mib_tables([{Mod, Tabs}|MibTabs])
+ when is_atom(Mod) andalso is_list(Tabs) ->
print_mib_tables(Mod, Tabs),
print_mib_tables(MibTabs);
print_mib_tables([_|MibTabs]) ->
@@ -347,9 +348,9 @@ print_mib_tables([_|MibTabs]) ->
print_mib_tables(Mod, Tables) ->
io:format("~n** ~s ** ~n~n", [make_pretty_mib(Mod)]),
- print_tables(Mod, Tables).
+ print_mib_tables2(Mod, Tables).
-print_tables(Mod, Tables) ->
+print_mib_tables2(Mod, Tables) ->
[(catch Mod:Table(print)) || Table <- Tables].
@@ -359,7 +360,8 @@ print_mib_variables() ->
print_mib_variables([]) ->
ok;
-print_mib_variables([{Mod, Vars}|MibVars]) when is_atom(Mod) andalso is_list(Vars) ->
+print_mib_variables([{Mod, Vars}|MibVars])
+ when is_atom(Mod) andalso is_list(Vars) ->
print_mib_variables(Mod, Vars),
print_mib_variables(MibVars);
print_mib_variables([_|MibVars]) ->
@@ -367,9 +369,9 @@ print_mib_variables([_|MibVars]) ->
print_mib_variables(Mod, Vars) ->
io:format("~n** ~s ** ~n~n", [make_pretty_mib(Mod)]),
- print_variables(Mod, Vars).
+ print_mib_variables2(Mod, Vars).
-print_variables(Mod, Variables) ->
+print_mib_variables2(Mod, Variables) ->
[(catch Mod:Variable(print)) || Variable <- Variables].
diff --git a/lib/snmp/src/agent/snmpa_mib_lib.erl b/lib/snmp/src/agent/snmpa_mib_lib.erl
index 441228b9ee..22057b4547 100644
--- a/lib/snmp/src/agent/snmpa_mib_lib.erl
+++ b/lib/snmp/src/agent/snmpa_mib_lib.erl
@@ -19,7 +19,8 @@
-module(snmpa_mib_lib).
-export([table_cre_row/3, table_del_row/2]).
--export([get_table/2, print_table/3, print_table/4, print_tables/1]).
+-export([get_table/2]).
+-export([print_variables/1, print_table/3, print_table/4, print_tables/1]).
-export([gc_tab/3, gc_tab/5]).
-include("SNMPv2-TC.hrl").
@@ -81,6 +82,47 @@ get_table(NameDb, FOI, Oid, Acc) ->
end.
+print_variables(Variables) when is_list(Variables) ->
+ Variables2 = print_variables_prefixify(Variables),
+ lists:foreach(fun({Variable, ValueResult, Prefix}) ->
+ print_variable(Variable, ValueResult, Prefix)
+ end, Variables2),
+ ok.
+
+print_variable(Variable, {value, Val}, Prefix) when is_atom(Variable) ->
+ io:format("~w~s => ~p~n", [Variable, Prefix, Val]);
+print_variable(Variable, Error, Prefix) when is_atom(Variable) ->
+ io:format("~w~s => ERROR: ~p~n", [Variable, Prefix, Error]).
+
+print_variables_prefixify(Variables) ->
+ MaxVarLength = print_variables_maxlength(Variables),
+ print_variables_prefixify(Variables, MaxVarLength, []).
+
+print_variables_prefixify([], _MaxVarLength, Acc) ->
+ lists:reverse(Acc);
+print_variables_prefixify([{Var, Res}|Variables], MaxVarLength, Acc) ->
+ Prefix = make_variable_print_prefix(Var, MaxVarLength),
+ print_variables_prefixify(Variables, MaxVarLength,
+ [{Var, Res, Prefix}|Acc]).
+
+make_variable_print_prefix(Var, MaxVarLength) ->
+ lists:duplicate(MaxVarLength - length(atom_to_list(Var)) + 1, $ ).
+
+print_variables_maxlength(Variables) ->
+ print_variables_maxlength(Variables, 0).
+
+print_variables_maxlength([], MaxLength) ->
+ MaxLength;
+print_variables_maxlength([{Var, _}|Variables], MaxLength) when is_atom(Var) ->
+ VarLen = length(atom_to_list(Var)),
+ if
+ VarLen > MaxLength ->
+ print_variables_maxlength(Variables, VarLen);
+ true ->
+ print_variables_maxlength(Variables, MaxLength)
+ end.
+
+
print_tables(Tables) when is_list(Tables) ->
lists:foreach(fun({Table, DB, FOI, PrintRow}) ->
print_table(Table, DB, FOI, PrintRow)