Search in sources :

Example 1 with Postbox

use of org.lastaflute.core.mail.Postbox in project fess by codelibs.

the class PingEsJob method execute.

public String execute() {
    final FessEsClient fessEsClient = ComponentUtil.getFessEsClient();
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
    final StringBuilder resultBuf = new StringBuilder();
    final String notificationTo = fessConfig.getNotificationTo();
    final PingResponse ping = fessEsClient.ping();
    final int status = ping.getStatus();
    if (systemHelper.isChangedClusterState(status)) {
        if (StringUtil.isNotBlank(notificationTo)) {
            final Postbox postbox = ComponentUtil.getComponent(Postbox.class);
            try {
                EsStatusPostcard.droppedInto(postbox, postcard -> {
                    postcard.setFrom(fessConfig.getMailFromAddress(), fessConfig.getMailFromName());
                    postcard.addReplyTo(fessConfig.getMailReturnPath());
                    postcard.addTo(notificationTo);
                    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);
            }
        }
        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();
}
Also used : SystemHelper(org.codelibs.fess.helper.SystemHelper) FessEsClient(org.codelibs.fess.es.client.FessEsClient) PingResponse(org.codelibs.fess.entity.PingResponse) Postbox(org.lastaflute.core.mail.Postbox) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 2 with Postbox

use of org.lastaflute.core.mail.Postbox in project fess by codelibs.

the class AdminGeneralAction method sendmail.

@Execute
@Secured({ ROLE })
public HtmlResponse sendmail(final MailForm form) {
    validate(form, messages -> {
    }, () -> asHtml(path_AdminGeneral_AdminGeneralJsp));
    final String[] toAddresses = form.notificationTo.split(",");
    final Map<String, Object> dataMap = new HashMap<>();
    dataMap.put("hostname", systemHelper.getHostname());
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final Postbox postbox = ComponentUtil.getComponent(Postbox.class);
    try {
        TestmailPostcard.droppedInto(postbox, postcard -> {
            postcard.setFrom(fessConfig.getMailFromAddress(), fessConfig.getMailFromName());
            postcard.addReplyTo(fessConfig.getMailReturnPath());
            stream(toAddresses).of(stream -> stream.forEach(address -> {
                postcard.addTo(address);
            }));
            BeanUtil.copyMapToBean(dataMap, postcard);
        });
        saveInfo(messages -> messages.addSuccessSendTestmail(GLOBAL));
        updateProperty(Constants.NOTIFICATION_TO_PROPERTY, form.notificationTo);
        systemProperties.store();
    } catch (final Exception e) {
        logger.warn("Failed to send a test mail.", e);
        saveError(messages -> messages.addErrorsFailedToSendTestmail(GLOBAL));
    }
    return redirectByParam(AdminGeneralAction.class, "notificationTo", form.notificationTo);
}
Also used : BeanUtil(org.codelibs.core.beans.util.BeanUtil) Constants(org.codelibs.fess.Constants) Secured(org.codelibs.fess.annotation.Secured) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) DynamicProperties(org.codelibs.core.misc.DynamicProperties) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) HashMap(java.util.HashMap) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) ArrayList(java.util.ArrayList) Postbox(org.lastaflute.core.mail.Postbox) List(java.util.List) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Logger(org.apache.logging.log4j.Logger) TestmailPostcard(org.codelibs.fess.mylasta.mail.TestmailPostcard) ComponentUtil(org.codelibs.fess.util.ComponentUtil) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) SystemHelper(org.codelibs.fess.helper.SystemHelper) Map(java.util.Map) Execute(org.lastaflute.web.Execute) HtmlResponse(org.lastaflute.web.response.HtmlResponse) LogManager(org.apache.logging.log4j.LogManager) HashMap(java.util.HashMap) Postbox(org.lastaflute.core.mail.Postbox) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Execute(org.lastaflute.web.Execute) Secured(org.codelibs.fess.annotation.Secured)

Example 3 with Postbox

use of org.lastaflute.core.mail.Postbox 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();
}
Also used : StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) SMailCallbackContext(org.dbflute.mail.send.hook.SMailCallbackContext) NotificationHelper(org.codelibs.fess.helper.NotificationHelper) StringUtil(org.codelibs.core.lang.StringUtil) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) EsStatusPostcard(org.codelibs.fess.mylasta.mail.EsStatusPostcard) Postbox(org.lastaflute.core.mail.Postbox) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Logger(org.apache.logging.log4j.Logger) PingResponse(org.codelibs.fess.entity.PingResponse) ComponentUtil(org.codelibs.fess.util.ComponentUtil) SystemHelper(org.codelibs.fess.helper.SystemHelper) LogManager(org.apache.logging.log4j.LogManager) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) PingResponse(org.codelibs.fess.entity.PingResponse) Postbox(org.lastaflute.core.mail.Postbox) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) SystemHelper(org.codelibs.fess.helper.SystemHelper) NotificationHelper(org.codelibs.fess.helper.NotificationHelper)

