use of password.pwm.ws.server.rest.bean.HealthData 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.ws.server.rest.bean.HealthData in project pwm by pwm-project.
the class RestHealthServer method doPwmHealthJsonGet.
@RestMethodHandler(method = HttpMethod.GET, consumes = HttpContentType.json, produces = HttpContentType.json)
private RestResultBean doPwmHealthJsonGet(final RestRequest restRequest) throws PwmUnrecoverableException, IOException {
final boolean requestImmediateParam = restRequest.readParameterAsBoolean(PARAM_IMMEDIATE_REFRESH);
final HealthData jsonOutput = processGetHealthCheckData(restRequest.getPwmApplication(), restRequest.getLocale(), requestImmediateParam);
StatisticsManager.incrementStat(restRequest.getPwmApplication(), Statistic.REST_HEALTH);
return RestResultBean.withData(jsonOutput);
}
use of password.pwm.ws.server.rest.bean.HealthData in project pwm by pwm-project.
the class RestHealthServer method processGetHealthCheckData.
public static HealthData processGetHealthCheckData(final PwmApplication pwmApplication, final Locale locale, final boolean refreshImmediate) throws IOException, PwmUnrecoverableException {
final HealthMonitor healthMonitor = pwmApplication.getHealthMonitor();
final HealthMonitor.CheckTimeliness timeliness = determineDataTimeliness(refreshImmediate);
final List<password.pwm.health.HealthRecord> healthRecords = new ArrayList<>(healthMonitor.getHealthRecords(timeliness));
final List<HealthRecord> healthRecordBeans = HealthRecord.fromHealthRecords(healthRecords, locale, pwmApplication.getConfig());
final HealthData healthData = new HealthData();
healthData.timestamp = healthMonitor.getLastHealthCheckTime();
healthData.overall = healthMonitor.getMostSevereHealthStatus(timeliness).toString();
healthData.records = healthRecordBeans;
return healthData;
}
use of password.pwm.ws.server.rest.bean.HealthData in project pwm by pwm-project.
the class HealthRecord method asHealthDataBean.
public static HealthData asHealthDataBean(final Configuration configuration, final Locale locale, final List<HealthRecord> profileRecords) {
final List<password.pwm.ws.server.rest.bean.HealthRecord> healthRecordBeans = password.pwm.ws.server.rest.bean.HealthRecord.fromHealthRecords(profileRecords, locale, configuration);
final HealthData healthData = new HealthData();
healthData.timestamp = Instant.now();
healthData.overall = HealthMonitor.getMostSevereHealthStatus(profileRecords).toString();
healthData.records = healthRecordBeans;
return healthData;
}
use of password.pwm.ws.server.rest.bean.HealthData in project pwm by pwm-project.
the class ClientApiServlet method restHealthProcessor.
@ActionHandler(action = "health")
public ProcessStatus restHealthProcessor(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException {
if (pwmRequest.getPwmApplication().getApplicationMode() == PwmApplicationMode.RUNNING) {
if (!pwmRequest.isAuthenticated()) {
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_AUTHENTICATION_REQUIRED);
LOGGER.debug(pwmRequest, errorInformation);
pwmRequest.respondWithError(errorInformation);
return ProcessStatus.Halt;
}
if (!pwmRequest.getPwmSession().getSessionManager().checkPermission(pwmRequest.getPwmApplication(), Permission.PWMADMIN)) {
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNAUTHORIZED, "admin privileges required");
LOGGER.debug(pwmRequest, errorInformation);
pwmRequest.respondWithError(errorInformation);
return ProcessStatus.Halt;
}
}
try {
final HealthData jsonOutput = RestHealthServer.processGetHealthCheckData(pwmRequest.getPwmApplication(), pwmRequest.getLocale(), false);
final RestResultBean restResultBean = RestResultBean.withData(jsonOutput);
pwmRequest.outputJsonResult(restResultBean);
} catch (PwmException e) {
final ErrorInformation errorInformation = e.getErrorInformation();
LOGGER.debug(pwmRequest, errorInformation);
pwmRequest.respondWithError(errorInformation);
} catch (Exception e) {
final String errorMessage = "unexpected error executing web service: " + e.getMessage();
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMessage);
LOGGER.debug(pwmRequest, errorInformation);
pwmRequest.respondWithError(errorInformation);
}
return ProcessStatus.Halt;
}
Aggregations