Search in sources :

Example 6 with DisplayElement

use of password.pwm.http.bean.DisplayElement in project pwm by pwm-project.

the class AdminServlet method restreadPwNotifyStatus.

@ActionHandler(action = "readPwNotifyStatus")
public ProcessStatus restreadPwNotifyStatus(final PwmRequest pwmRequest) throws IOException, DatabaseException, PwmUnrecoverableException {
    int key = 0;
    if (!pwmRequest.getConfig().readSettingAsBoolean(PwmSetting.PW_EXPY_NOTIFY_ENABLE)) {
        final DisplayElement displayElement = new DisplayElement(String.valueOf(key++), DisplayElement.Type.string, "Status", "Password Notification Feature is not enabled.  See setting: " + PwmSetting.PW_EXPY_NOTIFY_ENABLE.toMenuLocationDebug(null, pwmRequest.getLocale()));
        pwmRequest.outputJsonResult(RestResultBean.withData(new PwNotifyStatusBean(Collections.singletonList(displayElement), false)));
        return ProcessStatus.Halt;
    }
    {
        ErrorInformation errorInformation = null;
        try {
            if (!pwmRequest.getPwmApplication().getDatabaseService().getAccessor().isConnected()) {
                errorInformation = new ErrorInformation(PwmError.ERROR_DB_UNAVAILABLE, "database is not connected");
            }
        } catch (PwmUnrecoverableException e) {
            errorInformation = e.getErrorInformation();
        }
        if (errorInformation != null) {
            final DisplayElement displayElement = new DisplayElement(String.valueOf(key++), DisplayElement.Type.string, "Status", "Database must be functioning to view Password Notify status.  Current database error: " + errorInformation.toDebugStr());
            pwmRequest.outputJsonResult(RestResultBean.withData(new PwNotifyStatusBean(Collections.singletonList(displayElement), false)));
            return ProcessStatus.Halt;
        }
    }
    final List<DisplayElement> statusData = new ArrayList<>();
    final Configuration config = pwmRequest.getConfig();
    final Locale locale = pwmRequest.getLocale();
    final PwNotifyService pwNotifyService = pwmRequest.getPwmApplication().getPwNotifyService();
    final StoredJobState storedJobState = pwNotifyService.getJobState();
    final boolean canRunOnthisServer = pwNotifyService.canRunOnThisServer();
    statusData.add(new DisplayElement(String.valueOf(key++), DisplayElement.Type.string, "Currently Processing (on this server)", LocaleHelper.booleanString(pwNotifyService.isRunning(), locale, config)));
    statusData.add(new DisplayElement(String.valueOf(key++), DisplayElement.Type.string, "This Server is the Job Processor", LocaleHelper.booleanString(canRunOnthisServer, locale, config)));
    if (canRunOnthisServer) {
        statusData.add(new DisplayElement(String.valueOf(key++), DisplayElement.Type.timestamp, "Next Job Scheduled Time", LocaleHelper.instantString(pwNotifyService.getNextExecutionTime(), locale, config)));
    }
    if (storedJobState != null) {
        statusData.add(new DisplayElement(String.valueOf(key++), DisplayElement.Type.timestamp, "Last Job Start Time", LocaleHelper.instantString(storedJobState.getLastStart(), locale, config)));
        statusData.add(new DisplayElement(String.valueOf(key++), DisplayElement.Type.timestamp, "Last Job Completion Time", LocaleHelper.instantString(storedJobState.getLastCompletion(), locale, config)));
        if (storedJobState.getLastStart() != null && storedJobState.getLastCompletion() != null) {
            statusData.add(new DisplayElement(String.valueOf(key++), DisplayElement.Type.timestamp, "Last Job Duration", TimeDuration.between(storedJobState.getLastStart(), storedJobState.getLastCompletion()).asLongString(locale)));
        }
        statusData.add(new DisplayElement(String.valueOf(key++), DisplayElement.Type.string, "Last Job Server Instance", storedJobState.getServerInstance()));
        if (storedJobState.getLastError() != null) {
            statusData.add(new DisplayElement(String.valueOf(key++), DisplayElement.Type.string, "Last Job Error", storedJobState.getLastError().toDebugStr()));
        }
    }
    final boolean startButtonEnabled = !pwNotifyService.isRunning() && canRunOnthisServer;
    final PwNotifyStatusBean pwNotifyStatusBean = new PwNotifyStatusBean(statusData, startButtonEnabled);
    pwmRequest.outputJsonResult(RestResultBean.withData(pwNotifyStatusBean));
    return ProcessStatus.Halt;
}
Also used : Locale(java.util.Locale) ErrorInformation(password.pwm.error.ErrorInformation) Configuration(password.pwm.config.Configuration) ArrayList(java.util.ArrayList) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) DisplayElement(password.pwm.http.bean.DisplayElement) PwNotifyService(password.pwm.svc.pwnotify.PwNotifyService) StoredJobState(password.pwm.svc.pwnotify.StoredJobState)

Example 7 with DisplayElement

use of password.pwm.http.bean.DisplayElement in project pwm by pwm-project.

the class AppDashboardData method makeLocalDbInfo.

