use of org.graylog2.cluster.Node in project opennms by OpenNMS.
the class SyslogEventForwarder method getTranslatedMessage.
/**
* Gets the translated message.
*
* @param event the event
* @param node the node
* @param msgFormat the message format
* @return the translated message
*/
private String getTranslatedMessage(Event event, OnmsNode node, String msgFormat) {
StandardEvaluationContext context = new StandardEvaluationContext(event);
if (node != null) {
context.setVariable("node", node);
}
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression(msgFormat, new TemplateParserContext("${", "}"));
try {
final String msg = (String) exp.getValue(context, String.class);
LOG.debug("getTranslatedMessage: {} ==> {}", msgFormat, msg);
return msg;
} catch (Exception e) {
LOG.warn("getTranslatedMessage: can't evaluate expression {} for alarm {} because: {}", msgFormat, event.getUei(), e.getMessage());
}
return null;
}
use of org.graylog2.cluster.Node in project graylog2-server by Graylog2.
the class InputServiceImpl method findForThisNode.
@Override
public Input findForThisNode(String nodeId, String id) throws NotFoundException, IllegalArgumentException {
final List<BasicDBObject> forThisNode = ImmutableList.of(new BasicDBObject(MessageInput.FIELD_NODE_ID, nodeId), new BasicDBObject(MessageInput.FIELD_GLOBAL, false));
final List<BasicDBObject> query = ImmutableList.of(new BasicDBObject("_id", new ObjectId(id)), new BasicDBObject("$and", forThisNode));
final DBObject o = findOne(InputImpl.class, new BasicDBObject("$and", query));
if (o == null) {
throw new NotFoundException("Couldn't find input " + id + " on Graylog node " + nodeId);
} else {
return new InputImpl((ObjectId) o.get("_id"), o.toMap());
}
}
use of org.graylog2.cluster.Node in project graylog2-server by Graylog2.
the class ClusterSystemResource method jvm.
@GET
@Timed
@ApiOperation(value = "Get JVM information of the given node")
@Path("{nodeId}/jvm")
public SystemJVMResponse jvm(@ApiParam(name = "nodeId", value = "The id of the node where processing will be paused.", required = true) @PathParam("nodeId") String nodeId) throws IOException, NodeNotFoundException {
final Node targetNode = nodeService.byNodeId(nodeId);
final RemoteSystemResource remoteSystemResource = remoteInterfaceProvider.get(targetNode, this.authenticationToken, RemoteSystemResource.class);
final Response<SystemJVMResponse> response = remoteSystemResource.jvm().execute();
if (response.isSuccessful()) {
return response.body();
} else {
LOG.warn("Unable to get jvm information on node {}: {}", nodeId, response.message());
throw new WebApplicationException(response.message(), BAD_GATEWAY);
}
}
use of org.graylog2.cluster.Node in project graylog2-server by Graylog2.
the class ClusterSystemShutdownResource method shutdown.
@POST
@Timed
@ApiOperation(value = "Shutdown node gracefully.", notes = "Attempts to process all buffered and cached messages before exiting, " + "shuts down inputs first to make sure that no new messages are accepted.")
@AuditEvent(type = AuditEventTypes.NODE_SHUTDOWN_INITIATE)
public void shutdown(@ApiParam(name = "nodeId", value = "The id of the node to shutdown.", required = true) @PathParam("nodeId") String nodeId) throws IOException, NodeNotFoundException {
final Node targetNode = nodeService.byNodeId(nodeId);
RemoteSystemShutdownResource remoteSystemShutdownResource = remoteInterfaceProvider.get(targetNode, this.authenticationToken, RemoteSystemShutdownResource.class);
final Response response = remoteSystemShutdownResource.shutdown().execute();
if (response.code() != ACCEPTED.getCode()) {
LOG.warn("Unable send shut down signal to node {}: {}", nodeId, response.message());
throw new WebApplicationException(response.message(), BAD_GATEWAY);
}
}
use of org.graylog2.cluster.Node in project graylog2-server by Graylog2.
the class ClusterLoggersResource method setSubsystemLoggerLevel.
@PUT
@Timed
@Path("/{nodeId}/subsystems/{subsystem}/level/{level}")
@ApiOperation(value = "Set the loglevel of a whole subsystem", notes = "Provided level is falling back to DEBUG if it does not exist")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such subsystem.") })
@NoAuditEvent("proxy resource, audit event will be emitted on target nodes")
public void setSubsystemLoggerLevel(@ApiParam(name = "nodeId", required = true) @PathParam("nodeId") @NotEmpty String nodeId, @ApiParam(name = "subsystem", required = true) @PathParam("subsystem") @NotEmpty String subsystemTitle, @ApiParam(name = "level", required = true) @PathParam("level") @NotEmpty String level) throws NodeNotFoundException, IOException {
final Node node = this.nodeService.byNodeId(nodeId);
final RemoteLoggersResource remoteLoggersResource = this.remoteInterfaceProvider.get(node, this.authenticationToken, RemoteLoggersResource.class);
remoteLoggersResource.setSubsystemLoggerLevel(subsystemTitle, level).execute();
}
Aggregations