Skip to content
This repository has been archived by the owner on Jan 8, 2019. It is now read-only.

Commit

Permalink
more work on 020
Browse files Browse the repository at this point in the history
  • Loading branch information
Lennart Koopmann committed Apr 27, 2013
1 parent 4717978 commit e1ac407
Show file tree
Hide file tree
Showing 24 changed files with 251 additions and 58 deletions.
7 changes: 7 additions & 0 deletions NASA_IMAGES.txt
@@ -0,0 +1,7 @@
The images used as login screen backgrounds are from the Nasa Commons and do not fall under any copyright restrictions.

* http://www.flickr.com/photos/nasacommons/4858567220

Fore more information see http://www.nasa.gov/audience/formedia/features/MP_Photo_Guidelines.html

Thank you, NASA.
30 changes: 24 additions & 6 deletions app/controllers/MessageCountsController.java
Expand Up @@ -9,13 +9,31 @@
import com.google.gson.Gson;

import lib.APIException;
import models.MessageCount;
import models.MessageCountHistogram;
import models.api.results.DateHistogramResult;
import models.MessageCount;
import models.api.results.MessageCountResult;
import play.mvc.*;

public class MessageCountsController extends AuthenticatedController {

public static Result total(String timerange) {
public static Result total() {
try {
MessageCount count = new MessageCount();
MessageCountResult countResult = count.total();

Map<String, Integer> result = Maps.newHashMap();
result.put("events", countResult.getEventsCount());

return ok(new Gson().toJson(result)).as("application/json");
} catch (IOException e) {
return internalServerError("io exception");
} catch (APIException e) {
return internalServerError("api exception " + e);
}
}

public static Result histogram(String timerange) {
int range;
try {
range = Integer.parseInt(timerange);
Expand All @@ -24,8 +42,8 @@ public static Result total(String timerange) {
}

try {
MessageCount count = new MessageCount("minute", range);
DateHistogramResult histogramResult = count.total();
MessageCountHistogram count = new MessageCountHistogram("minute", range);
DateHistogramResult histogramResult = count.histogram();

List<Map<String, Object>> lines = Lists.newArrayList();
Map<String, Object> r = Maps.newTreeMap();
Expand All @@ -37,9 +55,9 @@ public static Result total(String timerange) {

return ok(new Gson().toJson(lines)).as("application/json");
} catch (IOException e) {
return ok("io exception");
return internalServerError("io exception");
} catch (APIException e) {
return ok("api exception" + e);
return internalServerError("api exception " + e);
}
}

Expand Down
6 changes: 5 additions & 1 deletion app/controllers/SearchController.java
Expand Up @@ -35,7 +35,11 @@ public static Result index(String q, String timerange, String interval) {
SearchResult searchResult = search.search();
DateHistogramResult histogramResult = search.dateHistogram(interval);

return ok(views.html.search.results.render(currentUser(), searchResult, histogramResult, q));
if (searchResult.getTotalResultCount() > 0) {
return ok(views.html.search.results.render(currentUser(), searchResult, histogramResult, q));
} else {
return ok(views.html.search.noresults.render(currentUser(), q));
}
} catch (IOException e) {
return status(504, views.html.errors.error.render(Api.ERROR_MSG_IO, e, request()));
} catch (APIException e) {
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/SessionsController.java
Expand Up @@ -12,6 +12,11 @@ public class SessionsController extends Controller {
final static Form<LoginRequest> userForm = form(LoginRequest.class);

public static Result index() {
// Redirect if already logged in.
if (session("username") != null && !session("username").isEmpty()) {
return redirect("/");
}

return ok(views.html.sessions.login.render(userForm));
}

Expand Down
36 changes: 36 additions & 0 deletions app/lib/Tools.java
@@ -0,0 +1,36 @@
/**
* Copyright 2013 Lennart Koopmann <lennart@torch.sh>
*
* This file is part of Graylog2.
*
* Graylog2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Graylog2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Graylog2. If not, see <http://www.gnu.org/licenses/>.
*
*/
package lib;

import java.util.Random;

/**
* @author Lennart Koopmann <lennart@torch.sh>
*/
public class Tools {

private Tools() { /* pure utility class */ }

public static int random(int min, int max) {
Random rand = new Random();
return rand.nextInt(max - min + 1) + min;
}

}
42 changes: 21 additions & 21 deletions app/models/MessageCount.java
@@ -1,29 +1,29 @@
package models;

import java.io.IOException;
import java.net.URL;

import lib.APIException;
import lib.Api;
import models.api.responses.DateHistogramResponse;
import models.api.results.DateHistogramResult;
import models.api.responses.MessageCountResponse;
import models.api.results.MessageCountResult;
import play.cache.Cache;

import java.io.IOException;
import java.net.URL;

public class MessageCount {

private final String interval;
private final int timerange;

public MessageCount(String interval, int timerange) {
this.interval = interval;
this.timerange = timerange;
}

public DateHistogramResult total() throws IOException, APIException {
String i = Api.urlEncode(interval);
URL url = Api.buildTarget("count/total?interval=" + i + "&timerange=" + timerange);

DateHistogramResponse response = Api.get(url, new DateHistogramResponse());
return new DateHistogramResult("match_all", response.time, response.interval, response.results);
}

public static final int TOTAL_CNT_CACHE_TTL = 2; // seconds
public static final String TOTAL_CNT_CACHE_KEY = "counts.total";

public MessageCountResult total() throws IOException, APIException {
MessageCountResult cached = (MessageCountResult) Cache.get(TOTAL_CNT_CACHE_KEY);
if (cached != null) {
return cached;
}

MessageCountResponse response = Api.get(Api.buildTarget("count/total"), new MessageCountResponse());
MessageCountResult result = new MessageCountResult(response.events);
Cache.set(TOTAL_CNT_CACHE_KEY, result, TOTAL_CNT_CACHE_TTL);
return result;
}

}
29 changes: 29 additions & 0 deletions app/models/MessageCountHistogram.java
@@ -0,0 +1,29 @@
package models;

import java.io.IOException;
import java.net.URL;

import lib.APIException;
import lib.Api;
import models.api.responses.DateHistogramResponse;
import models.api.results.DateHistogramResult;

public class MessageCountHistogram {

private final String interval;
private final int timerange;

public MessageCountHistogram(String interval, int timerange) {
this.interval = interval;
this.timerange = timerange;
}

public DateHistogramResult histogram() throws IOException, APIException {
String i = Api.urlEncode(interval);
URL url = Api.buildTarget("count/histogram?interval=" + i + "&timerange=" + timerange);

DateHistogramResponse response = Api.get(url, new DateHistogramResponse());
return new DateHistogramResult("match_all", response.time, response.interval, response.results);
}

}
7 changes: 7 additions & 0 deletions app/models/api/responses/MessageCountResponse.java
@@ -0,0 +1,7 @@
package models.api.responses;

public class MessageCountResponse {

public int events;

}
15 changes: 15 additions & 0 deletions app/models/api/results/MessageCountResult.java
@@ -0,0 +1,15 @@
package models.api.results;

public class MessageCountResult {

private final int eventsCount;

public MessageCountResult(int eventsCount) {
this.eventsCount = eventsCount;
}

public int getEventsCount() {
return eventsCount;
}

}
10 changes: 6 additions & 4 deletions app/models/api/results/SearchResult.java
Expand Up @@ -45,10 +45,12 @@ public List<Field> getFields() {

private List<Field> buildFields(List<String> sFields) {
List<Field> fields = Lists.newArrayList();

for (String field : sFields) {
fields.add(new Field(field));
}

if (sFields != null) {
for (String field : sFields) {
fields.add(new Field(field));
}
}

return fields;
}
Expand Down
3 changes: 3 additions & 0 deletions app/views/auth.scala.html
Expand Up @@ -8,11 +8,14 @@
<link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")">

<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/bootstrap.min.css")">
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/fonts.css")">
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/font-awesome.min.css")">
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/auth.css")">

<script src="@routes.Assets.at("javascripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
<script src="@routes.Assets.at("javascripts/bootstrap.min.js")" type="text/javascript"></script>
</head>

<body>
@content
</body>
Expand Down
2 changes: 2 additions & 0 deletions app/views/dashboard/index.scala.html
Expand Up @@ -2,4 +2,6 @@

@main("Dashboard", sidebars.standard(currentUser), "", currentUser) {

Containing <span class="total-events">[<i class="icon-spinner icon-spin"></i>]</span> events.

}
8 changes: 1 addition & 7 deletions app/views/errors/error.scala.html
Expand Up @@ -15,13 +15,7 @@ <h1>
<h3><strong>Reason:</strong> @message</h3>
</p>

<h2>What should I do now?</h2>
<p>
Please consult the <a href="http://support.torch.sh/" target="_blank">support pages</a> if you don't
know how to fix this problem. Contact the <a href="http://www.graylog2.org/support" target="_blank">
mailing list</a> or <a href="https://github.com/Graylog2/" target="_blank">file an issue</a> if in
doubt about anything or you have questions left.
</p>
@partials.support_sources()

<div class="well well-small crash-info">
<h2>Stacktrace</h2>
Expand Down
11 changes: 11 additions & 0 deletions app/views/partials/support_sources.scala.html
@@ -0,0 +1,11 @@
<div class="support-sources well well-small">
<h2>Need help?</h2>
Do not hesitate to consult the Graylog2 community if your questions are not answered in the
<a href="http://support.torch.sh/help/kb" target="_blank">documentation</a>.

<ul>
<li><i class="icon-group"></i> <a href="http://support.torch.sh/help/kb/general/forums-mailing-list" target="_blank">Forum / Mailing list</a></li>
<li><i class="icon-github-alt"></i> <a href="http://support.torch.sh/help/kb/general/issue-trackers" target="_blank">Issue trackers</a></li>
<li><i class="icon-heart"></i> <a href="http://www.torch.sh/" target="_blank">Commercial support</a></li>
</ul>
</div>
16 changes: 16 additions & 0 deletions app/views/search/noresults.scala.html
@@ -0,0 +1,16 @@
@(currentUser: User, query: String)

@main("Search results", sidebars.standard(currentUser), query, currentUser) {
<h1>
<i class="icon-search icon-large"></i>
Nothing found
</h1>

<p>
Your search returned no results. Take a look at the
<a href="http://support.torch.sh/help/kb/graylog2-web-interface/message-search-syntax" target="_blank">documentation</a>
if you need help with the search syntax.
</p>

@partials.support_sources()
}
20 changes: 9 additions & 11 deletions app/views/sessions/login.scala.html
@@ -1,28 +1,26 @@
@(loginForm: Form[LoginRequest])

@auth(title = "Login") {
@auth(title = "Welcome to Graylog2 - Sign in") {

<div class="container">
<div class="container" id="login-box">
<div class="row">
<div class="span4 offset4 well">
<legend>Welcome to Graylog2</legend>

<div class="span4 offset4 well" id="login-box-content">
<legend>
<i class="icon-group"></i> Welcome to Graylog2
</legend>

@if(flash.get("error") != null && !flash.get("error").isEmpty()) {
<div class="alert alert-error">
<a class="close" data-dismiss="alert" href="#">×</a>@flash.get("error")
</div>
}

@helper.form(action = controllers.routes.SessionsController.create()) {
<input type="text" id="username" class="span4" name="username" placeholder="Username">
<input type="password" id="password" class="span4" name="password" placeholder="Password">

<label class="checkbox">
<input type="checkbox" name="remember" value="1"> Remember Me
</label>
<button type="submit" name="submit" class="btn btn-info btn-block">Sign in</button>
}

</div>
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion app/views/sidebars/searchresults.scala.html
Expand Up @@ -9,6 +9,7 @@ <h2>
Found @searchResult.getTotalResultCount() messages in @searchResult.getTookMs()ms.
</p>

@if(searchResult.getTotalResultCount() > 0) {
<h3>Select fields</h3>
<ul class="search-result-fields">
@for(f <- searchResult.getFields()) {
Expand All @@ -27,4 +28,5 @@ <h3>Select fields</h3>

<br />
<h3>Analyze field</h3>
... tba ...
... tba ...
}
5 changes: 3 additions & 2 deletions conf/routes
Expand Up @@ -19,8 +19,9 @@ GET /messages/:index/:id/partial controllers.MessagesController.asPartial(index
# Streams
GET /streams controllers.StreamsController.index()

# API: Message counts
GET /a/messagecounts/total controllers.MessageCountsController.total(timerange ?= "")
# API: Message counts and histograms
GET /a/messagecounts/histogram controllers.MessageCountsController.histogram(timerange ?= "")
GET /a/messagecounts/total controllers.MessageCountsController.total()

# API: Message analyzing
GET /a/analyze/:index/:id/:field controllers.MessagesController.analyze(index: String, id: String, field: String)
Expand Down
Binary file added public/images/auth/loginbg.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed public/images/auth/pattern.png
Binary file not shown.

0 comments on commit e1ac407

Please sign in to comment.