Search in sources :

Example 1 with SmsItemBean

use of password.pwm.bean.SmsItemBean 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 SmsItemBean

use of password.pwm.bean.SmsItemBean in project pwm by pwm-project.

the class PwmApplication method sendSmsUsingQueue.

public void sendSmsUsingQueue(final String to, final String message, final SessionLabel sessionLabel, final MacroMachine macroMachine) {
    final SmsQueueManager smsQueue = getSmsQueue();
    if (smsQueue == null) {
        LOGGER.error(sessionLabel, "SMS queue is unavailable, unable to send SMS to: " + to);
        return;
    }
    final SmsItemBean smsItemBean = new SmsItemBean(macroMachine.expandMacros(to), macroMachine.expandMacros(message), sessionLabel);
    try {
        smsQueue.addSmsToQueue(smsItemBean);
    } catch (PwmUnrecoverableException e) {
        LOGGER.warn("unable to add sms to queue: " + e.getMessage());
    }
}
Also used : SmsQueueManager(password.pwm.util.queue.SmsQueueManager) SmsItemBean(password.pwm.bean.SmsItemBean) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException)

Aggregations

SmsItemBean (password.pwm.bean.SmsItemBean)2 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 Configuration (password.pwm.config.Configuration)1 PwmException (password.pwm.error.PwmException)1 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)1 HealthRecord (password.pwm.health.HealthRecord)1 ConfigManagerBean (password.pwm.http.bean.ConfigManagerBean)1 SmsQueueManager (password.pwm.util.queue.SmsQueueManager)1 RestResultBean (password.pwm.ws.server.RestResultBean)1 HealthData (password.pwm.ws.server.rest.bean.HealthData)1