Example 4 with Postbox

use of org.lastaflute.core.mail.Postbox 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();
        }
    }
}
Also used : ThreadUtil(org.codelibs.core.lang.ThreadUtil) Constants(org.codelibs.fess.Constants) SMailCallbackContext(org.dbflute.mail.send.hook.SMailCallbackContext) Date(java.util.Date) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) SystemMonitorTarget(org.codelibs.fess.timer.SystemMonitorTarget) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) CrawlerPostcard(org.codelibs.fess.mylasta.mail.CrawlerPostcard) Map(java.util.Map) JvmInfo(org.opensearch.monitor.jvm.JvmInfo) CmdLineParser(org.kohsuke.args4j.CmdLineParser) GenericExternalContext(org.lastaflute.di.core.external.GenericExternalContext) Resource(javax.annotation.Resource) Option(org.kohsuke.args4j.Option) CoreLibConstants(org.codelibs.core.CoreLibConstants) Collectors(java.util.stream.Collectors) CrawlingInfoService(org.codelibs.fess.app.service.CrawlingInfoService) CmdLineException(org.kohsuke.args4j.CmdLineException) List(java.util.List) Logger(org.apache.logging.log4j.Logger) OsProbe(org.opensearch.monitor.os.OsProbe) ComponentUtil(org.codelibs.fess.util.ComponentUtil) CrawlingInfoHelper(org.codelibs.fess.helper.CrawlingInfoHelper) ThreadDumpUtil(org.codelibs.fess.util.ThreadDumpUtil) PathMappingService(org.codelibs.fess.app.service.PathMappingService) Queue(java.util.Queue) DataIndexHelper(org.codelibs.fess.helper.DataIndexHelper) TimeoutTask(org.codelibs.core.timer.TimeoutTask) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) WebFsIndexHelper(org.codelibs.fess.helper.WebFsIndexHelper) NotificationHelper(org.codelibs.fess.helper.NotificationHelper) SimpleDateFormat(java.text.SimpleDateFormat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) SingletonLaContainerFactory(org.lastaflute.di.core.factory.SingletonLaContainerFactory) ArrayList(java.util.ArrayList) Postbox(org.lastaflute.core.mail.Postbox) InterruptedRuntimeException(org.codelibs.core.exception.InterruptedRuntimeException) FesenClient(org.codelibs.fess.crawler.client.FesenClient) ManagementFactory(java.lang.management.ManagementFactory) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) DynamicProperties(org.codelibs.core.misc.DynamicProperties) ProcessProbe(org.opensearch.monitor.process.ProcessProbe) ContainerNotAvailableException(org.codelibs.fess.exception.ContainerNotAvailableException) StringUtil(org.codelibs.core.lang.StringUtil) IOException(java.io.IOException) DuplicateHostHelper(org.codelibs.fess.helper.DuplicateHostHelper) InputStreamReader(java.io.InputStreamReader) File(java.io.File) PathMappingHelper(org.codelibs.fess.helper.PathMappingHelper) GenericExternalContextComponentDefRegister(org.lastaflute.di.core.external.GenericExternalContextComponentDefRegister) TimeoutManager(org.codelibs.core.timer.TimeoutManager) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) HashMap(java.util.HashMap) NotificationHelper(org.codelibs.fess.helper.NotificationHelper) DynamicProperties(org.codelibs.core.misc.DynamicProperties) Postbox(org.lastaflute.core.mail.Postbox) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)4 Postbox (org.lastaflute.core.mail.Postbox)4 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 StringUtil (org.codelibs.core.lang.StringUtil)3 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)3 ComponentUtil (org.codelibs.fess.util.ComponentUtil)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Resource (javax.annotation.Resource)2 DynamicProperties (org.codelibs.core.misc.DynamicProperties)2 Constants (org.codelibs.fess.Constants)2 PingResponse (org.codelibs.fess.entity.PingResponse)2 SearchEngineClient (org.codelibs.fess.es.client.SearchEngineClient)2 NotificationHelper (org.codelibs.fess.helper.NotificationHelper)2 SystemHelper (org.codelibs.fess.helper.SystemHelper)2 SMailCallbackContext (org.dbflute.mail.send.hook.SMailCallbackContext)2 BufferedReader (java.io.BufferedReader)1