/**
* 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 org.graylog2.rest.resources.dashboards;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.annotation.Timed;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.graylog2.dashboards.Dashboard;
import org.graylog2.dashboards.DashboardImpl;
import org.graylog2.dashboards.DashboardRegistry;
import org.graylog2.dashboards.DashboardService;
import org.graylog2.dashboards.widgets.DashboardWidget;
import org.graylog2.dashboards.widgets.InvalidWidgetConfigurationException;
import org.graylog2.database.ValidationException;
import org.graylog2.indexer.Indexer;
import org.graylog2.indexer.searches.timeranges.InvalidRangeParametersException;
import org.graylog2.rest.documentation.annotations.*;
import org.graylog2.rest.resources.RestResource;
import org.graylog2.rest.resources.dashboards.requests.*;
import org.graylog2.security.RestPermissions;
import org.graylog2.system.activities.Activity;
import org.graylog2.system.activities.ActivityWriter;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
/**
* @author Lennart Koopmann <lennart@torch.sh>
*/
@RequiresAuthentication
@Api(value = "Dashboards", description = "Manage dashboards")
@Path("/dashboards")
public class DashboardsResource extends RestResource {
private static final Logger LOG = LoggerFactory.getLogger(DashboardsResource.class);
private DashboardService dashboardService;
private DashboardRegistry dashboardRegistry;
private ActivityWriter activityWriter;
private MetricRegistry metricRegistry;
private Indexer indexer;
@Inject
public DashboardsResource(DashboardService dashboardService,
DashboardRegistry dashboardRegistry,
ActivityWriter activityWriter,
MetricRegistry metricRegistry,
Indexer indexer) {
this.dashboardService = dashboardService;
this.dashboardRegistry = dashboardRegistry;
this.activityWriter = activityWriter;
this.metricRegistry = metricRegistry;
this.indexer = indexer;
}
@POST
@Timed
@ApiOperation(value = "Create a dashboard")
@RequiresPermissions(RestPermissions.DASHBOARDS_CREATE)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = {
@ApiResponse(code = 403, message = "Request must be performed against master node.")
})
public Response create(@ApiParam(title = "JSON body", required = true) String body) {
restrictToMaster();
CreateRequest cr;
try {
cr = objectMapper.readValue(body, CreateRequest.class);
} catch(IOException e) {
LOG.error("Error while parsing JSON", e);
throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
}
// Create dashboard.
Map<String, Object> dashboardData = Maps.newHashMap();
dashboardData.put("title", cr.title);
dashboardData.put("description", cr.description);
dashboardData.put("creator_user_id", cr.creatorUserId);
dashboardData.put("created_at", new DateTime(DateTimeZone.UTC));
Dashboard dashboard = new DashboardImpl(dashboardData);
String id;
try {
id = dashboardService.save(dashboard);
} catch (ValidationException e) {
LOG.error("Validation error.", e);
throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
}
dashboardRegistry.add(dashboard);
Map<String, Object> result = Maps.newHashMap();
result.put("dashboard_id", id);
return Response.status(Response.Status.CREATED).entity(json(result)).build();
}
@GET @Timed
@ApiOperation(value = "Get a list of all dashboards and all configurations of their widgets.")
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = {
@ApiResponse(code = 403, message = "Request must be performed against master node.")
})
public String list() {
restrictToMaster();
List<Map<String, Object>> dashboards = Lists.newArrayList();
for (Dashboard dashboard : dashboardService.all()) {
if (isPermitted(RestPermissions.DASHBOARDS_READ, dashboard.getId())) {
dashboards.add(dashboard.asMap());
}
}
Map<String, Object> result = Maps.newHashMap();
result.put("total", dashboards.size());
result.put("dashboards", dashboards);
return json(result);
}
@GET @Timed
@ApiOperation(value = "Get a single dashboards and all configurations of its widgets.")
@Path("/{dashboardId}")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Dashboard not found."),
@ApiResponse(code = 403, message = "Request must be performed against master node.")
})
@Produces(MediaType.APPLICATION_JSON)
public String get(@ApiParam(title = "dashboardId", required = true) @PathParam("dashboardId") String dashboardId) {
restrictToMaster();
checkPermission(RestPermissions.DASHBOARDS_READ, dashboardId);
try {
Dashboard dashboard = dashboardService.load(dashboardId);
return json(dashboard.asMap());
} catch (org.graylog2.database.NotFoundException e) {
throw new WebApplicationException(404);
}
}
@DELETE @Timed
@ApiOperation(value = "Delete a dashboard and all its widgets")
@Produces(MediaType.APPLICATION_JSON)
@Path("/{dashboardId}")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Dashboard not found."),
@ApiResponse(code = 403, message = "Request must be performed against master node.")
})
public Response delete(@ApiParam(title = "dashboardId", required = true) @PathParam("dashboardId") String dashboardId) {
restrictToMaster();
checkPermission(RestPermissions.DASHBOARDS_EDIT, dashboardId);
try {
Dashboard dashboard = dashboardService.load(dashboardId);
dashboardRegistry.remove(dashboardId);
dashboardService.destroy(dashboard);
String msg = "Deleted dashboard <" + dashboard.getId() + ">. Reason: REST request.";
LOG.info(msg);
activityWriter.write(new Activity(msg, DashboardsResource.class));
} catch (org.graylog2.database.NotFoundException e) {
throw new WebApplicationException(404);
}
return Response.status(Response.Status.fromStatusCode(204)).build();
}
@PUT @Timed
@ApiOperation(value = "Update the settings of a dashboard.")
@Produces(MediaType.APPLICATION_JSON)
@Path("/{dashboardId}")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Dashboard not
没有合适的资源?快使用搜索试试~ 我知道了~
Graylog免费和开源的日志管理
共765个文件
java:681个
xml:18个
js:14个
需积分: 50 8 下载量 3 浏览量
2019-08-07
05:40:09
上传
评论 1
收藏 1.41MB ZIP 举报
温馨提示
Graylog:免费和开源的日志管理。集中和聚合所有的日志文件实现100%可视性。使用我们强大的查询语言,搜索TB级的日志数据,以发现和分析的重要信息。
资源推荐
资源详情
资源评论
收起资源包目录
Graylog免费和开源的日志管理 (765个子文件)
AUTHORS 41B
graylog2.conf 13KB
graylog2.conf 7KB
graylog2-radio.conf 4KB
graylog2-server.conf 337B
graylog2-server.conf 232B
COPYING 34KB
COPYING 34KB
screen.css 48KB
highlight.default.css 2KB
graylog2-server.init.d 2KB
blacklist.drl 893B
graylog2.drl 826B
graylog2.drl 693B
throbber.gif 9KB
.gitignore 514B
.gitignore 56B
.gitkeep 0B
.gitkeep 0B
graylog2-radio-node-id 36B
graylog2ctl 2KB
index.html 4KB
graylog2.init 3KB
syslog4j-graylog2-0.9.48-graylog2.jar 160KB
DashboardsResource.java 22KB
Searches.java 20KB
UsersResource.java 20KB
Configuration.java 19KB
AbsoluteSearchResource.java 17KB
Generator.java 17KB
KafkaInput.java 16KB
Indexer.java 16KB
RelativeSearchResource.java 16KB
KeywordSearchResource.java 16KB
SearchResource.java 15KB
Tools.java 15KB
StreamResource.java 15KB
SplitAndIndexExtractorTest.java 15KB
IndicesResource.java 15KB
Main.java 15KB
ExtractorsResource.java 14KB
InputsResource.java 14KB
Indices.java 12KB
MetricsResource.java 12KB
ConfigurationTest.java 12KB
StreamServiceImpl.java 12KB
PersistedServiceImpl.java 11KB
Extractor.java 11KB
InputServiceImpl.java 11KB
RadiosResource.java 11KB
DashboardWidget.java 11KB
MessageTest.java 11KB
Deflector.java 10KB
RestResource.java 10KB
RegexExtractorTest.java 10KB
SubstringExtractorTest.java 10KB
AMQPInput.java 10KB
SystemResource.java 10KB
Message.java 10KB
GELFHttpHandlerTest.java 10KB
InputsResource.java 10KB
MongoDbMetricsReporter.java 9KB
AlertServiceImpl.java 9KB
RestApiService.java 9KB
InputRegistry.java 9KB
LdapResource.java 9KB
IndexerTest.java 9KB
ServerBindings.java 9KB
PeriodicalsTest.java 9KB
RestPermissions.java 9KB
StreamRuleResource.java 9KB
AlarmCallbackResource.java 9KB
StreamAlertConditionResource.java 9KB
StaticEmailAlertSender.java 9KB
Main.java 9KB
DroolsEngine.java 9KB
StreamRouter.java 9KB
SyslogProcessor.java 8KB
MessageToJsonSerializer.java 8KB
StreamAlertReceiverResource.java 8KB
Consumer.java 8KB
ServerStatusTest.java 8KB
ToolsTest.java 8KB
UserImpl.java 8KB
JsonPathInput.java 8KB
Graylog2Reporter.java 8KB
OutputRouterTest.java 8KB
LdapSettingsImpl.java 8KB
StreamAlertResource.java 8KB
DiskJournalCache.java 8KB
ProcessBuffer.java 8KB
FieldValueAlertConditionTest.java 8KB
LibratoMetricsFormatterTest.java 8KB
VersionCheckThread.java 7KB
MessageInput.java 7KB
LoggersResource.java 7KB
GELFChunkManager.java 7KB
OutputBufferProcessor.java 7KB
MessageCountAlertConditionTest.java 7KB
FieldValueAlertCondition.java 7KB
共 765 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
weixin_39840387
- 粉丝: 784
- 资源: 3万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功