Permalink
Browse files

more work on 020

  • Loading branch information...
1 parent 4717978 commit e1ac40701ca1b73b5eac265e73d56280894f6a49 @lennartkoopmann lennartkoopmann committed Apr 27, 2013
View
@@ -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.
@@ -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);
@@ -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();
@@ -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);
}
}
@@ -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) {
@@ -12,6 +12,11 @@
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));
}
View
@@ -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;
+ }
+
+}
@@ -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;
+ }
+
}
@@ -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);
+ }
+
+}
@@ -0,0 +1,7 @@
+package models.api.responses;
+
+public class MessageCountResponse {
+
+ public int events;
+
+}
@@ -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;
+ }
+
+}
@@ -45,10 +45,12 @@ public int getTotalResultCount() {
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;
}
@@ -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>
@@ -2,4 +2,6 @@
@main("Dashboard", sidebars.standard(currentUser), "", currentUser) {
+ Containing <span class="total-events">[<i class="icon-spinner icon-spin"></i>]</span> events.
+
}
@@ -15,13 +15,7 @@
<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>
@@ -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>
@@ -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()
+}
@@ -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>
@@ -9,6 +9,7 @@
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()) {
@@ -27,4 +28,5 @@
<br />
<h3>Analyze field</h3>
-... tba ...
+... tba ...
+}
View
@@ -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)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Deleted file not rendered
Oops, something went wrong.

0 comments on commit e1ac407

Please sign in to comment.