private static List<DisplayElement> makeLocalDbInfo(final PwmApplication pwmApplication, final Locale locale) {
    final List<DisplayElement> localDbInfo = new ArrayList<>();
    final String notApplicable = Display.getLocalizedMessage(locale, Display.Value_NotApplicable, pwmApplication.getConfig());
    final PwmNumberFormat numberFormat = PwmNumberFormat.forLocale(locale);
    localDbInfo.add(new DisplayElement("worlistSize", DisplayElement.Type.number, "Word List Dictionary Size", numberFormat.format(pwmApplication.getWordlistManager().size())));
    localDbInfo.add(new DisplayElement("seedlistSize", DisplayElement.Type.number, "Seed List Dictionary Size", numberFormat.format(pwmApplication.getSeedlistManager().size())));
    localDbInfo.add(new DisplayElement("sharedHistorySize", DisplayElement.Type.number, "Shared Password History Size", numberFormat.format(pwmApplication.getSharedHistoryManager().size())));
    {
        final Instant oldestEntryAge = pwmApplication.getSharedHistoryManager().getOldestEntryTime();
        final String display = oldestEntryAge == null ? notApplicable : TimeDuration.fromCurrent(oldestEntryAge).asCompactString();
        localDbInfo.add(new DisplayElement("oldestSharedHistory", DisplayElement.Type.string, "OldestShared Password Entry", display));
    }
    localDbInfo.add(new DisplayElement("emailQueueSize", DisplayElement.Type.number, "Email Queue Size", numberFormat.format(pwmApplication.getEmailQueue().queueSize())));
    localDbInfo.add(new DisplayElement("smsQueueSize", DisplayElement.Type.number, "SMS Queue Size", numberFormat.format(pwmApplication.getSmsQueue().queueSize())));
    localDbInfo.add(new DisplayElement("sharedHistorySize", DisplayElement.Type.number, "Syslog Queue Size", String.valueOf(pwmApplication.getAuditManager().syslogQueueSize())));
    localDbInfo.add(new DisplayElement("localAuditRecords", DisplayElement.Type.number, "Audit Records", pwmApplication.getAuditManager().sizeToDebugString()));
    {
        final Instant eldestAuditRecord = pwmApplication.getAuditManager().eldestVaultRecord();
        final String display = eldestAuditRecord != null ? TimeDuration.fromCurrent(eldestAuditRecord).asLongString() : notApplicable;
        localDbInfo.add(new DisplayElement("oldestLocalAuditRecords", DisplayElement.Type.string, "Oldest Audit Record", display));
    }
    localDbInfo.add(new DisplayElement("logEvents", DisplayElement.Type.number, "Log Events", pwmApplication.getLocalDBLogger().sizeToDebugString()));
    {
        final String display = pwmApplication.getLocalDBLogger() != null && pwmApplication.getLocalDBLogger().getTailDate() != null ? TimeDuration.fromCurrent(pwmApplication.getLocalDBLogger().getTailDate()).asLongString() : notApplicable;
        localDbInfo.add(new DisplayElement("oldestLogEvents", DisplayElement.Type.string, "Oldest Log Event", display));
    }
    {
        final String display = pwmApplication.getLocalDB() == null ? notApplicable : pwmApplication.getLocalDB().getFileLocation() == null ? notApplicable : StringUtil.formatDiskSize(FileSystemUtility.getFileDirectorySize(pwmApplication.getLocalDB().getFileLocation()));
        localDbInfo.add(new DisplayElement("localDbSizeOnDisk", DisplayElement.Type.string, "LocalDB Size On Disk", display));
    }
    {
        final String display = pwmApplication.getLocalDB() == null ? notApplicable : pwmApplication.getLocalDB().getFileLocation() == null ? notApplicable : StringUtil.formatDiskSize(FileSystemUtility.diskSpaceRemaining(pwmApplication.getLocalDB().getFileLocation()));
        localDbInfo.add(new DisplayElement("localDbFreeSpace", DisplayElement.Type.string, "LocalDB Free Space", display));
    }
    return Collections.unmodifiableList(localDbInfo);
}
Also used : PwmNumberFormat(password.pwm.util.java.PwmNumberFormat) Instant(java.time.Instant) ArrayList(java.util.ArrayList) DisplayElement(password.pwm.http.bean.DisplayElement)

Aggregations

ArrayList (java.util.ArrayList)7 DisplayElement (password.pwm.http.bean.DisplayElement)7 List (java.util.List)4 Map (java.util.Map)3 PwmNumberFormat (password.pwm.util.java.PwmNumberFormat)3 Instant (java.time.Instant)2 LinkedHashMap (java.util.LinkedHashMap)2 Locale (java.util.Locale)2 FormConfiguration (password.pwm.config.value.data.FormConfiguration)2 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)2 ChaiUser (com.novell.ldapchai.ChaiUser)1 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 PwmAboutProperty (password.pwm.PwmAboutProperty)1 ResponseInfoBean (password.pwm.bean.ResponseInfoBean)1 Configuration (password.pwm.config.Configuration)1 ViewStatusFields (password.pwm.config.option.ViewStatusFields)1 ErrorInformation (password.pwm.error.ErrorInformation)1