Search in sources :

Example 1 with IdmLoggingEventFilter

use of eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmLoggingEventFilter in project CzechIdMng by bcvsolutions.

the class LoggingEventMonitoringEvaluator method evaluate.

@Override
public IdmMonitoringResultDto evaluate(IdmMonitoringDto monitoring) {
    IdmMonitoringResultDto result = new IdmMonitoringResultDto();
    ResultModel resultModel;
    // 
    IdmLoggingEventFilter filter = new IdmLoggingEventFilter();
    filter.setLevelString(LogType.ERROR);
    Long givenNumberOfDays = getParameterConverter().toLong(monitoring.getEvaluatorProperties(), PARAMETER_NUMBER_OF_DAYS);
    if (givenNumberOfDays != null) {
        filter.setFrom(ZonedDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays(givenNumberOfDays));
    }
    long count = loggingEventService.count(filter);
    // 
    if (count > 0) {
        resultModel = new DefaultResultModel(CoreResultCode.MONITORING_LOGGING_EVENT_ERROR, ImmutableMap.of("count", Long.toString(count)));
    } else {
        resultModel = new DefaultResultModel(CoreResultCode.OK);
    }
    // 
    result.setResult(new OperationResultDto.Builder(OperationState.EXECUTED).setModel(resultModel).build());
    result.setValue(String.valueOf(count));
    // 
    return result;
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmLoggingEventFilter(eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmLoggingEventFilter) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) IdmMonitoringResultDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto)

Example 2 with IdmLoggingEventFilter

use of eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmLoggingEventFilter in project CzechIdMng by bcvsolutions.

the class IdmDbAppenderTest method append.

@Test
public void append() {
    final IdmDbAppender appender = new IdmDbAppender(loggingEventService, eventExceptionService, propertyService);
    LoggerContext context = new LoggerContext();
    final Logger logger = context.getLogger(IdmDbAppenderTest.class);
    final RuntimeException runtimeException = new RuntimeException();
    runtimeException.setStackTrace(new StackTraceElement[] { new StackTraceElement(IdmDbAppenderTest.class.getCanonicalName(), "test", "file", 0) });
    ILoggingEvent loggingEvent = new LoggingEvent(IdmDbAppenderTest.class.getCanonicalName(), logger, Level.ERROR, "TEST", runtimeException, new String[] {});
    appender.append(loggingEvent);
    IdmLoggingEventFilter eventFilter = new IdmLoggingEventFilter();
    eventFilter.setLoggerName(IdmDbAppenderTest.class.getCanonicalName());
    final List<IdmLoggingEventDto> foundEvents = loggingEventService.find(eventFilter, null).getContent();
    Assert.assertEquals(1, foundEvents.size());
    final IdmLoggingEventDto loggingEventDto = foundEvents.get(0);
    Assert.assertEquals("TEST", loggingEventDto.getFormattedMessage());
    Assert.assertEquals(IdmDbAppenderTest.class.getCanonicalName(), loggingEventDto.getLoggerName());
    Assert.assertEquals("ERROR", loggingEventDto.getLevelString().name());
    IdmLoggingEventExceptionFilter loggingEventExceptionFilter = new IdmLoggingEventExceptionFilter();
    loggingEventExceptionFilter.setEvent((Long) loggingEventDto.getId());
    // 
    final List<IdmLoggingEventExceptionDto> exceptions = eventExceptionService.find(loggingEventExceptionFilter, null).getContent();
    Assert.assertEquals(2, exceptions.size());
    IdmLoggingEventExceptionDto exceptionDto = exceptions.stream().filter(e -> ((long) e.getId()) == 1l).findFirst().get();
    Assert.assertTrue(exceptionDto.getTraceLine().contains("test"));
    Assert.assertTrue(exceptionDto.getTraceLine().contains("file"));
    Assert.assertTrue(exceptionDto.getTraceLine().contains("0"));
}
Also used : IdmLoggingEventExceptionDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmLoggingEventExceptionDto) IdmLoggingEventFilter(eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmLoggingEventFilter) IdmLoggingEventExceptionFilter(eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmLoggingEventExceptionFilter) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) IdmLoggingEventDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmLoggingEventDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 3 with IdmLoggingEventFilter

use of eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmLoggingEventFilter in project CzechIdMng by bcvsolutions.

the class DefaultIdmLoggingEventService method getEntity.

@Override
protected IdmLoggingEvent getEntity(Serializable id, BasePermission... permission) {
    Assert.notNull(id, "Identifier is requiered for load an log event.");
    IdmLoggingEventFilter filter = new IdmLoggingEventFilter();
    filter.setId(Long.valueOf(id.toString()));
    List<IdmLoggingEventDto> entities = this.find(filter, null, permission).getContent();
    if (entities.isEmpty()) {
        return null;
    }
    // for given id must found only one entity
    IdmLoggingEvent entity = this.toEntity(entities.get(0));
    return checkAccess(entity, permission);
}
Also used : IdmLoggingEventDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmLoggingEventDto) IdmLoggingEvent(eu.bcvsolutions.idm.core.audit.entity.IdmLoggingEvent) IdmLoggingEventFilter(eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmLoggingEventFilter)

Example 4 with IdmLoggingEventFilter

use of eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmLoggingEventFilter in project CzechIdMng by bcvsolutions.

the class RemoveOldLogsTaskExecutor method process.

@Override
public Boolean process() {
    ZonedDateTime dateTimeTill = ZonedDateTime.now().minusDays(numberOfDays);
    // 
    IdmLoggingEventFilter filter = new IdmLoggingEventFilter();
    filter.setTill(dateTimeTill);
    // only for get total elements
    Page<IdmLoggingEventDto> loggingEvents = loggingEventService.find(filter, PageRequest.of(0, 1, Sort.by(IdmLoggingEvent_.timestmp.getName())));
    // 
    this.count = loggingEvents.getTotalElements();
    this.setCounter(0l);
    this.updateState();
    // 
    int deletedItems = loggingEventService.deleteLowerOrEqualTimestamp(dateTimeTill.toInstant().toEpochMilli());
    this.setCounter(Long.valueOf(deletedItems));
    // 
    LOG.info("Removed logs older than [{}] days was successfully completed. Removed logs [{}].", numberOfDays, this.counter);
    // 
    return Boolean.TRUE;
}
Also used : IdmLoggingEventDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmLoggingEventDto) ZonedDateTime(java.time.ZonedDateTime) IdmLoggingEventFilter(eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmLoggingEventFilter)

Aggregations

IdmLoggingEventFilter (eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmLoggingEventFilter)4 IdmLoggingEventDto (eu.bcvsolutions.idm.core.api.audit.dto.IdmLoggingEventDto)3 Logger (ch.qos.logback.classic.Logger)1 LoggerContext (ch.qos.logback.classic.LoggerContext)1 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1 LoggingEvent (ch.qos.logback.classic.spi.LoggingEvent)1 IdmLoggingEventExceptionDto (eu.bcvsolutions.idm.core.api.audit.dto.IdmLoggingEventExceptionDto)1 IdmLoggingEventExceptionFilter (eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmLoggingEventExceptionFilter)1 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)1 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)1 ResultModel (eu.bcvsolutions.idm.core.api.dto.ResultModel)1 IdmLoggingEvent (eu.bcvsolutions.idm.core.audit.entity.IdmLoggingEvent)1 IdmMonitoringResultDto (eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto)1 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)1 ZonedDateTime (java.time.ZonedDateTime)1 Test (org.junit.Test)1