aboutsummaryrefslogtreecommitdiffstats
path: root/lib/snmp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/snmp')
-rw-r--r--lib/snmp/src/misc/snmp_log.erl246
-rw-r--r--lib/snmp/src/misc/snmp_verbosity.erl14
2 files changed, 67 insertions, 193 deletions
diff --git a/lib/snmp/src/misc/snmp_log.erl b/lib/snmp/src/misc/snmp_log.erl
index e4089870b8..ae28df37fa 100644
--- a/lib/snmp/src/misc/snmp_log.erl
+++ b/lib/snmp/src/misc/snmp_log.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1997-2013. All Rights Reserved.
+%% Copyright Ericsson AB 1997-2012. 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
@@ -16,7 +16,6 @@
%%
%% %CopyrightEnd%
%%
-%%
-module(snmp_log).
@@ -436,8 +435,6 @@ log_to_txt(Log, Block, FileName, Dir, Mibs, TextFile, Start, Stop)
[Log, Block, FileName, Dir, Mibs, TextFile, Start, Stop]),
File = filename:join(Dir, FileName),
Converter = fun(L) ->
- ?vtrace("log_to_txt:fun -> entry with"
- "~n L: ~p", [L]),
do_log_to_file(L, TextFile, Mibs, Start, Stop)
end,
log_convert(Log, Block, File, Converter).
@@ -479,8 +476,6 @@ log_to_io(Log, Block, FileName, Dir, Mibs, Start, Stop)
[Log, Block, FileName, Dir, Mibs, Start, Stop]),
File = filename:join(Dir, FileName),
Converter = fun(L) ->
- ?vtrace("log_to_io:fun -> entry with"
- "~n L: ~p", [L]),
do_log_to_io(L, Mibs, Start, Stop)
end,
log_convert(Log, Block, File, Converter).
@@ -502,8 +497,7 @@ do_log_convert(Log, Block, File, Converter) ->
%% "~n Log: ~p"
%% "~n Block: ~p"
%% "~n File: ~p"
- %% "~n disk_log:info(Log): ~p",
- %% [Log, Block, File, disk_log:info(Log)]),
+ %% [Log, Block, File]),
Verbosity = get(verbosity),
{Pid, Ref} =
erlang:spawn_monitor(
@@ -611,93 +605,50 @@ maybe_unblock(Log, true = _Block) ->
%% -- do_log_to_text ---
do_log_to_file(Log, TextFile, Mibs, Start, Stop) ->
- ?vtrace("do_log_to_txt -> entry with"
- "~n Log: ~p"
- "~n TextFile: ~p"
- "~n Start: ~p"
- "~n Stop: ~p", [Log, TextFile, Start, Stop]),
case file:open(TextFile, [write]) of
{ok, Fd} ->
- ?vtrace("do_log_to_txt -> outfile created - create mini MIB", []),
MiniMib = snmp_mini_mib:create(Mibs),
- ?vtrace("do_log_to_txt -> mini-MIB created - begin conversion", []),
Write = fun(X) ->
- ?vtrace("do_log_to_txt:fun -> "
- "entry - try format", []),
case format_msg(X, MiniMib, Start, Stop) of
{ok, S} ->
- ?vtrace("do_log_to_txt:fun -> "
- "formated - now write", []),
io:format(Fd, "~s", [S]);
_ ->
- ?vdebug("do_log_to_txt:fun -> "
- "format failed", []),
ok
end
end,
Res = (catch loop(disk_log:chunk(Log, start), Log, Write)),
- ?vtrace("do_log_to_txt -> converted - now delete mini-MIB", []),
snmp_mini_mib:delete(MiniMib),
- ?vtrace("do_log_to_txt -> "
- "mini-MIB closed - now close output file", []),
file:close(Fd),
- ?vtrace("do_log_to_txt -> done", []),
Res;
{error, Reason} ->
- ?vinfo("failed opening output file: "
- "~n TestFile: ~p"
- "~n Reason: ~p", [TextFile, Reason]),
{error, {TextFile, Reason}}
end.
do_log_to_io(Log, Mibs, Start, Stop) ->
- ?vtrace("do_log_to_io -> entry with"
- "~n Log: ~p"
- "~n Mibs: ~p"
- "~n Start: ~p"
- "~n Stop: ~p", [Log, Mibs, Start, Stop]),
MiniMib = snmp_mini_mib:create(Mibs),
- ?vtrace("do_log_to_io -> mini-MIB created - begin conversion", []),
Write = fun(X) ->
- ?vtrace("do_log_to_io:fun -> entry", []),
case format_msg(X, MiniMib, Start, Stop) of
{ok, S} ->
- ?vtrace("do_log_to_io:fun -> "
- "formated - now write", []),
io:format("~s", [S]);
_ ->
- ?vdebug("do_log_to_io:fun -> "
- "format failed", []),
ok
end
end,
(catch loop(disk_log:chunk(Log, start), Log, Write)),
- ?vtrace("do_log_to_io -> converted - now delete mini-MIB", []),
snmp_mini_mib:delete(MiniMib),
- ?vtrace("do_log_to_io -> done", []),
ok.
loop(eof, _Log, _Write) ->
- ?vtrace("loop -> entry when eof", []),
ok;
-loop({error, _Reason} = Error, _Log, _Write) ->
- ?vtrace("loop -> entry with error"
- "~n Reason: ~p", [_Reason]),
+loop({error, _} = Error, _Log, _Write) ->
Error;
loop({Cont, Terms}, Log, Write) ->
- ?vtrace("loop -> entry with terms"
- "~n Cont: ~p"
- "~n length(Terms): ~p", [Cont, length(Terms)]),
- case (catch lists:foreach(Write, Terms)) of
+ case (catch lists:foreach(Write, Terms)) of
{'EXIT', Reason} ->
- ?vtrace("loop -> failure while writing terms"
- "~n Reason: ~p", [Reason]),
{error, Reason};
- _X ->
- ?vtrace("loop -> terms written"
- "~n X: ~p", [_X]),
+ _ ->
loop(disk_log:chunk(Log, Cont), Log, Write)
end;
loop({Cont, Terms, BadBytes}, Log, Write) ->
@@ -710,8 +661,6 @@ loop({Cont, Terms, BadBytes}, Log, Write) ->
loop(disk_log:chunk(Log, Cont), Log, Write)
end;
loop(Error, _Log, _Write) ->
- ?vtrace("loop -> entry with unknown"
- "~n Error: ~p", [Error]),
Error.
@@ -726,17 +675,14 @@ format_msg(Entry, Mib, Start, Stop) ->
%% This is an old-style entry, that never had the sequence-number
do_format_msg({Timestamp, Packet, {Addr, Port}}, Mib) ->
- ?vdebug("do_format_msg -> old style log entry", []),
do_format_msg(Timestamp, Packet, Addr, Port, Mib);
%% This is the format without sequence-number
do_format_msg({Timestamp, Packet, Addr, Port}, Mib) ->
- ?vdebug("do_format_msg -> log entry without seqno", []),
do_format_msg(Timestamp, Packet, Addr, Port, Mib);
%% This is the format with sequence-number
do_format_msg({Timestamp, SeqNo, Packet, Addr, Port}, Mib) ->
- ?vdebug("do_format_msg -> log entry with seqno", []),
do_format_msg(Timestamp, SeqNo, Packet, Addr, Port, Mib);
%% This is crap...
@@ -744,165 +690,103 @@ do_format_msg(_, _) ->
format_tab("** unknown entry in log file\n\n", []).
do_format_msg(TimeStamp, {V3Hdr, ScopedPdu}, Addr, Port, Mib) ->
- ?vtrace("do_format_msg -> entry with"
- "~n Timestamp: ~p"
- "~n Addr: ~p"
- "~n Port: ~p"
- "~n => Try decode scoped pdu",
- [TimeStamp, Addr, Port]),
case (catch snmp_pdus:dec_scoped_pdu(ScopedPdu)) of
ScopedPDU when is_record(ScopedPDU, scopedPdu) ->
- ?vtrace("do_format_msg -> scoped pdu decoded"
- "~n ScopedPDU: ~p", [ScopedPDU]),
Msg = #message{version = 'version-3',
vsn_hdr = V3Hdr,
data = ScopedPDU},
f(ts2str(TimeStamp), "", Msg, Addr, Port, Mib);
-
{'EXIT', Reason} ->
- ?vinfo("Failed decoding scoped pdu: "
- "~n V3Hdr: ~w"
- "~n ScopedPdu: ~w"
- "~n Reason: ~p", [V3Hdr, ScopedPdu, Reason]),
- format_tab("** error in log file at ~s from ~s:~w ~p\n\n",
+ format_tab("** error in log file at ~s from ~p:~w ~p\n\n",
[ts2str(TimeStamp), ip(Addr), Port, Reason])
end;
-
do_format_msg(TimeStamp, Packet, Addr, Port, Mib) ->
- ?vtrace("do_format_msg -> entry with"
- "~n Timestamp: ~p"
- "~n Addr: ~p"
- "~n Port: ~p"
- "~n => Try decode packet",
- [TimeStamp, Addr, Port]),
case (catch snmp_pdus:dec_message(binary_to_list(Packet))) of
- #message{data = Data} = Msg when (is_record(Data, scopedPdu) orelse
- is_record(Data, pdu) orelse
- is_record(Data, trappdu)) ->
- ?vtrace("do_format_msg -> packet decoded"
- "~n Msg: ~p", [Msg]),
+ Msg when is_record(Msg, message) ->
f(ts2str(TimeStamp), "", Msg, Addr, Port, Mib);
-
- #message{version = Vsn,
- vsn_hdr = VsnHdr} = Msg ->
- ?vinfo("Message not fully decoded: "
- "~n Msg: ~p", [Msg]),
- Reason =
- lists:flatten(
- io_lib:format("Message not fully decoded: "
- "Vsn = ~p, VsnHdr = ~w", [Vsn, VsnHdr])),
- format_tab("** error in log file ~s from ~s:~w => "
- "\n ~s\n\n",
- [ts2str(TimeStamp), ip(Addr), Port, Reason]);
-
{'EXIT', Reason} ->
- ?vinfo("Failed decoding packet: "
- "~n Packet: ~w"
- "~n Reason: ~p", [Packet, Reason]),
format_tab("** error in log file ~p\n\n", [Reason])
end.
do_format_msg(TimeStamp, SeqNo, {V3Hdr, ScopedPdu}, Addr, Port, Mib) ->
- ?vtrace("do_format_msg -> entry with"
- "~n Timestamp: ~p"
- "~n SeqNo: ~p"
- "~n Addr: ~p"
- "~n Port: ~p"
- "~n => Try decode scoped pdu",
- [TimeStamp, SeqNo, Addr, Port]),
case (catch snmp_pdus:dec_scoped_pdu(ScopedPdu)) of
ScopedPDU when is_record(ScopedPDU, scopedPdu) ->
- ?vtrace("do_format_msg -> scoped pdu decoded"
- "~n ScopedPDU: ~p", [ScopedPDU]),
Msg = #message{version = 'version-3',
vsn_hdr = V3Hdr,
data = ScopedPDU},
f(ts2str(TimeStamp), sn2str(SeqNo), Msg, Addr, Port, Mib);
-
{'EXIT', Reason} ->
- ?vinfo("Failed decoding scoped pdu: "
- "~n V3Hdr: ~w"
- "~n ScopedPdu: ~w"
- "~n Reason: ~p", [V3Hdr, ScopedPdu, Reason]),
- format_tab("** error in log file at ~s~s from ~s:~w ~p\n\n",
+ format_tab("** error in log file at ~s from ~p:~w ~p\n\n",
[ts2str(TimeStamp), sn2str(SeqNo),
ip(Addr), Port, Reason])
end;
do_format_msg(TimeStamp, SeqNo, Packet, Addr, Port, Mib) ->
- ?vtrace("do_format_msg -> entry with"
- "~n Timestamp: ~p"
- "~n SeqNo: ~p"
- "~n Addr: ~p"
- "~n Port: ~p"
- "~n => Try decode message",
- [TimeStamp, SeqNo, Addr, Port]),
case (catch snmp_pdus:dec_message(binary_to_list(Packet))) of
- #message{data = Data} = Msg when (is_record(Data, scopedPdu) orelse
- is_record(Data, pdu) orelse
- is_record(Data, trappdu)) ->
- ?vtrace("do_format_msg -> message decoded"
- "~n Msg: ~p", [Msg]),
+ Msg when is_record(Msg, message) ->
f(ts2str(TimeStamp), sn2str(SeqNo), Msg, Addr, Port, Mib);
-
- #message{version = Vsn,
- vsn_hdr = VsnHdr} = Msg ->
- ?vinfo("Message not fully decoded: "
- "~n Msg: ~p", [Msg]),
- Reason =
- lists:flatten(
- io_lib:format("Message not fully decoded: "
- "Vsn = ~p, VsnHdr = ~w", [Vsn, VsnHdr])),
- format_tab("** error in log file ~s~s from ~s:~w => "
- "\n ~s\n\n",
- [ts2str(TimeStamp), sn2str(SeqNo),
- ip(Addr), Port, Reason]);
-
{'EXIT', Reason} ->
- ?vinfo("Failed decoding packet: "
- "~n Packet: ~w"
- "~n Reason: ~p", [Packet, Reason]),
- format_tab("** error in log file ~s (~s) from ~s:~w ~p\n\n",
+ format_tab("** error in log file ~s from ~p:~w ~p\n\n",
[ts2str(TimeStamp), sn2str(SeqNo),
ip(Addr), Port, Reason])
end.
+%% format_msg({TimeStamp, {V3Hdr, ScopedPdu}, {Addr, Port}},
+%% Mib, Start, Stop) ->
+%% format_msg({TimeStamp, {V3Hdr, ScopedPdu}, Addr, Port},
+%% Mib, Start, Stop);
+%% format_msg({TimeStamp, {V3Hdr, ScopedPdu}, Addr, Port},
+%% Mib, Start, Stop) ->
+%% case timestamp_filter(TimeStamp, Start, Stop) of
+%% true ->
+%% case (catch snmp_pdus:dec_scoped_pdu(ScopedPdu)) of
+%% ScopedPDU when record(ScopedPDU, scopedPdu) ->
+%% Msg = #message{version = 'version-3',
+%% vsn_hdr = V3Hdr,
+%% data = ScopedPDU},
+%% f(ts2str(TimeStamp), Msg, Addr, Port, Mib);
+%% {'EXIT', Reason} ->
+%% format_tab("** error in log file at ~s from ~p:~w ~p\n\n",
+%% [ts2str(TimeStamp), ip(Addr), Port, Reason])
+%% end;
+%% false ->
+%% ignore
+%% end;
+%% format_msg({TimeStamp, Packet, {Addr, Port}}, Mib, Start, Stop) ->
+%% format_msg({TimeStamp, Packet, Addr, Port}, Mib, Start, Stop);
+%% format_msg({TimeStamp, Packet, Addr, Port}, Mib, Start, Stop) ->
+%% case timestamp_filter(TimeStamp, Start, Stop) of
+%% true ->
+%% case (catch snmp_pdus:dec_message(binary_to_list(Packet))) of
+%% Msg when record(Msg, message) ->
+%% f(ts2str(TimeStamp), Msg, Addr, Port, Mib);
+%% {'EXIT', Reason} ->
+%% format_tab("** error in log file ~p\n\n", [Reason])
+%% end;
+%% false ->
+%% ignore
+%% end;
+%% format_msg(_, _Mib, _Start, _Stop) ->
+%% format_tab("** unknown entry in log file\n\n", []).
+
f(TimeStamp, SeqNo,
#message{version = Vsn, vsn_hdr = VsnHdr, data = Data},
Addr, Port, Mib) ->
- try
- begin
- Str = format_pdu(Data, Mib),
- HdrStr = format_header(Vsn, VsnHdr),
- case get_type(Data) of
- trappdu ->
- f_trap(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port);
- 'snmpv2-trap' ->
- f_trap(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port);
- 'inform-request' ->
- f_inform(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port);
- 'get-response' ->
- f_response(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port);
- report ->
- f_report(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port);
- _ ->
- f_request(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port)
- end
- end
- catch
- T:E ->
- ?vinfo("Failed formating log entry"
- "~n TimeStamp: ~p"
- "~n SeqNo: ~p"
- "~n Data: ~p"
- "~n Vsn: ~p"
- "~n VsnHdr: ~p"
- "~n Addr: ~p"
- "~n Port: ~p"
- "~n Error Type: ~w"
- "~n Error: ~p",
- [TimeStamp, SeqNo, Data, Vsn, VsnHdr, Addr, Port, T, E]),
- format_tab("** error while formating log entry ~p\n\n", [{T, E}])
+ Str = format_pdu(Data, Mib),
+ HdrStr = format_header(Vsn, VsnHdr),
+ case get_type(Data) of
+ trappdu ->
+ f_trap(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port);
+ 'snmpv2-trap' ->
+ f_trap(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port);
+ 'inform-request' ->
+ f_inform(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port);
+ 'get-response' ->
+ f_response(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port);
+ report ->
+ f_report(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port);
+ _ ->
+ f_request(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port)
end.
f_request(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port) ->
@@ -929,7 +813,7 @@ f_inform(TimeStamp, SeqNo, Vsn, HdrStr, Str, Addr, Port) ->
%% Convert a timestamp 2-tupple to a printable string
%%
ts2str({Local,Universal}) ->
- lists:flatten(dat2str(Local) ++ " , " ++ dat2str(Universal));
+ dat2str(Local) ++ " , " ++ dat2str(Universal);
ts2str(_) ->
"".
@@ -1026,7 +910,7 @@ get_type(#pdu{type = Type}) ->
ip({A,B,C,D}) ->
- lists:flatten(io_lib:format("~w.~w.~w.~w", [A,B,C,D])).
+ io_lib:format("~w.~w.~w.~w", [A,B,C,D]).
diff --git a/lib/snmp/src/misc/snmp_verbosity.erl b/lib/snmp/src/misc/snmp_verbosity.erl
index 7d063fd702..f27c31db03 100644
--- a/lib/snmp/src/misc/snmp_verbosity.erl
+++ b/lib/snmp/src/misc/snmp_verbosity.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2000-2013. All Rights Reserved.
+%% Copyright Ericsson AB 2000-2012. 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
@@ -154,17 +154,7 @@ image_of_sname(mgr) -> "MGR";
image_of_sname(mgr_misc) -> "MGR_MISC";
image_of_sname(undefined) -> "";
-image_of_sname(S) when is_list(S) ->
- %% The assumption is that its a printable string,
- %% but just in case it is some other list...
- try lists:flatten(io_lib:format("~s", [S])) of
- L ->
- L
- catch
- _:_ ->
- lists:flatten(io_lib:format("~p", [S]))
- end;
-image_of_sname(V) -> lists:flatten(io_lib:format("~p", [V])).
+image_of_sname(V) -> lists:flatten(io_lib:format("~p",[V])).
validate(info) -> info;