github.com/coincircle/mattermost-server@v4.8.1-0.20180321182714-9d701c704416+incompatible/app/diagnostics.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package app 5 6 import ( 7 "encoding/json" 8 "log" 9 "os" 10 "runtime" 11 "sync/atomic" 12 13 "github.com/mattermost/mattermost-server/model" 14 "github.com/segmentio/analytics-go" 15 ) 16 17 const ( 18 SEGMENT_KEY = "fwb7VPbFeQ7SKp3wHm1RzFUuXZudqVok" 19 20 TRACK_CONFIG_SERVICE = "config_service" 21 TRACK_CONFIG_TEAM = "config_team" 22 TRACK_CONFIG_CLIENT_REQ = "config_client_requirements" 23 TRACK_CONFIG_SQL = "config_sql" 24 TRACK_CONFIG_LOG = "config_log" 25 TRACK_CONFIG_FILE = "config_file" 26 TRACK_CONFIG_RATE = "config_rate" 27 TRACK_CONFIG_EMAIL = "config_email" 28 TRACK_CONFIG_PRIVACY = "config_privacy" 29 TRACK_CONFIG_THEME = "config_theme" 30 TRACK_CONFIG_OAUTH = "config_oauth" 31 TRACK_CONFIG_LDAP = "config_ldap" 32 TRACK_CONFIG_COMPLIANCE = "config_compliance" 33 TRACK_CONFIG_LOCALIZATION = "config_localization" 34 TRACK_CONFIG_SAML = "config_saml" 35 TRACK_CONFIG_PASSWORD = "config_password" 36 TRACK_CONFIG_CLUSTER = "config_cluster" 37 TRACK_CONFIG_METRICS = "config_metrics" 38 TRACK_CONFIG_WEBRTC = "config_webrtc" 39 TRACK_CONFIG_SUPPORT = "config_support" 40 TRACK_CONFIG_NATIVEAPP = "config_nativeapp" 41 TRACK_CONFIG_ANALYTICS = "config_analytics" 42 TRACK_CONFIG_ANNOUNCEMENT = "config_announcement" 43 TRACK_CONFIG_ELASTICSEARCH = "config_elasticsearch" 44 TRACK_CONFIG_PLUGIN = "config_plugin" 45 TRACK_CONFIG_DATA_RETENTION = "config_data_retention" 46 TRACK_CONFIG_MESSAGE_EXPORT = "config_message_export" 47 48 TRACK_ACTIVITY = "activity" 49 TRACK_LICENSE = "license" 50 TRACK_SERVER = "server" 51 TRACK_PLUGINS = "plugins" 52 ) 53 54 var client *analytics.Client 55 56 func (a *App) SendDailyDiagnostics() { 57 if *a.Config().LogSettings.EnableDiagnostics && a.IsLeader() { 58 a.initDiagnostics("") 59 a.trackActivity() 60 a.trackConfig() 61 a.trackLicense() 62 a.trackPlugins() 63 a.trackServer() 64 } 65 } 66 67 func (a *App) initDiagnostics(endpoint string) { 68 if client == nil { 69 client = analytics.New(SEGMENT_KEY) 70 // For testing 71 if endpoint != "" { 72 client.Endpoint = endpoint 73 client.Verbose = true 74 client.Size = 1 75 client.Logger = log.New(os.Stdout, "segment ", log.LstdFlags) 76 } 77 client.Identify(&analytics.Identify{ 78 UserId: a.DiagnosticId(), 79 }) 80 } 81 } 82 83 func (a *App) SendDiagnostic(event string, properties map[string]interface{}) { 84 client.Track(&analytics.Track{ 85 Event: event, 86 UserId: a.DiagnosticId(), 87 Properties: properties, 88 }) 89 } 90 91 func isDefault(setting interface{}, defaultValue interface{}) bool { 92 return setting == defaultValue 93 } 94 95 func pluginSetting(pluginSettings *model.PluginSettings, plugin, key string, defaultValue interface{}) interface{} { 96 settings, ok := pluginSettings.Plugins[plugin] 97 if !ok { 98 return defaultValue 99 } 100 var m map[string]interface{} 101 if b, err := json.Marshal(settings); err != nil { 102 return defaultValue 103 } else { 104 json.Unmarshal(b, &m) 105 } 106 if value, ok := m[key]; ok { 107 return value 108 } 109 return defaultValue 110 } 111 112 func pluginActivated(pluginStates map[string]*model.PluginState, pluginId string) bool { 113 state, ok := pluginStates[pluginId] 114 if !ok { 115 return false 116 } 117 return state.Enable 118 } 119 120 func (a *App) trackActivity() { 121 var userCount int64 122 var activeUserCount int64 123 var inactiveUserCount int64 124 var teamCount int64 125 var publicChannelCount int64 126 var privateChannelCount int64 127 var directChannelCount int64 128 var deletedPublicChannelCount int64 129 var deletedPrivateChannelCount int64 130 var postsCount int64 131 132 if ucr := <-a.Srv.Store.User().GetTotalUsersCount(); ucr.Err == nil { 133 userCount = ucr.Data.(int64) 134 } 135 136 if ucr := <-a.Srv.Store.Status().GetTotalActiveUsersCount(); ucr.Err == nil { 137 activeUserCount = ucr.Data.(int64) 138 } 139 140 if iucr := <-a.Srv.Store.Status().GetTotalActiveUsersCount(); iucr.Err == nil { 141 inactiveUserCount = iucr.Data.(int64) 142 } 143 144 if tcr := <-a.Srv.Store.Team().AnalyticsTeamCount(); tcr.Err == nil { 145 teamCount = tcr.Data.(int64) 146 } 147 148 if ucc := <-a.Srv.Store.Channel().AnalyticsTypeCount("", "O"); ucc.Err == nil { 149 publicChannelCount = ucc.Data.(int64) 150 } 151 152 if pcc := <-a.Srv.Store.Channel().AnalyticsTypeCount("", "P"); pcc.Err == nil { 153 privateChannelCount = pcc.Data.(int64) 154 } 155 156 if dcc := <-a.Srv.Store.Channel().AnalyticsTypeCount("", "D"); dcc.Err == nil { 157 directChannelCount = dcc.Data.(int64) 158 } 159 160 if duccr := <-a.Srv.Store.Channel().AnalyticsDeletedTypeCount("", "O"); duccr.Err == nil { 161 deletedPublicChannelCount = duccr.Data.(int64) 162 } 163 164 if dpccr := <-a.Srv.Store.Channel().AnalyticsDeletedTypeCount("", "P"); dpccr.Err == nil { 165 deletedPrivateChannelCount = dpccr.Data.(int64) 166 } 167 168 if pcr := <-a.Srv.Store.Post().AnalyticsPostCount("", false, false); pcr.Err == nil { 169 postsCount = pcr.Data.(int64) 170 } 171 172 a.SendDiagnostic(TRACK_ACTIVITY, map[string]interface{}{ 173 "registered_users": userCount, 174 "active_users": activeUserCount, 175 "registered_inactive_users": inactiveUserCount, 176 "teams": teamCount, 177 "public_channels": publicChannelCount, 178 "private_channels": privateChannelCount, 179 "direct_message_channels": directChannelCount, 180 "public_channels_deleted": deletedPublicChannelCount, 181 "private_channels_deleted": deletedPrivateChannelCount, 182 "posts": postsCount, 183 "used_apiv3": atomic.LoadInt32(model.UsedApiV3) == 1, 184 }) 185 186 atomic.StoreInt32(model.UsedApiV3, 0) 187 } 188 189 func (a *App) trackConfig() { 190 cfg := a.Config() 191 a.SendDiagnostic(TRACK_CONFIG_SERVICE, map[string]interface{}{ 192 "web_server_mode": *cfg.ServiceSettings.WebserverMode, 193 "enable_security_fix_alert": *cfg.ServiceSettings.EnableSecurityFixAlert, 194 "enable_insecure_outgoing_connections": *cfg.ServiceSettings.EnableInsecureOutgoingConnections, 195 "enable_incoming_webhooks": cfg.ServiceSettings.EnableIncomingWebhooks, 196 "enable_outgoing_webhooks": cfg.ServiceSettings.EnableOutgoingWebhooks, 197 "enable_commands": *cfg.ServiceSettings.EnableCommands, 198 "enable_only_admin_integrations": *cfg.ServiceSettings.EnableOnlyAdminIntegrations, 199 "enable_post_username_override": cfg.ServiceSettings.EnablePostUsernameOverride, 200 "enable_post_icon_override": cfg.ServiceSettings.EnablePostIconOverride, 201 "enable_apiv3": *cfg.ServiceSettings.EnableAPIv3, 202 "enable_user_access_tokens": *cfg.ServiceSettings.EnableUserAccessTokens, 203 "enable_custom_emoji": *cfg.ServiceSettings.EnableCustomEmoji, 204 "enable_emoji_picker": *cfg.ServiceSettings.EnableEmojiPicker, 205 "experimental_enable_authentication_transfer": *cfg.ServiceSettings.ExperimentalEnableAuthenticationTransfer, 206 "restrict_custom_emoji_creation": *cfg.ServiceSettings.RestrictCustomEmojiCreation, 207 "enable_testing": cfg.ServiceSettings.EnableTesting, 208 "enable_developer": *cfg.ServiceSettings.EnableDeveloper, 209 "enable_multifactor_authentication": *cfg.ServiceSettings.EnableMultifactorAuthentication, 210 "enforce_multifactor_authentication": *cfg.ServiceSettings.EnforceMultifactorAuthentication, 211 "enable_oauth_service_provider": cfg.ServiceSettings.EnableOAuthServiceProvider, 212 "connection_security": *cfg.ServiceSettings.ConnectionSecurity, 213 "uses_letsencrypt": *cfg.ServiceSettings.UseLetsEncrypt, 214 "forward_80_to_443": *cfg.ServiceSettings.Forward80To443, 215 "maximum_login_attempts": *cfg.ServiceSettings.MaximumLoginAttempts, 216 "session_length_web_in_days": *cfg.ServiceSettings.SessionLengthWebInDays, 217 "session_length_mobile_in_days": *cfg.ServiceSettings.SessionLengthMobileInDays, 218 "session_length_sso_in_days": *cfg.ServiceSettings.SessionLengthSSOInDays, 219 "session_cache_in_minutes": *cfg.ServiceSettings.SessionCacheInMinutes, 220 "session_idle_timeout_in_minutes": *cfg.ServiceSettings.SessionIdleTimeoutInMinutes, 221 "isdefault_site_url": isDefault(*cfg.ServiceSettings.SiteURL, model.SERVICE_SETTINGS_DEFAULT_SITE_URL), 222 "isdefault_tls_cert_file": isDefault(*cfg.ServiceSettings.TLSCertFile, model.SERVICE_SETTINGS_DEFAULT_TLS_CERT_FILE), 223 "isdefault_tls_key_file": isDefault(*cfg.ServiceSettings.TLSKeyFile, model.SERVICE_SETTINGS_DEFAULT_TLS_KEY_FILE), 224 "isdefault_read_timeout": isDefault(*cfg.ServiceSettings.ReadTimeout, model.SERVICE_SETTINGS_DEFAULT_READ_TIMEOUT), 225 "isdefault_write_timeout": isDefault(*cfg.ServiceSettings.WriteTimeout, model.SERVICE_SETTINGS_DEFAULT_WRITE_TIMEOUT), 226 "isdefault_google_developer_key": isDefault(cfg.ServiceSettings.GoogleDeveloperKey, ""), 227 "isdefault_allow_cors_from": isDefault(*cfg.ServiceSettings.AllowCorsFrom, model.SERVICE_SETTINGS_DEFAULT_ALLOW_CORS_FROM), 228 "isdefault_allowed_untrusted_internal_connections": isDefault(*cfg.ServiceSettings.AllowedUntrustedInternalConnections, ""), 229 "restrict_post_delete": *cfg.ServiceSettings.RestrictPostDelete, 230 "allow_edit_post": *cfg.ServiceSettings.AllowEditPost, 231 "post_edit_time_limit": *cfg.ServiceSettings.PostEditTimeLimit, 232 "enable_user_typing_messages": *cfg.ServiceSettings.EnableUserTypingMessages, 233 "enable_channel_viewed_messages": *cfg.ServiceSettings.EnableChannelViewedMessages, 234 "time_between_user_typing_updates_milliseconds": *cfg.ServiceSettings.TimeBetweenUserTypingUpdatesMilliseconds, 235 "cluster_log_timeout_milliseconds": *cfg.ServiceSettings.ClusterLogTimeoutMilliseconds, 236 "enable_post_search": *cfg.ServiceSettings.EnablePostSearch, 237 "enable_user_statuses": *cfg.ServiceSettings.EnableUserStatuses, 238 "close_unused_direct_messages": *cfg.ServiceSettings.CloseUnusedDirectMessages, 239 "enable_preview_features": *cfg.ServiceSettings.EnablePreviewFeatures, 240 "enable_tutorial": *cfg.ServiceSettings.EnableTutorial, 241 "experimental_enable_default_channel_leave_join_messages": *cfg.ServiceSettings.ExperimentalEnableDefaultChannelLeaveJoinMessages, 242 "experimental_group_unread_channels": *cfg.ServiceSettings.ExperimentalGroupUnreadChannels, 243 "isdefault_image_proxy_type": isDefault(*cfg.ServiceSettings.ImageProxyType, ""), 244 "isdefault_image_proxy_url": isDefault(*cfg.ServiceSettings.ImageProxyURL, ""), 245 "isdefault_image_proxy_options": isDefault(*cfg.ServiceSettings.ImageProxyOptions, ""), 246 "websocket_url": isDefault(*cfg.ServiceSettings.WebsocketURL, ""), 247 "allow_cookies_for_subdomains": *cfg.ServiceSettings.AllowCookiesForSubdomains, 248 }) 249 250 a.SendDiagnostic(TRACK_CONFIG_TEAM, map[string]interface{}{ 251 "enable_user_creation": cfg.TeamSettings.EnableUserCreation, 252 "enable_team_creation": cfg.TeamSettings.EnableTeamCreation, 253 "restrict_team_invite": *cfg.TeamSettings.RestrictTeamInvite, 254 "restrict_public_channel_creation": *cfg.TeamSettings.RestrictPublicChannelCreation, 255 "restrict_private_channel_creation": *cfg.TeamSettings.RestrictPrivateChannelCreation, 256 "restrict_public_channel_management": *cfg.TeamSettings.RestrictPublicChannelManagement, 257 "restrict_private_channel_management": *cfg.TeamSettings.RestrictPrivateChannelManagement, 258 "restrict_public_channel_deletion": *cfg.TeamSettings.RestrictPublicChannelDeletion, 259 "restrict_private_channel_deletion": *cfg.TeamSettings.RestrictPrivateChannelDeletion, 260 "enable_open_server": *cfg.TeamSettings.EnableOpenServer, 261 "enable_custom_brand": *cfg.TeamSettings.EnableCustomBrand, 262 "restrict_direct_message": *cfg.TeamSettings.RestrictDirectMessage, 263 "max_notifications_per_channel": *cfg.TeamSettings.MaxNotificationsPerChannel, 264 "enable_confirm_notifications_to_channel": *cfg.TeamSettings.EnableConfirmNotificationsToChannel, 265 "max_users_per_team": *cfg.TeamSettings.MaxUsersPerTeam, 266 "max_channels_per_team": *cfg.TeamSettings.MaxChannelsPerTeam, 267 "teammate_name_display": *cfg.TeamSettings.TeammateNameDisplay, 268 "isdefault_site_name": isDefault(cfg.TeamSettings.SiteName, "Mattermost"), 269 "isdefault_custom_brand_text": isDefault(*cfg.TeamSettings.CustomBrandText, model.TEAM_SETTINGS_DEFAULT_CUSTOM_BRAND_TEXT), 270 "isdefault_custom_description_text": isDefault(*cfg.TeamSettings.CustomDescriptionText, model.TEAM_SETTINGS_DEFAULT_CUSTOM_DESCRIPTION_TEXT), 271 "isdefault_user_status_away_timeout": isDefault(*cfg.TeamSettings.UserStatusAwayTimeout, model.TEAM_SETTINGS_DEFAULT_USER_STATUS_AWAY_TIMEOUT), 272 "restrict_private_channel_manage_members": *cfg.TeamSettings.RestrictPrivateChannelManageMembers, 273 "enable_X_to_leave_channels_from_LHS": *cfg.TeamSettings.EnableXToLeaveChannelsFromLHS, 274 "experimental_town_square_is_read_only": *cfg.TeamSettings.ExperimentalTownSquareIsReadOnly, 275 "experimental_primary_team": isDefault(*cfg.TeamSettings.ExperimentalPrimaryTeam, ""), 276 }) 277 278 a.SendDiagnostic(TRACK_CONFIG_CLIENT_REQ, map[string]interface{}{ 279 "android_latest_version": cfg.ClientRequirements.AndroidLatestVersion, 280 "android_min_version": cfg.ClientRequirements.AndroidMinVersion, 281 "desktop_latest_version": cfg.ClientRequirements.DesktopLatestVersion, 282 "desktop_min_version": cfg.ClientRequirements.DesktopMinVersion, 283 "ios_latest_version": cfg.ClientRequirements.IosLatestVersion, 284 "ios_min_version": cfg.ClientRequirements.IosMinVersion, 285 }) 286 287 a.SendDiagnostic(TRACK_CONFIG_SQL, map[string]interface{}{ 288 "driver_name": *cfg.SqlSettings.DriverName, 289 "trace": cfg.SqlSettings.Trace, 290 "max_idle_conns": *cfg.SqlSettings.MaxIdleConns, 291 "max_open_conns": *cfg.SqlSettings.MaxOpenConns, 292 "data_source_replicas": len(cfg.SqlSettings.DataSourceReplicas), 293 "data_source_search_replicas": len(cfg.SqlSettings.DataSourceSearchReplicas), 294 "query_timeout": *cfg.SqlSettings.QueryTimeout, 295 }) 296 297 a.SendDiagnostic(TRACK_CONFIG_LOG, map[string]interface{}{ 298 "enable_console": cfg.LogSettings.EnableConsole, 299 "console_level": cfg.LogSettings.ConsoleLevel, 300 "enable_file": cfg.LogSettings.EnableFile, 301 "file_level": cfg.LogSettings.FileLevel, 302 "enable_webhook_debugging": cfg.LogSettings.EnableWebhookDebugging, 303 "isdefault_file_format": isDefault(cfg.LogSettings.FileFormat, ""), 304 "isdefault_file_location": isDefault(cfg.LogSettings.FileLocation, ""), 305 }) 306 307 a.SendDiagnostic(TRACK_CONFIG_PASSWORD, map[string]interface{}{ 308 "minimum_length": *cfg.PasswordSettings.MinimumLength, 309 "lowercase": *cfg.PasswordSettings.Lowercase, 310 "number": *cfg.PasswordSettings.Number, 311 "uppercase": *cfg.PasswordSettings.Uppercase, 312 "symbol": *cfg.PasswordSettings.Symbol, 313 }) 314 315 a.SendDiagnostic(TRACK_CONFIG_FILE, map[string]interface{}{ 316 "enable_public_links": cfg.FileSettings.EnablePublicLink, 317 "driver_name": *cfg.FileSettings.DriverName, 318 "amazon_s3_ssl": *cfg.FileSettings.AmazonS3SSL, 319 "amazon_s3_sse": *cfg.FileSettings.AmazonS3SSE, 320 "amazon_s3_signv2": *cfg.FileSettings.AmazonS3SignV2, 321 "amazon_s3_trace": *cfg.FileSettings.AmazonS3Trace, 322 "max_file_size": *cfg.FileSettings.MaxFileSize, 323 "enable_file_attachments": *cfg.FileSettings.EnableFileAttachments, 324 "enable_mobile_upload": *cfg.FileSettings.EnableMobileUpload, 325 "enable_mobile_download": *cfg.FileSettings.EnableMobileDownload, 326 }) 327 328 a.SendDiagnostic(TRACK_CONFIG_EMAIL, map[string]interface{}{ 329 "enable_sign_up_with_email": cfg.EmailSettings.EnableSignUpWithEmail, 330 "enable_sign_in_with_email": *cfg.EmailSettings.EnableSignInWithEmail, 331 "enable_sign_in_with_username": *cfg.EmailSettings.EnableSignInWithUsername, 332 "require_email_verification": cfg.EmailSettings.RequireEmailVerification, 333 "send_email_notifications": cfg.EmailSettings.SendEmailNotifications, 334 "use_channel_in_email_notifications": *cfg.EmailSettings.UseChannelInEmailNotifications, 335 "email_notification_contents_type": *cfg.EmailSettings.EmailNotificationContentsType, 336 "enable_smtp_auth": *cfg.EmailSettings.EnableSMTPAuth, 337 "connection_security": cfg.EmailSettings.ConnectionSecurity, 338 "send_push_notifications": *cfg.EmailSettings.SendPushNotifications, 339 "push_notification_contents": *cfg.EmailSettings.PushNotificationContents, 340 "enable_email_batching": *cfg.EmailSettings.EnableEmailBatching, 341 "email_batching_buffer_size": *cfg.EmailSettings.EmailBatchingBufferSize, 342 "email_batching_interval": *cfg.EmailSettings.EmailBatchingInterval, 343 "isdefault_feedback_name": isDefault(cfg.EmailSettings.FeedbackName, ""), 344 "isdefault_feedback_email": isDefault(cfg.EmailSettings.FeedbackEmail, ""), 345 "isdefault_feedback_organization": isDefault(*cfg.EmailSettings.FeedbackOrganization, model.EMAIL_SETTINGS_DEFAULT_FEEDBACK_ORGANIZATION), 346 "skip_server_certificate_verification": *cfg.EmailSettings.SkipServerCertificateVerification, 347 "isdefault_login_button_color": isDefault(*cfg.EmailSettings.LoginButtonColor, ""), 348 "isdefault_login_button_border_color": isDefault(*cfg.EmailSettings.LoginButtonBorderColor, ""), 349 "isdefault_login_button_text_color": isDefault(*cfg.EmailSettings.LoginButtonTextColor, ""), 350 }) 351 352 a.SendDiagnostic(TRACK_CONFIG_RATE, map[string]interface{}{ 353 "enable_rate_limiter": *cfg.RateLimitSettings.Enable, 354 "vary_by_remote_address": *cfg.RateLimitSettings.VaryByRemoteAddr, 355 "vary_by_user": *cfg.RateLimitSettings.VaryByUser, 356 "per_sec": *cfg.RateLimitSettings.PerSec, 357 "max_burst": *cfg.RateLimitSettings.MaxBurst, 358 "memory_store_size": *cfg.RateLimitSettings.MemoryStoreSize, 359 "isdefault_vary_by_header": isDefault(cfg.RateLimitSettings.VaryByHeader, ""), 360 }) 361 362 a.SendDiagnostic(TRACK_CONFIG_PRIVACY, map[string]interface{}{ 363 "show_email_address": cfg.PrivacySettings.ShowEmailAddress, 364 "show_full_name": cfg.PrivacySettings.ShowFullName, 365 }) 366 367 a.SendDiagnostic(TRACK_CONFIG_THEME, map[string]interface{}{ 368 "enable_theme_selection": *cfg.ThemeSettings.EnableThemeSelection, 369 "isdefault_default_theme": isDefault(*cfg.ThemeSettings.DefaultTheme, model.TEAM_SETTINGS_DEFAULT_TEAM_TEXT), 370 "allow_custom_themes": *cfg.ThemeSettings.AllowCustomThemes, 371 "allowed_themes": len(cfg.ThemeSettings.AllowedThemes), 372 }) 373 374 a.SendDiagnostic(TRACK_CONFIG_OAUTH, map[string]interface{}{ 375 "enable_gitlab": cfg.GitLabSettings.Enable, 376 "enable_google": cfg.GoogleSettings.Enable, 377 "enable_office365": cfg.Office365Settings.Enable, 378 }) 379 380 a.SendDiagnostic(TRACK_CONFIG_SUPPORT, map[string]interface{}{ 381 "isdefault_terms_of_service_link": isDefault(*cfg.SupportSettings.TermsOfServiceLink, model.SUPPORT_SETTINGS_DEFAULT_TERMS_OF_SERVICE_LINK), 382 "isdefault_privacy_policy_link": isDefault(*cfg.SupportSettings.PrivacyPolicyLink, model.SUPPORT_SETTINGS_DEFAULT_PRIVACY_POLICY_LINK), 383 "isdefault_about_link": isDefault(*cfg.SupportSettings.AboutLink, model.SUPPORT_SETTINGS_DEFAULT_ABOUT_LINK), 384 "isdefault_help_link": isDefault(*cfg.SupportSettings.HelpLink, model.SUPPORT_SETTINGS_DEFAULT_HELP_LINK), 385 "isdefault_report_a_problem_link": isDefault(*cfg.SupportSettings.ReportAProblemLink, model.SUPPORT_SETTINGS_DEFAULT_REPORT_A_PROBLEM_LINK), 386 "isdefault_support_email": isDefault(*cfg.SupportSettings.SupportEmail, model.SUPPORT_SETTINGS_DEFAULT_SUPPORT_EMAIL), 387 }) 388 389 a.SendDiagnostic(TRACK_CONFIG_LDAP, map[string]interface{}{ 390 "enable": *cfg.LdapSettings.Enable, 391 "enable_sync": *cfg.LdapSettings.EnableSync, 392 "connection_security": *cfg.LdapSettings.ConnectionSecurity, 393 "skip_certificate_verification": *cfg.LdapSettings.SkipCertificateVerification, 394 "sync_interval_minutes": *cfg.LdapSettings.SyncIntervalMinutes, 395 "query_timeout": *cfg.LdapSettings.QueryTimeout, 396 "max_page_size": *cfg.LdapSettings.MaxPageSize, 397 "isdefault_first_name_attribute": isDefault(*cfg.LdapSettings.FirstNameAttribute, model.LDAP_SETTINGS_DEFAULT_FIRST_NAME_ATTRIBUTE), 398 "isdefault_last_name_attribute": isDefault(*cfg.LdapSettings.LastNameAttribute, model.LDAP_SETTINGS_DEFAULT_LAST_NAME_ATTRIBUTE), 399 "isdefault_email_attribute": isDefault(*cfg.LdapSettings.EmailAttribute, model.LDAP_SETTINGS_DEFAULT_EMAIL_ATTRIBUTE), 400 "isdefault_username_attribute": isDefault(*cfg.LdapSettings.UsernameAttribute, model.LDAP_SETTINGS_DEFAULT_USERNAME_ATTRIBUTE), 401 "isdefault_nickname_attribute": isDefault(*cfg.LdapSettings.NicknameAttribute, model.LDAP_SETTINGS_DEFAULT_NICKNAME_ATTRIBUTE), 402 "isdefault_id_attribute": isDefault(*cfg.LdapSettings.IdAttribute, model.LDAP_SETTINGS_DEFAULT_ID_ATTRIBUTE), 403 "isdefault_position_attribute": isDefault(*cfg.LdapSettings.PositionAttribute, model.LDAP_SETTINGS_DEFAULT_POSITION_ATTRIBUTE), 404 "isdefault_login_field_name": isDefault(*cfg.LdapSettings.LoginFieldName, model.LDAP_SETTINGS_DEFAULT_LOGIN_FIELD_NAME), 405 "isdefault_login_button_color": isDefault(*cfg.LdapSettings.LoginButtonColor, ""), 406 "isdefault_login_button_border_color": isDefault(*cfg.LdapSettings.LoginButtonBorderColor, ""), 407 "isdefault_login_button_text_color": isDefault(*cfg.LdapSettings.LoginButtonTextColor, ""), 408 }) 409 410 a.SendDiagnostic(TRACK_CONFIG_COMPLIANCE, map[string]interface{}{ 411 "enable": *cfg.ComplianceSettings.Enable, 412 "enable_daily": *cfg.ComplianceSettings.EnableDaily, 413 }) 414 415 a.SendDiagnostic(TRACK_CONFIG_LOCALIZATION, map[string]interface{}{ 416 "default_server_locale": *cfg.LocalizationSettings.DefaultServerLocale, 417 "default_client_locale": *cfg.LocalizationSettings.DefaultClientLocale, 418 "available_locales": *cfg.LocalizationSettings.AvailableLocales, 419 }) 420 421 a.SendDiagnostic(TRACK_CONFIG_SAML, map[string]interface{}{ 422 "enable": *cfg.SamlSettings.Enable, 423 "enable_sync_with_ldap": *cfg.SamlSettings.EnableSyncWithLdap, 424 "verify": *cfg.SamlSettings.Verify, 425 "encrypt": *cfg.SamlSettings.Encrypt, 426 "isdefault_first_name_attribute": isDefault(*cfg.SamlSettings.FirstNameAttribute, model.SAML_SETTINGS_DEFAULT_FIRST_NAME_ATTRIBUTE), 427 "isdefault_last_name_attribute": isDefault(*cfg.SamlSettings.LastNameAttribute, model.SAML_SETTINGS_DEFAULT_LAST_NAME_ATTRIBUTE), 428 "isdefault_email_attribute": isDefault(*cfg.SamlSettings.EmailAttribute, model.SAML_SETTINGS_DEFAULT_EMAIL_ATTRIBUTE), 429 "isdefault_username_attribute": isDefault(*cfg.SamlSettings.UsernameAttribute, model.SAML_SETTINGS_DEFAULT_USERNAME_ATTRIBUTE), 430 "isdefault_nickname_attribute": isDefault(*cfg.SamlSettings.NicknameAttribute, model.SAML_SETTINGS_DEFAULT_NICKNAME_ATTRIBUTE), 431 "isdefault_locale_attribute": isDefault(*cfg.SamlSettings.LocaleAttribute, model.SAML_SETTINGS_DEFAULT_LOCALE_ATTRIBUTE), 432 "isdefault_position_attribute": isDefault(*cfg.SamlSettings.PositionAttribute, model.SAML_SETTINGS_DEFAULT_POSITION_ATTRIBUTE), 433 "isdefault_login_button_text": isDefault(*cfg.SamlSettings.LoginButtonText, model.USER_AUTH_SERVICE_SAML_TEXT), 434 "isdefault_login_button_color": isDefault(*cfg.SamlSettings.LoginButtonColor, ""), 435 "isdefault_login_button_border_color": isDefault(*cfg.SamlSettings.LoginButtonBorderColor, ""), 436 "isdefault_login_button_text_color": isDefault(*cfg.SamlSettings.LoginButtonTextColor, ""), 437 }) 438 439 a.SendDiagnostic(TRACK_CONFIG_CLUSTER, map[string]interface{}{ 440 "enable": *cfg.ClusterSettings.Enable, 441 "use_ip_address": *cfg.ClusterSettings.UseIpAddress, 442 "use_experimental_gossip": *cfg.ClusterSettings.UseExperimentalGossip, 443 "read_only_config": *cfg.ClusterSettings.ReadOnlyConfig, 444 }) 445 446 a.SendDiagnostic(TRACK_CONFIG_METRICS, map[string]interface{}{ 447 "enable": *cfg.MetricsSettings.Enable, 448 "block_profile_rate": *cfg.MetricsSettings.BlockProfileRate, 449 }) 450 451 a.SendDiagnostic(TRACK_CONFIG_NATIVEAPP, map[string]interface{}{ 452 "isdefault_app_download_link": isDefault(*cfg.NativeAppSettings.AppDownloadLink, model.NATIVEAPP_SETTINGS_DEFAULT_APP_DOWNLOAD_LINK), 453 "isdefault_android_app_download_link": isDefault(*cfg.NativeAppSettings.AndroidAppDownloadLink, model.NATIVEAPP_SETTINGS_DEFAULT_ANDROID_APP_DOWNLOAD_LINK), 454 "isdefault_iosapp_download_link": isDefault(*cfg.NativeAppSettings.IosAppDownloadLink, model.NATIVEAPP_SETTINGS_DEFAULT_IOS_APP_DOWNLOAD_LINK), 455 }) 456 457 a.SendDiagnostic(TRACK_CONFIG_WEBRTC, map[string]interface{}{ 458 "enable": *cfg.WebrtcSettings.Enable, 459 "isdefault_stun_uri": isDefault(*cfg.WebrtcSettings.StunURI, model.WEBRTC_SETTINGS_DEFAULT_STUN_URI), 460 "isdefault_turn_uri": isDefault(*cfg.WebrtcSettings.TurnURI, model.WEBRTC_SETTINGS_DEFAULT_TURN_URI), 461 }) 462 463 a.SendDiagnostic(TRACK_CONFIG_ANALYTICS, map[string]interface{}{ 464 "isdefault_max_users_for_statistics": isDefault(*cfg.AnalyticsSettings.MaxUsersForStatistics, model.ANALYTICS_SETTINGS_DEFAULT_MAX_USERS_FOR_STATISTICS), 465 }) 466 467 a.SendDiagnostic(TRACK_CONFIG_ANNOUNCEMENT, map[string]interface{}{ 468 "enable_banner": *cfg.AnnouncementSettings.EnableBanner, 469 "isdefault_banner_color": isDefault(*cfg.AnnouncementSettings.BannerColor, model.ANNOUNCEMENT_SETTINGS_DEFAULT_BANNER_COLOR), 470 "isdefault_banner_text_color": isDefault(*cfg.AnnouncementSettings.BannerTextColor, model.ANNOUNCEMENT_SETTINGS_DEFAULT_BANNER_TEXT_COLOR), 471 "allow_banner_dismissal": *cfg.AnnouncementSettings.AllowBannerDismissal, 472 }) 473 474 a.SendDiagnostic(TRACK_CONFIG_ELASTICSEARCH, map[string]interface{}{ 475 "isdefault_connection_url": isDefault(*cfg.ElasticsearchSettings.ConnectionUrl, model.ELASTICSEARCH_SETTINGS_DEFAULT_CONNECTION_URL), 476 "isdefault_username": isDefault(*cfg.ElasticsearchSettings.Username, model.ELASTICSEARCH_SETTINGS_DEFAULT_USERNAME), 477 "isdefault_password": isDefault(*cfg.ElasticsearchSettings.Password, model.ELASTICSEARCH_SETTINGS_DEFAULT_PASSWORD), 478 "enable_indexing": *cfg.ElasticsearchSettings.EnableIndexing, 479 "enable_searching": *cfg.ElasticsearchSettings.EnableSearching, 480 "sniff": *cfg.ElasticsearchSettings.Sniff, 481 "post_index_replicas": *cfg.ElasticsearchSettings.PostIndexReplicas, 482 "post_index_shards": *cfg.ElasticsearchSettings.PostIndexShards, 483 "isdefault_index_prefix": isDefault(*cfg.ElasticsearchSettings.IndexPrefix, model.ELASTICSEARCH_SETTINGS_DEFAULT_INDEX_PREFIX), 484 "live_indexing_batch_size": *cfg.ElasticsearchSettings.LiveIndexingBatchSize, 485 "bulk_indexing_time_window_seconds": *cfg.ElasticsearchSettings.BulkIndexingTimeWindowSeconds, 486 "request_timeout_seconds": *cfg.ElasticsearchSettings.RequestTimeoutSeconds, 487 }) 488 489 a.SendDiagnostic(TRACK_CONFIG_PLUGIN, map[string]interface{}{ 490 "enable_jira": pluginSetting(&cfg.PluginSettings, "jira", "enabled", false), 491 "enable_zoom": pluginActivated(cfg.PluginSettings.PluginStates, "zoom"), 492 "enable": *cfg.PluginSettings.Enable, 493 "enable_uploads": *cfg.PluginSettings.EnableUploads, 494 }) 495 496 a.SendDiagnostic(TRACK_CONFIG_DATA_RETENTION, map[string]interface{}{ 497 "enable_message_deletion": *cfg.DataRetentionSettings.EnableMessageDeletion, 498 "enable_file_deletion": *cfg.DataRetentionSettings.EnableFileDeletion, 499 "message_retention_days": *cfg.DataRetentionSettings.MessageRetentionDays, 500 "file_retention_days": *cfg.DataRetentionSettings.FileRetentionDays, 501 "deletion_job_start_time": *cfg.DataRetentionSettings.DeletionJobStartTime, 502 }) 503 504 a.SendDiagnostic(TRACK_CONFIG_MESSAGE_EXPORT, map[string]interface{}{ 505 "enable_message_export": *cfg.MessageExportSettings.EnableExport, 506 "export_format": *cfg.MessageExportSettings.ExportFormat, 507 "daily_run_time": *cfg.MessageExportSettings.DailyRunTime, 508 "default_export_from_timestamp": *cfg.MessageExportSettings.ExportFromTimestamp, 509 "batch_size": *cfg.MessageExportSettings.BatchSize, 510 "global_relay_customer_type": *cfg.MessageExportSettings.GlobalRelaySettings.CustomerType, 511 "is_default_global_relay_smtp_username": isDefault(*cfg.MessageExportSettings.GlobalRelaySettings.SmtpUsername, ""), 512 "is_default_global_relay_smtp_password": isDefault(*cfg.MessageExportSettings.GlobalRelaySettings.SmtpPassword, ""), 513 "is_default_global_relay_email_address": isDefault(*cfg.MessageExportSettings.GlobalRelaySettings.EmailAddress, ""), 514 }) 515 } 516 517 func (a *App) trackLicense() { 518 if license := a.License(); license != nil { 519 data := map[string]interface{}{ 520 "customer_id": license.Customer.Id, 521 "license_id": license.Id, 522 "issued": license.IssuedAt, 523 "start": license.StartsAt, 524 "expire": license.ExpiresAt, 525 "users": *license.Features.Users, 526 } 527 528 features := license.Features.ToMap() 529 for featureName, featureValue := range features { 530 data["feature_"+featureName] = featureValue 531 } 532 533 a.SendDiagnostic(TRACK_LICENSE, data) 534 } 535 } 536 537 func (a *App) trackPlugins() { 538 if *a.Config().PluginSettings.Enable { 539 totalActiveCount := -1 // -1 to indicate disabled or error 540 webappActiveCount := 0 541 backendActiveCount := 0 542 totalInactiveCount := -1 // -1 to indicate disabled or error 543 webappInactiveCount := 0 544 backendInactiveCount := 0 545 settingsCount := 0 546 547 plugins, _ := a.GetPlugins() 548 549 if plugins != nil { 550 totalActiveCount = len(plugins.Active) 551 552 for _, plugin := range plugins.Active { 553 if plugin.Webapp != nil { 554 webappActiveCount += 1 555 } 556 557 if plugin.Backend != nil { 558 backendActiveCount += 1 559 } 560 561 if plugin.SettingsSchema != nil { 562 settingsCount += 1 563 } 564 } 565 566 totalInactiveCount = len(plugins.Inactive) 567 568 for _, plugin := range plugins.Inactive { 569 if plugin.Webapp != nil { 570 webappInactiveCount += 1 571 } 572 573 if plugin.Backend != nil { 574 backendInactiveCount += 1 575 } 576 577 if plugin.SettingsSchema != nil { 578 settingsCount += 1 579 } 580 } 581 } 582 583 a.SendDiagnostic(TRACK_PLUGINS, map[string]interface{}{ 584 "active_plugins": totalActiveCount, 585 "active_webapp_plugins": webappActiveCount, 586 "active_backend_plugins": backendActiveCount, 587 "inactive_plugins": totalInactiveCount, 588 "inactive_webapp_plugins": webappInactiveCount, 589 "inactive_backend_plugins": backendInactiveCount, 590 "plugins_with_settings": settingsCount, 591 }) 592 } 593 } 594 595 func (a *App) trackServer() { 596 data := map[string]interface{}{ 597 "edition": model.BuildEnterpriseReady, 598 "version": model.CurrentVersion, 599 "database_type": *a.Config().SqlSettings.DriverName, 600 "operating_system": runtime.GOOS, 601 } 602 603 if scr := <-a.Srv.Store.User().AnalyticsGetSystemAdminCount(); scr.Err == nil { 604 data["system_admins"] = scr.Data.(int64) 605 } 606 607 a.SendDiagnostic(TRACK_SERVER, data) 608 }