use of org.codelibs.fess.helper.NotificationHelper in project fess by codelibs.
the class PingSearchEngineJob method execute.
public String execute() {
final SearchEngineClient searchEngineClient = ComponentUtil.getSearchEngineClient();
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final StringBuilder resultBuf = new StringBuilder();
final PingResponse ping = searchEngineClient.ping();
final int status = ping.getStatus();
if (systemHelper.isChangedClusterState(status)) {
if (fessConfig.hasNotification()) {
final String toStrs = fessConfig.getNotificationTo();
final String[] toAddresses;
if (StringUtil.isNotBlank(toStrs)) {
toAddresses = toStrs.split(",");
} else {
toAddresses = StringUtil.EMPTY_STRINGS;
}
final Postbox postbox = ComponentUtil.getComponent(Postbox.class);
try {
final NotificationHelper notificationHelper = ComponentUtil.getNotificationHelper();
SMailCallbackContext.setPreparedMessageHookOnThread(notificationHelper::send);
EsStatusPostcard.droppedInto(postbox, postcard -> {
postcard.setFrom(fessConfig.getMailFromAddress(), fessConfig.getMailFromName());
postcard.addReplyTo(fessConfig.getMailReturnPath());
if (toAddresses.length > 0) {
stream(toAddresses).of(stream -> stream.map(String::trim).forEach(address -> {
postcard.addTo(address);
}));
} else {
postcard.addTo(fessConfig.getMailFromAddress());
postcard.dryrun();
}
postcard.setHostname(systemHelper.getHostname());
postcard.setClustername(ping.getClusterName());
postcard.setClusterstatus(ping.getClusterStatus());
});
} catch (final Exception e) {
logger.warn("Failed to send a test mail.", e);
} finally {
SMailCallbackContext.clearPreparedMessageHookOnThread();
}
}
resultBuf.append("Status of ").append(ping.getClusterName()).append(" is changed to ").append(ping.getClusterStatus()).append('.');
} else if (status == 0) {
resultBuf.append(ping.getClusterName()).append(" is alive.");
} else {
resultBuf.append(ping.getClusterName()).append(" is not available.");
}
return resultBuf.toString();
}
use of org.codelibs.fess.helper.NotificationHelper in project fess by codelibs.
the class Crawler method sendMail.
protected void sendMail(final Map<String, String> infoMap) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
if (fessConfig.hasNotification()) {
final Map<String, String> dataMap = new HashMap<>();
for (final Map.Entry<String, String> entry : infoMap.entrySet()) {
dataMap.put(StringUtil.decapitalize(entry.getKey()), entry.getValue());
}
String hostname = fessConfig.getMailHostname();
if (StringUtil.isBlank(hostname)) {
hostname = ComponentUtil.getSystemHelper().getHostname();
}
dataMap.put("hostname", hostname);
logger.debug("\ninfoMap: {}\ndataMap: {}", infoMap, dataMap);
final DynamicProperties systemProperties = ComponentUtil.getSystemProperties();
final String toStrs = fessConfig.getNotificationTo();
final Postbox postbox = ComponentUtil.getComponent(Postbox.class);
try {
final String[] toAddresses;
if (StringUtil.isNotBlank(toStrs)) {
toAddresses = toStrs.split(",");
} else {
toAddresses = StringUtil.EMPTY_STRINGS;
}
final NotificationHelper notificationHelper = ComponentUtil.getNotificationHelper();
SMailCallbackContext.setPreparedMessageHookOnThread(notificationHelper::send);
CrawlerPostcard.droppedInto(postbox, postcard -> {
postcard.setFrom(fessConfig.getMailFromAddress(), fessConfig.getMailFromName());
postcard.addReplyTo(fessConfig.getMailReturnPath());
if (toAddresses.length > 0) {
stream(toAddresses).of(stream -> stream.map(String::trim).forEach(address -> {
postcard.addTo(address);
}));
} else {
postcard.addTo(fessConfig.getMailFromAddress());
postcard.dryrun();
}
postcard.setCrawlerEndTime(getValueFromMap(dataMap, "crawlerEndTime", StringUtil.EMPTY));
postcard.setCrawlerExecTime(getValueFromMap(dataMap, "crawlerExecTime", "0"));
postcard.setCrawlerStartTime(getValueFromMap(dataMap, "crawlerStartTime", StringUtil.EMPTY));
postcard.setDataCrawlEndTime(getValueFromMap(dataMap, "dataCrawlEndTime", StringUtil.EMPTY));
postcard.setDataCrawlExecTime(getValueFromMap(dataMap, "dataCrawlExecTime", "0"));
postcard.setDataCrawlStartTime(getValueFromMap(dataMap, "dataCrawlStartTime", StringUtil.EMPTY));
postcard.setDataIndexSize(getValueFromMap(dataMap, "dataIndexSize", "0"));
postcard.setDataIndexExecTime(getValueFromMap(dataMap, "dataIndexExecTime", "0"));
postcard.setHostname(getValueFromMap(dataMap, "hostname", StringUtil.EMPTY));
postcard.setWebFsCrawlEndTime(getValueFromMap(dataMap, "webFsCrawlEndTime", StringUtil.EMPTY));
postcard.setWebFsCrawlExecTime(getValueFromMap(dataMap, "webFsCrawlExecTime", "0"));
postcard.setWebFsCrawlStartTime(getValueFromMap(dataMap, "webFsCrawlStartTime", StringUtil.EMPTY));
postcard.setWebFsIndexExecTime(getValueFromMap(dataMap, "webFsIndexExecTime", "0"));
postcard.setWebFsIndexSize(getValueFromMap(dataMap, "webFsIndexSize", "0"));
if (Constants.TRUE.equalsIgnoreCase(infoMap.get(Constants.CRAWLER_STATUS))) {
postcard.setStatus(Constants.OK);
} else {
postcard.setStatus(Constants.FAIL);
}
postcard.setJobname(systemProperties.getProperty("job.runtime.name", StringUtil.EMPTY));
});
} finally {
SMailCallbackContext.clearPreparedMessageHookOnThread();
}
}
}
Aggregations