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