diff options
author | Micael Karlberg <[email protected]> | 2011-03-02 13:49:11 +0100 |
---|---|---|
committer | Micael Karlberg <[email protected]> | 2011-03-02 13:49:11 +0100 |
commit | 455ff4bc78f94c997d43a46fd2619b7d683c10c5 (patch) | |
tree | 376e4c476c1a50facdbd1ff59e0f6633bc06b2d3 /lib/snmp/src/agent/snmpa_mib_lib.erl | |
parent | 6daf9097abb20ae9fef69f60eb1b994aeaac0baf (diff) | |
parent | cf7f5f99f46708db185d927d0c7681fc4f6f3a0e (diff) | |
download | otp-455ff4bc78f94c997d43a46fd2619b7d683c10c5.tar.gz otp-455ff4bc78f94c997d43a46fd2619b7d683c10c5.tar.bz2 otp-455ff4bc78f94c997d43a46fd2619b7d683c10c5.zip |
Merge branch 'bmk/snmp/snmp419_integration/OTP-9068' into dev
* [compiler] Added support for textual convention AGENT-CAPABILITIES
and full support for textual convention MODULE-COMPLIANCE:
OTP-8966
* [agent] Added a "complete" set of (snmp) table and variable
print functions:
OTP-8977
* [agent] For is_set_ok and set operations on the table
vacmAccessTable, all values of the vacmAccessSecurityModel
column was incorrectly translated into any:
OTP-8980
* [agent] Reconfigure of SNMP-VIEW-BASED-ACM-MIB could after
a change in the vacm config file (vacm.conf):
OTP-8981
* [compiler] Added a MIB compiler (frontend) escript, snmpc:
OTP-9004
Diffstat (limited to 'lib/snmp/src/agent/snmpa_mib_lib.erl')
-rw-r--r-- | lib/snmp/src/agent/snmpa_mib_lib.erl | 57 |
1 files changed, 48 insertions, 9 deletions
diff --git a/lib/snmp/src/agent/snmpa_mib_lib.erl b/lib/snmp/src/agent/snmpa_mib_lib.erl index 441228b9ee..cb96ff8056 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,31 +82,69 @@ 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=> [e] ~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) end, Tables), ok. -%% print_table(Table, DB, FOI, PrintRow) -> -%% TableInfo = get_table(DB(Table), FOI(Table)), -%% print_table(Table, TableInfo, PrintRow), -%% ok. - print_table(Table, DB, FOI, PrintRow) -> TableInfo = get_table(DB, FOI), print_table(Table, TableInfo, PrintRow). print_table(Table, TableInfo, PrintRow) when is_function(PrintRow, 2) -> - io:format("~w => ~n", [Table]), + io:format("~w =>", [Table]), do_print_table(TableInfo, PrintRow). +do_print_table({ok, [] = _TableInfo}, _PrintRow) -> + io:format(" -~n", []); do_print_table({ok, TableInfo}, PrintRow) when is_function(PrintRow, 2) -> + io:format("~n", []), lists:foreach(fun({RowIdx, Row}) -> io:format(" ~w => ~n~s~n", [RowIdx, PrintRow(" ", Row)]) - end, TableInfo), - io:format("~n", []); + end, TableInfo); do_print_table({error, {invalid_rowindex, BadRowIndex, []}}, _PrintRow) -> io:format("Error: Bad rowindex ~w~n", [BadRowIndex]); do_print_table({error, {invalid_rowindex, BadRowIndex, TableInfo}}, PrintRow) -> |