Search in sources :

Example 1 with HealthData

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;
}
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 2 with HealthData

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);
}
Also used : HealthData(password.pwm.ws.server.rest.bean.HealthData) RestMethodHandler(password.pwm.ws.server.RestMethodHandler)

Example 3 with HealthData

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;
}
Also used : HealthData(password.pwm.ws.server.rest.bean.HealthData) HealthRecord(password.pwm.ws.server.rest.bean.HealthRecord) HealthMonitor(password.pwm.health.HealthMonitor) ArrayList(java.util.ArrayList)

Example 4 with 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;
}
Also used : HealthData(password.pwm.ws.server.rest.bean.HealthData)

Example 5 with 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;
}
Also used : HealthData(password.pwm.ws.server.rest.bean.HealthData) PwmException(password.pwm.error.PwmException) ErrorInformation(password.pwm.error.ErrorInformation) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException) RestResultBean(password.pwm.ws.server.RestResultBean)

Aggregations

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