Search in sources :

Example 1 with HealthRecord

use of password.pwm.health.HealthRecord in project pwm by pwm-project.

the class LocalDBLogger method healthCheck.

public List<HealthRecord> healthCheck() {
    final List<HealthRecord> healthRecords = new ArrayList<>();
    if (status != STATUS.OPEN) {
        healthRecords.add(HealthRecord.forMessage(HealthMessage.LocalDBLogger_NOTOPEN, status.toString()));
        return healthRecords;
    }
    final int eventCount = getStoredEventCount();
    if (eventCount > settings.getMaxEvents() + 5000) {
        final PwmNumberFormat numberFormat = PwmNumberFormat.forDefaultLocale();
        healthRecords.add(HealthRecord.forMessage(HealthMessage.LocalDBLogger_HighRecordCount, numberFormat.format(eventCount), numberFormat.format(settings.getMaxEvents())));
    }
    final Instant tailDate = getTailDate();
    if (tailDate != null) {
        final TimeDuration timeDuration = TimeDuration.fromCurrent(tailDate);
        final TimeDuration maxTimeDuration = settings.getMaxAge().add(TimeDuration.HOUR);
        if (timeDuration.isLongerThan(maxTimeDuration)) {
            // older than max age + 1h
            healthRecords.add(HealthRecord.forMessage(HealthMessage.LocalDBLogger_OldRecordPresent, timeDuration.asCompactString(), maxTimeDuration.asCompactString()));
        }
    }
    return healthRecords;
}
Also used : HealthRecord(password.pwm.health.HealthRecord) PwmNumberFormat(password.pwm.util.java.PwmNumberFormat) Instant(java.time.Instant) ArrayList(java.util.ArrayList) TimeDuration(password.pwm.util.java.TimeDuration)

Example 2 with HealthRecord

use of password.pwm.health.HealthRecord in project pwm by pwm-project.

the class UserReportCommand method doCommand.

@Override
@SuppressFBWarnings("DM_EXIT")
void doCommand() throws Exception {
    final File outputFile = (File) cliEnvironment.getOptions().get(OUTPUT_FILE_OPTIONNAME);
    try (OutputStream outputFileStream = new BufferedOutputStream(new FileOutputStream(outputFile))) {
        final PwmApplication pwmApplication = cliEnvironment.getPwmApplication();
        final ReportService userReport = pwmApplication.getReportService();
        if (userReport.status() != PwmService.STATUS.OPEN) {
            out("report service is not open or enabled");
            final List<HealthRecord> healthIssues = userReport.healthCheck();
            if (healthIssues != null) {
                for (final HealthRecord record : healthIssues) {
                    out("report health status: " + record.toDebugString(Locale.getDefault(), pwmApplication.getConfig()));
                }
            }
            return;
        }
        final ReportCsvUtility reportCsvUtility = new ReportCsvUtility(pwmApplication);
        reportCsvUtility.outputToCsv(outputFileStream, true, PwmConstants.DEFAULT_LOCALE);
    } catch (IOException e) {
        out("unable to open file '" + outputFile.getAbsolutePath() + "' for writing");
        System.exit(-1);
        throw new Exception();
    }
    out("report output complete.");
}
Also used : PwmApplication(password.pwm.PwmApplication) HealthRecord(password.pwm.health.HealthRecord) ReportService(password.pwm.svc.report.ReportService) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) ReportCsvUtility(password.pwm.svc.report.ReportCsvUtility) IOException(java.io.IOException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) IOException(java.io.IOException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 3 with HealthRecord

use of password.pwm.health.HealthRecord in project pwm by pwm-project.

the class ConfigEditorServlet method restSmsHealthCheck.

@ActionHandler(action = "smsHealthCheck")
private ProcessStatus restSmsHealthCheck(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final Instant startTime = Instant.now();
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    LOGGER.debug(pwmRequest, "beginning restSmsHealthCheck");
    final List<HealthRecord> returnRecords = new ArrayList<>();
    final Configuration config = new Configuration(configManagerBean.getStoredConfiguration());
    if (!SmsQueueManager.smsIsConfigured(config)) {
        returnRecords.add(new HealthRecord(HealthStatus.INFO, HealthTopic.SMS, "SMS not configured"));
    } else {
        final Map<String, String> testParams = pwmRequest.readBodyAsJsonStringMap();
        final SmsItemBean testSmsItem = new SmsItemBean(testParams.get("to"), testParams.get("message"), pwmRequest.getSessionLabel());
        try {
            final String responseBody = SmsQueueManager.sendDirectMessage(pwmRequest.getPwmApplication(), config, pwmRequest.getSessionLabel(), testSmsItem);
            returnRecords.add(new HealthRecord(HealthStatus.INFO, HealthTopic.SMS, "message sent"));
            returnRecords.add(new HealthRecord(HealthStatus.INFO, HealthTopic.SMS, "response body: \n" + StringUtil.escapeHtml(responseBody)));
        } catch (PwmException e) {
            returnRecords.add(new HealthRecord(HealthStatus.WARN, HealthTopic.SMS, "unable to send message: " + e.getMessage()));
        }
    }
    final HealthData healthData = HealthRecord.asHealthDataBean(config, pwmRequest.getLocale(), returnRecords);
    final RestResultBean restResultBean = RestResultBean.withData(healthData);
    pwmRequest.outputJsonResult(restResultBean);
    LOGGER.debug(pwmRequest, "completed restSmsHealthCheck in " + TimeDuration.fromCurrent(startTime).asCompactString());
    return ProcessStatus.Halt;
}
Also used : PwmException(password.pwm.error.PwmException) HealthData(password.pwm.ws.server.rest.bean.HealthData) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) HealthRecord(password.pwm.health.HealthRecord) Configuration(password.pwm.config.Configuration) SmsItemBean(password.pwm.bean.SmsItemBean) Instant(java.time.Instant) ArrayList(java.util.ArrayList) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 4 with HealthRecord

