Search in sources :

Example 1 with LogQueryArrayStream

use of com.serotonin.m2m2.web.mvc.rest.v1.model.logging.LogQueryArrayStream in project ma-modules-public by infiniteautomation.

the class LoggingRestController method query.

@PreAuthorize("isAdmin()")
@ApiOperation(value = "Query ma.log logs", notes = "Returns a list of recent logs, ie. /by-filename/ma.log?limit(10)\n" + "<br>Query Examples: \n" + "by-filename/ma.log/?level=gt=DEBUG\n" + "by-filename/ma.log/?thread=qtp-1\n" + "by-filename/ma.log/?message=setPointValue\n" + "NOTE: Querying non ma.log files is not supported.")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/by-filename/{filename}")
public ResponseEntity<QueryArrayStream<?>> query(@PathVariable String filename, HttpServletRequest request) {
    RestProcessResult<QueryArrayStream<?>> result = new RestProcessResult<QueryArrayStream<?>>(HttpStatus.OK);
    try {
        ASTNode query = parseRQLtoAST(request.getQueryString());
        File file = new File(Common.getLogsDir(), filename);
        if (file.exists()) {
            // Pattern pattern = new
            if (filename.matches(LogQueryArrayStream.LOGFILE_REGEX)) {
                LogQueryArrayStream stream = new LogQueryArrayStream(filename, query);
                return result.createResponseEntity(stream);
            } else {
                throw new AccessDeniedException("Non ma.log files are not accessible on this endpoint.");
            }
        } else {
            result.addRestMessage(getDoesNotExistMessage());
        }
    } catch (InvalidRQLRestException e) {
        LOG.error(e.getMessage(), e);
        result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
        return result.createResponseEntity();
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) AccessDeniedException(org.springframework.security.access.AccessDeniedException) InvalidRQLRestException(com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException) ASTNode(net.jazdw.rql.parser.ASTNode) QueryArrayStream(com.serotonin.m2m2.web.mvc.rest.v1.model.QueryArrayStream) LogQueryArrayStream(com.serotonin.m2m2.web.mvc.rest.v1.model.logging.LogQueryArrayStream) File(java.io.File) LogQueryArrayStream(com.serotonin.m2m2.web.mvc.rest.v1.model.logging.LogQueryArrayStream) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

InvalidRQLRestException (com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException)1 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)1 QueryArrayStream (com.serotonin.m2m2.web.mvc.rest.v1.model.QueryArrayStream)1 LogQueryArrayStream (com.serotonin.m2m2.web.mvc.rest.v1.model.logging.LogQueryArrayStream)1 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 File (java.io.File)1 ASTNode (net.jazdw.rql.parser.ASTNode)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1