Commit 9b7bc08c authored by Heinz N. Gies's avatar Heinz N. Gies

Add support for filtering

parent e34a8b0b
......@@ -21,8 +21,8 @@ rel/pkg/packlist
.eqc-info
*.eqc
apps/dalmatiner_frontend/include/dalmatiner_frontend_version.hrl
apps/dalmatiner_frontend/src/dql_lexer.erl
apps/dalmatiner_frontend/src/dql_parser.erl
_build
TEST-*
rebar3.crashdump
apps/dalmatiner_frontend/src/event_query_lexer.xrl
apps/dalmatiner_frontend/src/event_query_parser.yrl
......@@ -35,9 +35,9 @@
</ul>
</section>
</nav>
<div class="row">
<form id="queryfrom" action="/events" method="get">
<div class="large-2 columns">
<form id="queryfrom" action="/events" method="get">
<div class="row">
<div class="large-4 columns">
<input type="text" id="bucket" name="bucket" value="" placeholder="Bucket"/>
</div>
<div class="large-4 columns">
......@@ -46,12 +46,17 @@
<div class="large-4 columns">
<input type="text" id="end" name="end" value="" placeholder="End date"/>
</div>
</div>
<div class="row">
<div class="large-10 columns">
<input type="text" id="filter" name="filter" value="" placeholder="Filter"/>
</div>
<div class="small-2 columns">
<button type="submit" class="button postfix">Lookup</button>
</div>
</form>
</div>
</div>
</form>
<div class="row">
<div class="large-12 columns">
<table>
......
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
$(function() {
msgpack.download(
"", {header: {accept:"application/x-msgpack"}},
function(d) {
console.log(d)
d.forEach(function(e) {
var date = new Date(e.timestamp/1000/1000);
$("#events").append("<tr><td>" + date +
"</td><td>" + JSON.stringify(e.event) + "</td></tr>")
})
$("#filter").val(getParameterByName("filter", window.location));
$("#start").val(getParameterByName("start", window.location));
$("#end").val(getParameterByName("end", window.location));
$("#bucket").val(getParameterByName("bucket", window.location));
msgpack.download(
"", {header: {accept:"application/x-msgpack"}},
function(d) {
d.forEach(function(e) {
var date = new Date(e.timestamp/1000/1000);
$("#events").append("<tr><td>" + date +
"</td><td>" + JSON.stringify(e.event) + "</td></tr>")
})
})
})
......@@ -11,7 +11,16 @@ init(_Transport, Req, []) ->
-dialyzer({no_opaque, handle/2}).
handle(Req, State) ->
{ContentType, Req1} = dalmatiner_idx_handler:content_type(Req),
{Filter, Req0} =
case cowboy_req:qs_val(<<"filter">>, Req) of
{undefined, Req0x} ->
{[], Req0x};
{<<>>, Req0x} ->
{[], Req0x};
{Q, Req0x} ->
{event_query:parse(Q), Req0x}
end,
{ContentType, Req1} = dalmatiner_idx_handler:content_type(Req0),
{Bucket, Req2} = cowboy_req:qs_val(<<"bucket">>, Req1),
{StartS, Req3} = cowboy_req:qs_val(<<"start">>, Req2),
{EndS, Req4} = cowboy_req:qs_val(<<"end">>, Req3),
......@@ -43,7 +52,7 @@ handle(Req, State) ->
Start = erlang:convert_time_unit(StartSec, seconds, nano_seconds),
EndSec = qdate:to_unixtime(EndS),
End = erlang:convert_time_unit(EndSec, seconds, nano_seconds),
{ok, Es} = ddb_connection:read_events(Bucket, Start, End),
{ok, Es} = ddb_connection:read_events(Bucket, Start, End, Filter),
Es1 = [[{<<"timestamp">>, T}, {<<"event">>, E}] ||
{T, E} <- Es],
dalmatiner_idx_handler:send(ContentType, Es1, Req4, State)
......
%%%-------------------------------------------------------------------
%%% @author Heinz Nikolaus Gies <heinz@licenser.net>
%%% @copyright (C) 2016, Heinz Nikolaus Gies
%%% @doc
%%%
%%% @end
%%% Created : 20 Sep 2016 by Heinz Nikolaus Gies <heinz@licenser.net>
%%%-------------------------------------------------------------------
-module(event_query).
-export([parse/1]).
parse(S) when is_binary(S) ->
parse(binary_to_list(S));
parse(S) ->
{ok, L, _} = event_query_lexer:string(S),
{ok, T} = event_query_parser:parse(L),
flatten(T).
flatten({'and', A, B}) ->
lists:flatten([flatten(A), flatten(B)]);
flatten({'or', A, B}) ->
[{'or', flatten(A), flatten(B)}];
flatten({'not', A}) ->
[{'not', flatten(A)}];
flatten(O) ->
[O].
This diff is collapsed.
This diff is collapsed.
......@@ -3,6 +3,7 @@
[{config,
[#{dirs => ["apps/*/src"],
filter => "*.erl",
ignore => [event_query_parser, event_query_lexer],
rules => [{elvis_style, line_length,
#{ignore => [],
limit => 80,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment