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;
}
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.");
}
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;
}
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);
}
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;
}
Aggregations