use of password.pwm.health.HealthRecord in project pwm by pwm-project.

the class AbstractWordlist method healthCheck.

public List<HealthRecord> healthCheck() {
    final List<HealthRecord> returnList = new ArrayList<>();
    if (autoImportError != null) {
        final HealthRecord healthRecord = HealthRecord.forMessage(HealthMessage.Wordlist_AutoImportFailure, this.getWordlistFileSetting().toMenuLocationDebug(null, PwmConstants.DEFAULT_LOCALE), autoImportError.getDetailedErrorMsg(), JavaHelper.toIsoDate(autoImportError.getDate()));
        returnList.add(healthRecord);
    }
    if (wlStatus == STATUS.OPENING) {
        final HealthRecord healthRecord = new HealthRecord(HealthStatus.CAUTION, HealthTopic.Application, this.debugLabel + " is not yet open: " + this.getDebugStatus());
        returnList.add(healthRecord);
    }
    if (lastError != null) {
        final HealthRecord healthRecord = new HealthRecord(HealthStatus.WARN, HealthTopic.Application, this.debugLabel + " error: " + lastError.toDebugStr());
        returnList.add(healthRecord);
    }
    return Collections.unmodifiableList(returnList);
}
Also used : HealthRecord(password.pwm.health.HealthRecord) ArrayList(java.util.ArrayList)

Example 5 with HealthRecord

use of password.pwm.health.HealthRecord in project pwm by pwm-project.

the class EmailService method healthCheck.

public List<HealthRecord> healthCheck() {
    if (pwmApplication.getLocalDB() == null || pwmApplication.getLocalDB().status() != LocalDB.Status.OPEN) {
        return Collections.singletonList(HealthRecord.forMessage(HealthMessage.ServiceClosed_LocalDBUnavail, this.getClass().getSimpleName()));
    }
    if (pwmApplication.getApplicationMode() == PwmApplicationMode.READ_ONLY) {
        return Collections.singletonList(HealthRecord.forMessage(HealthMessage.ServiceClosed_AppReadOnly, this.getClass().getSimpleName()));
    }
    final List<HealthRecord> records = new ArrayList<>();
    for (final Map.Entry<EmailServer, Optional<ErrorInformation>> entry : serverErrors.entrySet()) {
        if (entry.getValue().isPresent()) {
            final ErrorInformation errorInformation = entry.getValue().get();
            records.add(HealthRecord.forMessage(HealthMessage.Email_SendFailure, errorInformation.toDebugStr()));
        }
    }
    return records;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) HealthRecord(password.pwm.health.HealthRecord) Optional(java.util.Optional) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

HealthRecord (password.pwm.health.HealthRecord)11 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 Configuration (password.pwm.config.Configuration)4 PwmException (password.pwm.error.PwmException)4 RestResultBean (password.pwm.ws.server.RestResultBean)4 HealthData (password.pwm.ws.server.rest.bean.HealthData)4 IOException (java.io.IOException)3 Instant (java.time.Instant)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ConfigManagerBean (password.pwm.http.bean.ConfigManagerBean)3 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)2 Map (java.util.Map)2 ServletException (javax.servlet.ServletException)2 PwmApplication (password.pwm.PwmApplication)2 PwmOperationalException (password.pwm.error.PwmOperationalException)2 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)2 TimeDuration (password.pwm.util.java.TimeDuration)2 PasswordRuleHelper (com.novell.ldapchai.util.PasswordRuleHelper)1