Search in sources :

Example 1 with TelemetryPublishBean

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

the class TelemetryService method executePublishJob.

private void executePublishJob() throws PwmUnrecoverableException, IOException, URISyntaxException {
    final String authValue = pwmApplication.getStatisticsManager().getStatBundleForKey(StatisticsManager.KEY_CUMULATIVE).getStatistic(Statistic.AUTHENTICATIONS);
    if (StringUtil.isEmpty(authValue) || Integer.parseInt(authValue) < settings.getMinimumAuthentications()) {
        LOGGER.trace(SessionLabel.TELEMETRY_SESSION_LABEL, "skipping telemetry send, authentication count is too low");
    } else {
        try {
            final TelemetryPublishBean telemetryPublishBean = generatePublishableBean();
            sender.publish(telemetryPublishBean);
            LOGGER.trace(SessionLabel.TELEMETRY_SESSION_LABEL, "sent telemetry data: " + JsonUtil.serialize(telemetryPublishBean));
        } catch (PwmException e) {
            lastError = e.getErrorInformation();
            LOGGER.error(SessionLabel.TELEMETRY_SESSION_LABEL, "error sending telemetry data: " + e.getMessage());
        }
    }
    lastPublishTime = Instant.now();
    pwmApplication.writeAppAttribute(PwmApplication.AppAttribute.TELEMETRY_LAST_PUBLISH_TIMESTAMP, lastPublishTime);
    scheduleNextJob();
}
Also used : PwmException(password.pwm.error.PwmException) TelemetryPublishBean(password.pwm.bean.TelemetryPublishBean)

Example 2 with TelemetryPublishBean

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

the class TelemetryService method generatePublishableBean.

public TelemetryPublishBean generatePublishableBean() throws URISyntaxException, IOException, PwmUnrecoverableException {
    final StatisticsBundle bundle = pwmApplication.getStatisticsManager().getStatBundleForKey(StatisticsManager.KEY_CUMULATIVE);
    final Configuration config = pwmApplication.getConfig();
    final Map<PwmAboutProperty, String> aboutPropertyStringMap = PwmAboutProperty.makeInfoBean(pwmApplication);
    final Map<String, String> statData = new TreeMap<>();
    for (final Statistic loopStat : Statistic.values()) {
        statData.put(loopStat.getKey(), bundle.getStatistic(loopStat));
    }
    final List<String> configuredSettings = new ArrayList<>();
    for (final PwmSetting pwmSetting : config.nonDefaultSettings()) {
        if (!pwmSetting.getCategory().hasProfiles() && !config.isDefaultValue(pwmSetting)) {
            configuredSettings.add(pwmSetting.getKey());
        }
    }
    String ldapVendorName = null;
    for (final LdapProfile ldapProfile : config.getLdapProfiles().values()) {
        if (ldapVendorName == null) {
            try {
                final DirectoryVendor directoryVendor = ldapProfile.getProxyChaiProvider(pwmApplication).getDirectoryVendor();
                final PwmLdapVendor pwmLdapVendor = PwmLdapVendor.fromChaiVendor(directoryVendor);
                if (pwmLdapVendor != null) {
                    ldapVendorName = pwmLdapVendor.name();
                }
            } catch (Exception e) {
                LOGGER.trace(SessionLabel.TELEMETRY_SESSION_LABEL, "unable to read ldap vendor type for stats publication: " + e.getMessage());
            }
        }
    }
    final Map<String, String> aboutStrings = new TreeMap<>();
    {
        for (final Map.Entry<PwmAboutProperty, String> entry : aboutPropertyStringMap.entrySet()) {
            final PwmAboutProperty pwmAboutProperty = entry.getKey();
            aboutStrings.put(pwmAboutProperty.name(), entry.getValue());
        }
        aboutStrings.remove(PwmAboutProperty.app_instanceID.name());
        aboutStrings.remove(PwmAboutProperty.app_siteUrl.name());
    }
    final TelemetryPublishBean.TelemetryPublishBeanBuilder builder = TelemetryPublishBean.builder();
    builder.timestamp(Instant.now());
    builder.id(makeId(pwmApplication));
    builder.instanceHash(pwmApplication.getSecureService().hash(pwmApplication.getInstanceID()));
    builder.installTime(pwmApplication.getInstallTime());
    builder.siteDescription(config.readSettingAsString(PwmSetting.PUBLISH_STATS_SITE_DESCRIPTION));
    builder.versionBuild(PwmConstants.BUILD_NUMBER);
    builder.versionVersion(PwmConstants.BUILD_VERSION);
    builder.ldapVendorName(ldapVendorName);
    builder.statistics(Collections.unmodifiableMap(statData));
    builder.configuredSettings(Collections.unmodifiableList(configuredSettings));
    builder.about(aboutStrings);
    return builder.build();
}
Also used : Configuration(password.pwm.config.Configuration) ArrayList(java.util.ArrayList) PwmLdapVendor(password.pwm.ldap.PwmLdapVendor) TreeMap(java.util.TreeMap) LdapProfile(password.pwm.config.profile.LdapProfile) URISyntaxException(java.net.URISyntaxException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException) PwmSetting(password.pwm.config.PwmSetting) PwmAboutProperty(password.pwm.PwmAboutProperty) StatisticsBundle(password.pwm.svc.stats.StatisticsBundle) Statistic(password.pwm.svc.stats.Statistic) DirectoryVendor(com.novell.ldapchai.provider.DirectoryVendor) TelemetryPublishBean(password.pwm.bean.TelemetryPublishBean)

Aggregations

TelemetryPublishBean (password.pwm.bean.TelemetryPublishBean)2 PwmException (password.pwm.error.PwmException)2 DirectoryVendor (com.novell.ldapchai.provider.DirectoryVendor)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1 PwmAboutProperty (password.pwm.PwmAboutProperty)1 Configuration (password.pwm.config.Configuration)1 PwmSetting (password.pwm.config.PwmSetting)1 LdapProfile (password.pwm.config.profile.LdapProfile)1 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)1 PwmLdapVendor (password.pwm.ldap.PwmLdapVendor)1 Statistic (password.pwm.svc.stats.Statistic)1 StatisticsBundle (password.pwm.svc.stats.StatisticsBundle)1