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