From fcf991e671c4a09fdb31bdbe50155f46905f0f7a Mon Sep 17 00:00:00 2001 From: Tilman Holschuh Date: Fri, 2 Mar 2018 15:26:45 -0800 Subject: [PATCH 1/2] Fix proper rfc5424 msg formatting --- src/logplex_api_v3_channel_logs.erl | 4 +++- test/logplex_api_v3_SUITE.erl | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/logplex_api_v3_channel_logs.erl b/src/logplex_api_v3_channel_logs.erl index 006662ba..ac0c82e6 100644 --- a/src/logplex_api_v3_channel_logs.erl +++ b/src/logplex_api_v3_channel_logs.erl @@ -87,4 +87,6 @@ prepare_logs([Msg | Logs], Acc) -> prepare_logs(Logs, [prepare_msg(Msg) | Acc]). prepare_msg(Msg) -> - logplex_syslog_utils:frame([Msg, $\n]). + ParsedMsg = logplex_syslog_utils:from_msg(Msg), + RFC5424Msg = logplex_syslog_utils:rfc5424(ParsedMsg), + logplex_syslog_utils:frame([RFC5424Msg, $\n]). diff --git a/test/logplex_api_v3_SUITE.erl b/test/logplex_api_v3_SUITE.erl index 10b8cc9f..2b97663c 100644 --- a/test/logplex_api_v3_SUITE.erl +++ b/test/logplex_api_v3_SUITE.erl @@ -587,7 +587,7 @@ fetch_channel_logs(Config0) -> [begin ?assertEqual(match, re:run(Line, Expected, [{capture, none}])), NBin = list_to_binary(integer_to_list(N)), - ?assertMatch(<<"72 <", NBin:1/binary, _/binary>>, Line) + ?assertMatch(<<"61 <", NBin:1/binary, _/binary>>, Line) end || {{N, Expected}, Line} <- lists:zip(ExpectedLogMsgs, Lines)], Config. @@ -755,7 +755,7 @@ new_drain_url() -> list_to_binary([<<"http://my.drain.com/">>, uuid:to_binary(uuid:v4())]). new_log_msg(N, Msg) when is_integer(N) -> - list_to_binary(["<", integer_to_list(N), ">", "aaaa bbbb cccc dddd eeee ffff - ", Msg]). + list_to_binary(["<", integer_to_list(N), ">1 ", "aaaa bbbb cccc dddd eeee - ", Msg]). to_binary(L) when is_list(L) -> list_to_binary(L); to_binary(Bin) when is_binary(Bin) -> Bin. From 749def80e80c19d2ae7a5fa77cb98fbd67a8ff42 Mon Sep 17 00:00:00 2001 From: Tilman Holschuh Date: Tue, 6 Mar 2018 17:15:01 -0800 Subject: [PATCH 2/2] Fake host --- src/logplex_api_v3_channel_logs.erl | 6 +++--- test/logplex_api_v3_SUITE.erl | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/logplex_api_v3_channel_logs.erl b/src/logplex_api_v3_channel_logs.erl index ac0c82e6..f44ca509 100644 --- a/src/logplex_api_v3_channel_logs.erl +++ b/src/logplex_api_v3_channel_logs.erl @@ -86,7 +86,7 @@ prepare_logs([], Acc) -> prepare_logs([Msg | Logs], Acc) -> prepare_logs(Logs, [prepare_msg(Msg) | Acc]). -prepare_msg(Msg) -> - ParsedMsg = logplex_syslog_utils:from_msg(Msg), - RFC5424Msg = logplex_syslog_utils:rfc5424(ParsedMsg), +prepare_msg(RawMsg) -> + {Facility, Severity, Time, Source, Process, Msg} = logplex_syslog_utils:from_msg(RawMsg), + RFC5424Msg = logplex_syslog_utils:rfc5424(Facility, Severity, Time, "host", Source, Process, undefined, Msg), logplex_syslog_utils:frame([RFC5424Msg, $\n]). diff --git a/test/logplex_api_v3_SUITE.erl b/test/logplex_api_v3_SUITE.erl index 2b97663c..a305fe79 100644 --- a/test/logplex_api_v3_SUITE.erl +++ b/test/logplex_api_v3_SUITE.erl @@ -55,6 +55,7 @@ groups() -> [channel_logs_service_unavailable , channel_logs_not_authorized , fetch_channel_logs + , channel_logs_format ]}, {sessions, [sessions_service_unavailable @@ -587,10 +588,26 @@ fetch_channel_logs(Config0) -> [begin ?assertEqual(match, re:run(Line, Expected, [{capture, none}])), NBin = list_to_binary(integer_to_list(N)), - ?assertMatch(<<"61 <", NBin:1/binary, _/binary>>, Line) + ?assertMatch(<<"64 <", NBin:1/binary, _/binary>>, Line) end || {{N, Expected}, Line} <- lists:zip(ExpectedLogMsgs, Lines)], Config. +channel_logs_format(Config0) -> + Config = create_channel_with_tokens(Config0), + Channel = ?config(channel, Config), + [{TokenName, TokenId} | _] = ?config(tokens, Config), + InputMsg = <<"<158>1 2018-03-02T23:22:34.901697+00:00 hermes.537018@staging.herokudev.com heroku router - - at=info code=H81 desc=\"Blank app\" method=GET path=\"/\" host=direwolf-d99daa9eda.staging.herokuappdev.com request_id=56a11b1c-1f68-4658-80e4-8213a09a81c2 fwd=\"54.163.94.153\" dyno= connect= service= status=502 bytes= protocol=https">>, + ExpectedMsg = "290 <158>1 2018-03-02T23:22:34.901697+00:00 host heroku router - at=info code=H81 desc=\"Blank app\" method=GET path=\"/\" host=direwolf-d99daa9eda.staging.herokuappdev.com request_id=56a11b1c-1f68-4658-80e4-8213a09a81c2 fwd=\"54.163.94.153\" dyno= connect= service= status=502 bytes= protocol=https\n", + logplex_message:process_msg({msg, InputMsg}, list_to_binary(Channel), TokenId, TokenName), + Props = stream_channel_logs(Channel, Config), + Headers = proplists:get_value(headers, Props), + ?assertEqual("application/logplex-1", proplists:get_value("content-type", Headers)), + ?assertEqual("1", proplists:get_value("logplex-msg-count", Headers)), + ?assertEqual("chunked", proplists:get_value("transfer-encoding", Headers)), + ?assertEqual("close", proplists:get_value("connection", Headers)), + ?assertMatch(ExpectedMsg, proplists:get_value(body, Props)). + + %% ----------------------------------------------------------------------------- %% sessions