github.com/levb/mattermost-server@v5.3.1+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  	"path/filepath"
     8  	"runtime"
     9  	"strings"
    10  
    11  	"github.com/segmentio/analytics-go"
    12  
    13  	"github.com/mattermost/mattermost-server/mlog"
    14  	"github.com/mattermost/mattermost-server/model"
    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_EXTENSION          = "config_extension"
    28  	TRACK_CONFIG_EMAIL              = "config_email"
    29  	TRACK_CONFIG_PRIVACY            = "config_privacy"
    30  	TRACK_CONFIG_THEME              = "config_theme"
    31  	TRACK_CONFIG_OAUTH              = "config_oauth"
    32  	TRACK_CONFIG_LDAP               = "config_ldap"
    33  	TRACK_CONFIG_COMPLIANCE         = "config_compliance"
    34  	TRACK_CONFIG_LOCALIZATION       = "config_localization"
    35  	TRACK_CONFIG_SAML               = "config_saml"
    36  	TRACK_CONFIG_PASSWORD           = "config_password"
    37  	TRACK_CONFIG_CLUSTER            = "config_cluster"
    38  	TRACK_CONFIG_METRICS            = "config_metrics"
    39  	TRACK_CONFIG_WEBRTC             = "config_webrtc"
    40  	TRACK_CONFIG_SUPPORT            = "config_support"
    41  	TRACK_CONFIG_NATIVEAPP          = "config_nativeapp"
    42  	TRACK_CONFIG_EXPERIMENTAL       = "config_experimental"
    43  	TRACK_CONFIG_ANALYTICS          = "config_analytics"
    44  	TRACK_CONFIG_ANNOUNCEMENT       = "config_announcement"
    45  	TRACK_CONFIG_ELASTICSEARCH      = "config_elasticsearch"
    46  	TRACK_CONFIG_PLUGIN             = "config_plugin"
    47  	TRACK_CONFIG_DATA_RETENTION     = "config_data_retention"
    48  	TRACK_CONFIG_MESSAGE_EXPORT     = "config_message_export"
    49  	TRACK_CONFIG_DISPLAY            = "config_display"
    50  	TRACK_CONFIG_TIMEZONE           = "config_timezone"
    51  	TRACK_PERMISSIONS_GENERAL       = "permissions_general"
    52  	TRACK_PERMISSIONS_SYSTEM_SCHEME = "permissions_system_scheme"
    53  	TRACK_PERMISSIONS_TEAM_SCHEMES  = "permissions_team_schemes"
    54  
    55  	TRACK_ACTIVITY = "activity"
    56  	TRACK_LICENSE  = "license"
    57  	TRACK_SERVER   = "server"
    58  	TRACK_PLUGINS  = "plugins"
    59  )
    60  
    61  var client *analytics.Client
    62  
    63  func (a *App) SendDailyDiagnostics() {
    64  	if *a.Config().LogSettings.EnableDiagnostics && a.IsLeader() {
    65  		a.initDiagnostics("")
    66  		a.trackActivity()
    67  		a.trackConfig()
    68  		a.trackLicense()
    69  		a.trackPlugins()
    70  		a.trackServer()
    71  		a.trackPermissions()
    72  	}
    73  }
    74  
    75  func (a *App) initDiagnostics(endpoint string) {
    76  	if client == nil {
    77  		client = analytics.New(SEGMENT_KEY)
    78  		client.Logger = a.Log.StdLog(mlog.String("source", "segment"))
    79  		// For testing
    80  		if endpoint != "" {
    81  			client.Endpoint = endpoint
    82  			client.Verbose = true
    83  			client.Size = 1
    84  		}
    85  		client.Identify(&analytics.Identify{
    86  			UserId: a.DiagnosticId(),
    87  		})
    88  	}
    89  }
    90  
    91  func (a *App) SendDiagnostic(event string, properties map[string]interface{}) {
    92  	client.Track(&analytics.Track{
    93  		Event:      event,
    94  		UserId:     a.DiagnosticId(),
    95  		Properties: properties,
    96  	})
    97  }
    98  
    99  func isDefault(setting interface{}, defaultValue interface{}) bool {
   100  	return setting == defaultValue
   101  }
   102  
   103  func pluginSetting(pluginSettings *model.PluginSettings, plugin, key string, defaultValue interface{}) interface{} {
   104  	settings, ok := pluginSettings.Plugins[plugin]
   105  	if !ok {
   106  		return defaultValue
   107  	}
   108  	if value, ok := settings[key]; ok {
   109  		return value
   110  	}
   111  	return defaultValue
   112  }
   113  
   114  func pluginActivated(pluginStates map[string]*model.PluginState, pluginId string) bool {
   115  	state, ok := pluginStates[pluginId]
   116  	if !ok {
   117  		return false
   118  	}
   119  	return state.Enable
   120  }
   121  
   122  func (a *App) trackActivity() {
   123  	var userCount int64
   124  	var activeUsersDailyCount int64
   125  	var activeUsersMonthlyCount int64
   126  	var inactiveUserCount int64
   127  	var teamCount int64
   128  	var publicChannelCount int64
   129  	var privateChannelCount int64
   130  	var directChannelCount int64
   131  	var deletedPublicChannelCount int64
   132  	var deletedPrivateChannelCount int64
   133  	var postsCount int64
   134  
   135  	dailyActiveChan := a.Srv.Store.User().AnalyticsActiveCount(DAY_MILLISECONDS)
   136  	monthlyActiveChan := a.Srv.Store.User().AnalyticsActiveCount(MONTH_MILLISECONDS)
   137  
   138  	if r := <-dailyActiveChan; r.Err == nil {
   139  		activeUsersDailyCount = r.Data.(int64)
   140  	}
   141  
   142  	if r := <-monthlyActiveChan; r.Err == nil {
   143  		activeUsersMonthlyCount = r.Data.(int64)
   144  	}
   145  
   146  	if ucr := <-a.Srv.Store.User().GetTotalUsersCount(); ucr.Err == nil {
   147  		userCount = ucr.Data.(int64)
   148  	}
   149  
   150  	if iucr := <-a.Srv.Store.User().AnalyticsGetInactiveUsersCount(); iucr.Err == nil {
   151  		inactiveUserCount = iucr.Data.(int64)
   152  	}
   153  
   154  	if tcr := <-a.Srv.Store.Team().AnalyticsTeamCount(); tcr.Err == nil {
   155  		teamCount = tcr.Data.(int64)
   156  	}
   157  
   158  	if ucc := <-a.Srv.Store.Channel().AnalyticsTypeCount("", "O"); ucc.Err == nil {
   159  		publicChannelCount = ucc.Data.(int64)
   160  	}
   161  
   162  	if pcc := <-a.Srv.Store.Channel().AnalyticsTypeCount("", "P"); pcc.Err == nil {
   163  		privateChannelCount = pcc.Data.(int64)
   164  	}
   165  
   166  	if dcc := <-a.Srv.Store.Channel().AnalyticsTypeCount("", "D"); dcc.Err == nil {
   167  		directChannelCount = dcc.Data.(int64)
   168  	}
   169  
   170  	if duccr := <-a.Srv.Store.Channel().AnalyticsDeletedTypeCount("", "O"); duccr.Err == nil {
   171  		deletedPublicChannelCount = duccr.Data.(int64)
   172  	}
   173  
   174  	if dpccr := <-a.Srv.Store.Channel().AnalyticsDeletedTypeCount("", "P"); dpccr.Err == nil {
   175  		deletedPrivateChannelCount = dpccr.Data.(int64)
   176  	}
   177  
   178  	if pcr := <-a.Srv.Store.Post().AnalyticsPostCount("", false, false); pcr.Err == nil {
   179  		postsCount = pcr.Data.(int64)
   180  	}
   181  
   182  	a.SendDiagnostic(TRACK_ACTIVITY, map[string]interface{}{
   183  		"registered_users":             userCount,
   184  		"active_users_daily":           activeUsersDailyCount,
   185  		"active_users_monthly":         activeUsersMonthlyCount,
   186  		"registered_deactivated_users": inactiveUserCount,
   187  		"teams":                    teamCount,
   188  		"public_channels":          publicChannelCount,
   189  		"private_channels":         privateChannelCount,
   190  		"direct_message_channels":  directChannelCount,
   191  		"public_channels_deleted":  deletedPublicChannelCount,
   192  		"private_channels_deleted": deletedPrivateChannelCount,
   193  		"posts":                    postsCount,
   194  	})
   195  }
   196  
   197  func (a *App) trackConfig() {
   198  	cfg := a.Config()
   199  	a.SendDiagnostic(TRACK_CONFIG_SERVICE, map[string]interface{}{
   200  		"web_server_mode":                             *cfg.ServiceSettings.WebserverMode,
   201  		"enable_security_fix_alert":                   *cfg.ServiceSettings.EnableSecurityFixAlert,
   202  		"enable_insecure_outgoing_connections":        *cfg.ServiceSettings.EnableInsecureOutgoingConnections,
   203  		"enable_incoming_webhooks":                    cfg.ServiceSettings.EnableIncomingWebhooks,
   204  		"enable_outgoing_webhooks":                    cfg.ServiceSettings.EnableOutgoingWebhooks,
   205  		"enable_commands":                             *cfg.ServiceSettings.EnableCommands,
   206  		"enable_only_admin_integrations":              *cfg.ServiceSettings.EnableOnlyAdminIntegrations,
   207  		"enable_post_username_override":               cfg.ServiceSettings.EnablePostUsernameOverride,
   208  		"enable_post_icon_override":                   cfg.ServiceSettings.EnablePostIconOverride,
   209  		"enable_user_access_tokens":                   *cfg.ServiceSettings.EnableUserAccessTokens,
   210  		"enable_custom_emoji":                         *cfg.ServiceSettings.EnableCustomEmoji,
   211  		"enable_emoji_picker":                         *cfg.ServiceSettings.EnableEmojiPicker,
   212  		"enable_gif_picker":                           *cfg.ServiceSettings.EnableGifPicker,
   213  		"gfycat_api_key":                              isDefault(*cfg.ServiceSettings.GfycatApiKey, model.SERVICE_SETTINGS_DEFAULT_GFYCAT_API_KEY),
   214  		"gfycat_api_secret":                           isDefault(*cfg.ServiceSettings.GfycatApiSecret, model.SERVICE_SETTINGS_DEFAULT_GFYCAT_API_SECRET),
   215  		"experimental_enable_authentication_transfer": *cfg.ServiceSettings.ExperimentalEnableAuthenticationTransfer,
   216  		"restrict_custom_emoji_creation":              *cfg.ServiceSettings.RestrictCustomEmojiCreation,
   217  		"enable_testing":                              cfg.ServiceSettings.EnableTesting,
   218  		"enable_developer":                            *cfg.ServiceSettings.EnableDeveloper,
   219  		"enable_multifactor_authentication":           *cfg.ServiceSettings.EnableMultifactorAuthentication,
   220  		"enforce_multifactor_authentication":          *cfg.ServiceSettings.EnforceMultifactorAuthentication,
   221  		"enable_oauth_service_provider":               cfg.ServiceSettings.EnableOAuthServiceProvider,
   222  		"connection_security":                         *cfg.ServiceSettings.ConnectionSecurity,
   223  		"uses_letsencrypt":                            *cfg.ServiceSettings.UseLetsEncrypt,
   224  		"forward_80_to_443":                           *cfg.ServiceSettings.Forward80To443,
   225  		"maximum_login_attempts":                      *cfg.ServiceSettings.MaximumLoginAttempts,
   226  		"session_length_web_in_days":                  *cfg.ServiceSettings.SessionLengthWebInDays,
   227  		"session_length_mobile_in_days":               *cfg.ServiceSettings.SessionLengthMobileInDays,
   228  		"session_length_sso_in_days":                  *cfg.ServiceSettings.SessionLengthSSOInDays,
   229  		"session_cache_in_minutes":                    *cfg.ServiceSettings.SessionCacheInMinutes,
   230  		"session_idle_timeout_in_minutes":             *cfg.ServiceSettings.SessionIdleTimeoutInMinutes,
   231  		"isdefault_site_url":                          isDefault(*cfg.ServiceSettings.SiteURL, model.SERVICE_SETTINGS_DEFAULT_SITE_URL),
   232  		"isdefault_tls_cert_file":                     isDefault(*cfg.ServiceSettings.TLSCertFile, model.SERVICE_SETTINGS_DEFAULT_TLS_CERT_FILE),
   233  		"isdefault_tls_key_file":                      isDefault(*cfg.ServiceSettings.TLSKeyFile, model.SERVICE_SETTINGS_DEFAULT_TLS_KEY_FILE),
   234  		"isdefault_read_timeout":                      isDefault(*cfg.ServiceSettings.ReadTimeout, model.SERVICE_SETTINGS_DEFAULT_READ_TIMEOUT),
   235  		"isdefault_write_timeout":                     isDefault(*cfg.ServiceSettings.WriteTimeout, model.SERVICE_SETTINGS_DEFAULT_WRITE_TIMEOUT),
   236  		"isdefault_google_developer_key":              isDefault(cfg.ServiceSettings.GoogleDeveloperKey, ""),
   237  		"isdefault_allow_cors_from":                   isDefault(*cfg.ServiceSettings.AllowCorsFrom, model.SERVICE_SETTINGS_DEFAULT_ALLOW_CORS_FROM),
   238  		"isdefault_cors_exposed_headers":              isDefault(cfg.ServiceSettings.CorsExposedHeaders, ""),
   239  		"cors_allow_credentials":                      *cfg.ServiceSettings.CorsAllowCredentials,
   240  		"cors_debug":                                  *cfg.ServiceSettings.CorsDebug,
   241  		"isdefault_allowed_untrusted_internal_connections":        isDefault(*cfg.ServiceSettings.AllowedUntrustedInternalConnections, ""),
   242  		"restrict_post_delete":                                    *cfg.ServiceSettings.RestrictPostDelete,
   243  		"allow_edit_post":                                         *cfg.ServiceSettings.AllowEditPost,
   244  		"post_edit_time_limit":                                    *cfg.ServiceSettings.PostEditTimeLimit,
   245  		"enable_user_typing_messages":                             *cfg.ServiceSettings.EnableUserTypingMessages,
   246  		"enable_channel_viewed_messages":                          *cfg.ServiceSettings.EnableChannelViewedMessages,
   247  		"time_between_user_typing_updates_milliseconds":           *cfg.ServiceSettings.TimeBetweenUserTypingUpdatesMilliseconds,
   248  		"cluster_log_timeout_milliseconds":                        *cfg.ServiceSettings.ClusterLogTimeoutMilliseconds,
   249  		"enable_post_search":                                      *cfg.ServiceSettings.EnablePostSearch,
   250  		"enable_user_statuses":                                    *cfg.ServiceSettings.EnableUserStatuses,
   251  		"close_unused_direct_messages":                            *cfg.ServiceSettings.CloseUnusedDirectMessages,
   252  		"enable_preview_features":                                 *cfg.ServiceSettings.EnablePreviewFeatures,
   253  		"enable_tutorial":                                         *cfg.ServiceSettings.EnableTutorial,
   254  		"experimental_enable_default_channel_leave_join_messages": *cfg.ServiceSettings.ExperimentalEnableDefaultChannelLeaveJoinMessages,
   255  		"experimental_group_unread_channels":                      *cfg.ServiceSettings.ExperimentalGroupUnreadChannels,
   256  		"isdefault_image_proxy_type":                              isDefault(*cfg.ServiceSettings.ImageProxyType, ""),
   257  		"isdefault_image_proxy_url":                               isDefault(*cfg.ServiceSettings.ImageProxyURL, ""),
   258  		"isdefault_image_proxy_options":                           isDefault(*cfg.ServiceSettings.ImageProxyOptions, ""),
   259  		"websocket_url":                                           isDefault(*cfg.ServiceSettings.WebsocketURL, ""),
   260  		"allow_cookies_for_subdomains":                            *cfg.ServiceSettings.AllowCookiesForSubdomains,
   261  		"enable_api_team_deletion":                                *cfg.ServiceSettings.EnableAPITeamDeletion,
   262  		"experimental_enable_hardened_mode":                       *cfg.ServiceSettings.ExperimentalEnableHardenedMode,
   263  		"experimental_limit_client_config":                        *cfg.ServiceSettings.ExperimentalLimitClientConfig,
   264  		"enable_email_invitations":                                *cfg.ServiceSettings.EnableEmailInvitations,
   265  		"experimental_channel_organization":                       *cfg.ServiceSettings.ExperimentalChannelOrganization,
   266  	})
   267  
   268  	a.SendDiagnostic(TRACK_CONFIG_TEAM, map[string]interface{}{
   269  		"enable_user_creation":                      cfg.TeamSettings.EnableUserCreation,
   270  		"enable_team_creation":                      *cfg.TeamSettings.EnableTeamCreation,
   271  		"restrict_team_invite":                      *cfg.TeamSettings.RestrictTeamInvite,
   272  		"restrict_public_channel_creation":          *cfg.TeamSettings.RestrictPublicChannelCreation,
   273  		"restrict_private_channel_creation":         *cfg.TeamSettings.RestrictPrivateChannelCreation,
   274  		"restrict_public_channel_management":        *cfg.TeamSettings.RestrictPublicChannelManagement,
   275  		"restrict_private_channel_management":       *cfg.TeamSettings.RestrictPrivateChannelManagement,
   276  		"restrict_public_channel_deletion":          *cfg.TeamSettings.RestrictPublicChannelDeletion,
   277  		"restrict_private_channel_deletion":         *cfg.TeamSettings.RestrictPrivateChannelDeletion,
   278  		"enable_open_server":                        *cfg.TeamSettings.EnableOpenServer,
   279  		"enable_user_deactivation":                  *cfg.TeamSettings.EnableUserDeactivation,
   280  		"enable_custom_brand":                       *cfg.TeamSettings.EnableCustomBrand,
   281  		"restrict_direct_message":                   *cfg.TeamSettings.RestrictDirectMessage,
   282  		"max_notifications_per_channel":             *cfg.TeamSettings.MaxNotificationsPerChannel,
   283  		"enable_confirm_notifications_to_channel":   *cfg.TeamSettings.EnableConfirmNotificationsToChannel,
   284  		"max_users_per_team":                        *cfg.TeamSettings.MaxUsersPerTeam,
   285  		"max_channels_per_team":                     *cfg.TeamSettings.MaxChannelsPerTeam,
   286  		"teammate_name_display":                     *cfg.TeamSettings.TeammateNameDisplay,
   287  		"experimental_view_archived_channels":       *cfg.TeamSettings.ExperimentalViewArchivedChannels,
   288  		"isdefault_site_name":                       isDefault(cfg.TeamSettings.SiteName, "Mattermost"),
   289  		"isdefault_custom_brand_text":               isDefault(*cfg.TeamSettings.CustomBrandText, model.TEAM_SETTINGS_DEFAULT_CUSTOM_BRAND_TEXT),
   290  		"isdefault_custom_description_text":         isDefault(*cfg.TeamSettings.CustomDescriptionText, model.TEAM_SETTINGS_DEFAULT_CUSTOM_DESCRIPTION_TEXT),
   291  		"isdefault_user_status_away_timeout":        isDefault(*cfg.TeamSettings.UserStatusAwayTimeout, model.TEAM_SETTINGS_DEFAULT_USER_STATUS_AWAY_TIMEOUT),
   292  		"restrict_private_channel_manage_members":   *cfg.TeamSettings.RestrictPrivateChannelManageMembers,
   293  		"enable_X_to_leave_channels_from_LHS":       *cfg.TeamSettings.EnableXToLeaveChannelsFromLHS,
   294  		"experimental_enable_automatic_replies":     *cfg.TeamSettings.ExperimentalEnableAutomaticReplies,
   295  		"experimental_town_square_is_hidden_in_lhs": *cfg.TeamSettings.ExperimentalHideTownSquareinLHS,
   296  		"experimental_town_square_is_read_only":     *cfg.TeamSettings.ExperimentalTownSquareIsReadOnly,
   297  		"experimental_primary_team":                 isDefault(*cfg.TeamSettings.ExperimentalPrimaryTeam, ""),
   298  		"experimental_default_channels":             len(cfg.TeamSettings.ExperimentalDefaultChannels),
   299  	})
   300  
   301  	a.SendDiagnostic(TRACK_CONFIG_CLIENT_REQ, map[string]interface{}{
   302  		"android_latest_version": cfg.ClientRequirements.AndroidLatestVersion,
   303  		"android_min_version":    cfg.ClientRequirements.AndroidMinVersion,
   304  		"desktop_latest_version": cfg.ClientRequirements.DesktopLatestVersion,
   305  		"desktop_min_version":    cfg.ClientRequirements.DesktopMinVersion,
   306  		"ios_latest_version":     cfg.ClientRequirements.IosLatestVersion,
   307  		"ios_min_version":        cfg.ClientRequirements.IosMinVersion,
   308  	})
   309  
   310  	a.SendDiagnostic(TRACK_CONFIG_SQL, map[string]interface{}{
   311  		"driver_name":                    *cfg.SqlSettings.DriverName,
   312  		"trace":                          cfg.SqlSettings.Trace,
   313  		"max_idle_conns":                 *cfg.SqlSettings.MaxIdleConns,
   314  		"conn_max_lifetime_milliseconds": *cfg.SqlSettings.ConnMaxLifetimeMilliseconds,
   315  		"max_open_conns":                 *cfg.SqlSettings.MaxOpenConns,
   316  		"data_source_replicas":           len(cfg.SqlSettings.DataSourceReplicas),
   317  		"data_source_search_replicas":    len(cfg.SqlSettings.DataSourceSearchReplicas),
   318  		"query_timeout":                  *cfg.SqlSettings.QueryTimeout,
   319  	})
   320  
   321  	a.SendDiagnostic(TRACK_CONFIG_LOG, map[string]interface{}{
   322  		"enable_console":           cfg.LogSettings.EnableConsole,
   323  		"console_level":            cfg.LogSettings.ConsoleLevel,
   324  		"console_json":             *cfg.LogSettings.ConsoleJson,
   325  		"enable_file":              cfg.LogSettings.EnableFile,
   326  		"file_level":               cfg.LogSettings.FileLevel,
   327  		"file_json":                cfg.LogSettings.FileJson,
   328  		"enable_webhook_debugging": cfg.LogSettings.EnableWebhookDebugging,
   329  		"isdefault_file_location":  isDefault(cfg.LogSettings.FileLocation, ""),
   330  	})
   331  
   332  	a.SendDiagnostic(TRACK_CONFIG_PASSWORD, map[string]interface{}{
   333  		"minimum_length": *cfg.PasswordSettings.MinimumLength,
   334  		"lowercase":      *cfg.PasswordSettings.Lowercase,
   335  		"number":         *cfg.PasswordSettings.Number,
   336  		"uppercase":      *cfg.PasswordSettings.Uppercase,
   337  		"symbol":         *cfg.PasswordSettings.Symbol,
   338  	})
   339  
   340  	a.SendDiagnostic(TRACK_CONFIG_FILE, map[string]interface{}{
   341  		"enable_public_links":     cfg.FileSettings.EnablePublicLink,
   342  		"driver_name":             *cfg.FileSettings.DriverName,
   343  		"isdefault_directory":     isDefault(cfg.FileSettings.Directory, model.FILE_SETTINGS_DEFAULT_DIRECTORY),
   344  		"isabsolute_directory":    filepath.IsAbs(cfg.FileSettings.Directory),
   345  		"amazon_s3_ssl":           *cfg.FileSettings.AmazonS3SSL,
   346  		"amazon_s3_sse":           *cfg.FileSettings.AmazonS3SSE,
   347  		"amazon_s3_signv2":        *cfg.FileSettings.AmazonS3SignV2,
   348  		"amazon_s3_trace":         *cfg.FileSettings.AmazonS3Trace,
   349  		"max_file_size":           *cfg.FileSettings.MaxFileSize,
   350  		"enable_file_attachments": *cfg.FileSettings.EnableFileAttachments,
   351  		"enable_mobile_upload":    *cfg.FileSettings.EnableMobileUpload,
   352  		"enable_mobile_download":  *cfg.FileSettings.EnableMobileDownload,
   353  	})
   354  
   355  	a.SendDiagnostic(TRACK_CONFIG_EMAIL, map[string]interface{}{
   356  		"enable_sign_up_with_email":            cfg.EmailSettings.EnableSignUpWithEmail,
   357  		"enable_sign_in_with_email":            *cfg.EmailSettings.EnableSignInWithEmail,
   358  		"enable_sign_in_with_username":         *cfg.EmailSettings.EnableSignInWithUsername,
   359  		"require_email_verification":           cfg.EmailSettings.RequireEmailVerification,
   360  		"send_email_notifications":             cfg.EmailSettings.SendEmailNotifications,
   361  		"use_channel_in_email_notifications":   *cfg.EmailSettings.UseChannelInEmailNotifications,
   362  		"email_notification_contents_type":     *cfg.EmailSettings.EmailNotificationContentsType,
   363  		"enable_smtp_auth":                     *cfg.EmailSettings.EnableSMTPAuth,
   364  		"connection_security":                  cfg.EmailSettings.ConnectionSecurity,
   365  		"send_push_notifications":              *cfg.EmailSettings.SendPushNotifications,
   366  		"push_notification_contents":           *cfg.EmailSettings.PushNotificationContents,
   367  		"enable_email_batching":                *cfg.EmailSettings.EnableEmailBatching,
   368  		"email_batching_buffer_size":           *cfg.EmailSettings.EmailBatchingBufferSize,
   369  		"email_batching_interval":              *cfg.EmailSettings.EmailBatchingInterval,
   370  		"enable_preview_mode_banner":           *cfg.EmailSettings.EnablePreviewModeBanner,
   371  		"isdefault_feedback_name":              isDefault(cfg.EmailSettings.FeedbackName, ""),
   372  		"isdefault_feedback_email":             isDefault(cfg.EmailSettings.FeedbackEmail, ""),
   373  		"isdefault_feedback_organization":      isDefault(*cfg.EmailSettings.FeedbackOrganization, model.EMAIL_SETTINGS_DEFAULT_FEEDBACK_ORGANIZATION),
   374  		"skip_server_certificate_verification": *cfg.EmailSettings.SkipServerCertificateVerification,
   375  		"isdefault_login_button_color":         isDefault(*cfg.EmailSettings.LoginButtonColor, ""),
   376  		"isdefault_login_button_border_color":  isDefault(*cfg.EmailSettings.LoginButtonBorderColor, ""),
   377  		"isdefault_login_button_text_color":    isDefault(*cfg.EmailSettings.LoginButtonTextColor, ""),
   378  	})
   379  
   380  	a.SendDiagnostic(TRACK_CONFIG_EXTENSION, map[string]interface{}{
   381  		"enable_experimental_extensions": *cfg.ExtensionSettings.EnableExperimentalExtensions,
   382  	})
   383  
   384  	a.SendDiagnostic(TRACK_CONFIG_RATE, map[string]interface{}{
   385  		"enable_rate_limiter":      *cfg.RateLimitSettings.Enable,
   386  		"vary_by_remote_address":   *cfg.RateLimitSettings.VaryByRemoteAddr,
   387  		"vary_by_user":             *cfg.RateLimitSettings.VaryByUser,
   388  		"per_sec":                  *cfg.RateLimitSettings.PerSec,
   389  		"max_burst":                *cfg.RateLimitSettings.MaxBurst,
   390  		"memory_store_size":        *cfg.RateLimitSettings.MemoryStoreSize,
   391  		"isdefault_vary_by_header": isDefault(cfg.RateLimitSettings.VaryByHeader, ""),
   392  	})
   393  
   394  	a.SendDiagnostic(TRACK_CONFIG_PRIVACY, map[string]interface{}{
   395  		"show_email_address": cfg.PrivacySettings.ShowEmailAddress,
   396  		"show_full_name":     cfg.PrivacySettings.ShowFullName,
   397  	})
   398  
   399  	a.SendDiagnostic(TRACK_CONFIG_THEME, map[string]interface{}{
   400  		"enable_theme_selection":  *cfg.ThemeSettings.EnableThemeSelection,
   401  		"isdefault_default_theme": isDefault(*cfg.ThemeSettings.DefaultTheme, model.TEAM_SETTINGS_DEFAULT_TEAM_TEXT),
   402  		"allow_custom_themes":     *cfg.ThemeSettings.AllowCustomThemes,
   403  		"allowed_themes":          len(cfg.ThemeSettings.AllowedThemes),
   404  	})
   405  
   406  	a.SendDiagnostic(TRACK_CONFIG_OAUTH, map[string]interface{}{
   407  		"enable_gitlab":    cfg.GitLabSettings.Enable,
   408  		"enable_google":    cfg.GoogleSettings.Enable,
   409  		"enable_office365": cfg.Office365Settings.Enable,
   410  	})
   411  
   412  	a.SendDiagnostic(TRACK_CONFIG_SUPPORT, map[string]interface{}{
   413  		"isdefault_terms_of_service_link": isDefault(*cfg.SupportSettings.TermsOfServiceLink, model.SUPPORT_SETTINGS_DEFAULT_TERMS_OF_SERVICE_LINK),
   414  		"isdefault_privacy_policy_link":   isDefault(*cfg.SupportSettings.PrivacyPolicyLink, model.SUPPORT_SETTINGS_DEFAULT_PRIVACY_POLICY_LINK),
   415  		"isdefault_about_link":            isDefault(*cfg.SupportSettings.AboutLink, model.SUPPORT_SETTINGS_DEFAULT_ABOUT_LINK),
   416  		"isdefault_help_link":             isDefault(*cfg.SupportSettings.HelpLink, model.SUPPORT_SETTINGS_DEFAULT_HELP_LINK),
   417  		"isdefault_report_a_problem_link": isDefault(*cfg.SupportSettings.ReportAProblemLink, model.SUPPORT_SETTINGS_DEFAULT_REPORT_A_PROBLEM_LINK),
   418  		"isdefault_support_email":         isDefault(*cfg.SupportSettings.SupportEmail, model.SUPPORT_SETTINGS_DEFAULT_SUPPORT_EMAIL),
   419  	})
   420  
   421  	a.SendDiagnostic(TRACK_CONFIG_LDAP, map[string]interface{}{
   422  		"enable":                              *cfg.LdapSettings.Enable,
   423  		"enable_sync":                         *cfg.LdapSettings.EnableSync,
   424  		"connection_security":                 *cfg.LdapSettings.ConnectionSecurity,
   425  		"skip_certificate_verification":       *cfg.LdapSettings.SkipCertificateVerification,
   426  		"sync_interval_minutes":               *cfg.LdapSettings.SyncIntervalMinutes,
   427  		"query_timeout":                       *cfg.LdapSettings.QueryTimeout,
   428  		"max_page_size":                       *cfg.LdapSettings.MaxPageSize,
   429  		"isdefault_first_name_attribute":      isDefault(*cfg.LdapSettings.FirstNameAttribute, model.LDAP_SETTINGS_DEFAULT_FIRST_NAME_ATTRIBUTE),
   430  		"isdefault_last_name_attribute":       isDefault(*cfg.LdapSettings.LastNameAttribute, model.LDAP_SETTINGS_DEFAULT_LAST_NAME_ATTRIBUTE),
   431  		"isdefault_email_attribute":           isDefault(*cfg.LdapSettings.EmailAttribute, model.LDAP_SETTINGS_DEFAULT_EMAIL_ATTRIBUTE),
   432  		"isdefault_username_attribute":        isDefault(*cfg.LdapSettings.UsernameAttribute, model.LDAP_SETTINGS_DEFAULT_USERNAME_ATTRIBUTE),
   433  		"isdefault_nickname_attribute":        isDefault(*cfg.LdapSettings.NicknameAttribute, model.LDAP_SETTINGS_DEFAULT_NICKNAME_ATTRIBUTE),
   434  		"isdefault_id_attribute":              isDefault(*cfg.LdapSettings.IdAttribute, model.LDAP_SETTINGS_DEFAULT_ID_ATTRIBUTE),
   435  		"isdefault_position_attribute":        isDefault(*cfg.LdapSettings.PositionAttribute, model.LDAP_SETTINGS_DEFAULT_POSITION_ATTRIBUTE),
   436  		"isdefault_login_id_attribute":        isDefault(*cfg.LdapSettings.LoginIdAttribute, ""),
   437  		"isdefault_login_field_name":          isDefault(*cfg.LdapSettings.LoginFieldName, model.LDAP_SETTINGS_DEFAULT_LOGIN_FIELD_NAME),
   438  		"isdefault_login_button_color":        isDefault(*cfg.LdapSettings.LoginButtonColor, ""),
   439  		"isdefault_login_button_border_color": isDefault(*cfg.LdapSettings.LoginButtonBorderColor, ""),
   440  		"isdefault_login_button_text_color":   isDefault(*cfg.LdapSettings.LoginButtonTextColor, ""),
   441  	})
   442  
   443  	a.SendDiagnostic(TRACK_CONFIG_COMPLIANCE, map[string]interface{}{
   444  		"enable":       *cfg.ComplianceSettings.Enable,
   445  		"enable_daily": *cfg.ComplianceSettings.EnableDaily,
   446  	})
   447  
   448  	a.SendDiagnostic(TRACK_CONFIG_LOCALIZATION, map[string]interface{}{
   449  		"default_server_locale": *cfg.LocalizationSettings.DefaultServerLocale,
   450  		"default_client_locale": *cfg.LocalizationSettings.DefaultClientLocale,
   451  		"available_locales":     *cfg.LocalizationSettings.AvailableLocales,
   452  	})
   453  
   454  	a.SendDiagnostic(TRACK_CONFIG_SAML, map[string]interface{}{
   455  		"enable":                             *cfg.SamlSettings.Enable,
   456  		"enable_sync_with_ldap":              *cfg.SamlSettings.EnableSyncWithLdap,
   457  		"enable_sync_with_ldap_include_auth": *cfg.SamlSettings.EnableSyncWithLdapIncludeAuth,
   458  		"verify":                              *cfg.SamlSettings.Verify,
   459  		"encrypt":                             *cfg.SamlSettings.Encrypt,
   460  		"isdefault_scoping_idp_provider_id":   isDefault(*cfg.SamlSettings.ScopingIDPProviderId, ""),
   461  		"isdefault_scoping_idp_name":          isDefault(*cfg.SamlSettings.ScopingIDPName, ""),
   462  		"isdefault_id_attribute":              isDefault(*cfg.SamlSettings.IdAttribute, model.SAML_SETTINGS_DEFAULT_ID_ATTRIBUTE),
   463  		"isdefault_first_name_attribute":      isDefault(*cfg.SamlSettings.FirstNameAttribute, model.SAML_SETTINGS_DEFAULT_FIRST_NAME_ATTRIBUTE),
   464  		"isdefault_last_name_attribute":       isDefault(*cfg.SamlSettings.LastNameAttribute, model.SAML_SETTINGS_DEFAULT_LAST_NAME_ATTRIBUTE),
   465  		"isdefault_email_attribute":           isDefault(*cfg.SamlSettings.EmailAttribute, model.SAML_SETTINGS_DEFAULT_EMAIL_ATTRIBUTE),
   466  		"isdefault_username_attribute":        isDefault(*cfg.SamlSettings.UsernameAttribute, model.SAML_SETTINGS_DEFAULT_USERNAME_ATTRIBUTE),
   467  		"isdefault_nickname_attribute":        isDefault(*cfg.SamlSettings.NicknameAttribute, model.SAML_SETTINGS_DEFAULT_NICKNAME_ATTRIBUTE),
   468  		"isdefault_locale_attribute":          isDefault(*cfg.SamlSettings.LocaleAttribute, model.SAML_SETTINGS_DEFAULT_LOCALE_ATTRIBUTE),
   469  		"isdefault_position_attribute":        isDefault(*cfg.SamlSettings.PositionAttribute, model.SAML_SETTINGS_DEFAULT_POSITION_ATTRIBUTE),
   470  		"isdefault_login_button_text":         isDefault(*cfg.SamlSettings.LoginButtonText, model.USER_AUTH_SERVICE_SAML_TEXT),
   471  		"isdefault_login_button_color":        isDefault(*cfg.SamlSettings.LoginButtonColor, ""),
   472  		"isdefault_login_button_border_color": isDefault(*cfg.SamlSettings.LoginButtonBorderColor, ""),
   473  		"isdefault_login_button_text_color":   isDefault(*cfg.SamlSettings.LoginButtonTextColor, ""),
   474  	})
   475  
   476  	a.SendDiagnostic(TRACK_CONFIG_CLUSTER, map[string]interface{}{
   477  		"enable":                  *cfg.ClusterSettings.Enable,
   478  		"use_ip_address":          *cfg.ClusterSettings.UseIpAddress,
   479  		"use_experimental_gossip": *cfg.ClusterSettings.UseExperimentalGossip,
   480  		"read_only_config":        *cfg.ClusterSettings.ReadOnlyConfig,
   481  	})
   482  
   483  	a.SendDiagnostic(TRACK_CONFIG_METRICS, map[string]interface{}{
   484  		"enable":             *cfg.MetricsSettings.Enable,
   485  		"block_profile_rate": *cfg.MetricsSettings.BlockProfileRate,
   486  	})
   487  
   488  	a.SendDiagnostic(TRACK_CONFIG_NATIVEAPP, map[string]interface{}{
   489  		"isdefault_app_download_link":         isDefault(*cfg.NativeAppSettings.AppDownloadLink, model.NATIVEAPP_SETTINGS_DEFAULT_APP_DOWNLOAD_LINK),
   490  		"isdefault_android_app_download_link": isDefault(*cfg.NativeAppSettings.AndroidAppDownloadLink, model.NATIVEAPP_SETTINGS_DEFAULT_ANDROID_APP_DOWNLOAD_LINK),
   491  		"isdefault_iosapp_download_link":      isDefault(*cfg.NativeAppSettings.IosAppDownloadLink, model.NATIVEAPP_SETTINGS_DEFAULT_IOS_APP_DOWNLOAD_LINK),
   492  	})
   493  
   494  	a.SendDiagnostic(TRACK_CONFIG_WEBRTC, map[string]interface{}{
   495  		"enable":             *cfg.WebrtcSettings.Enable,
   496  		"isdefault_stun_uri": isDefault(*cfg.WebrtcSettings.StunURI, model.WEBRTC_SETTINGS_DEFAULT_STUN_URI),
   497  		"isdefault_turn_uri": isDefault(*cfg.WebrtcSettings.TurnURI, model.WEBRTC_SETTINGS_DEFAULT_TURN_URI),
   498  	})
   499  
   500  	a.SendDiagnostic(TRACK_CONFIG_EXPERIMENTAL, map[string]interface{}{
   501  		"client_side_cert_enable":          *cfg.ExperimentalSettings.ClientSideCertEnable,
   502  		"isdefault_client_side_cert_check": isDefault(*cfg.ExperimentalSettings.ClientSideCertCheck, model.CLIENT_SIDE_CERT_CHECK_PRIMARY_AUTH),
   503  	})
   504  
   505  	a.SendDiagnostic(TRACK_CONFIG_ANALYTICS, map[string]interface{}{
   506  		"isdefault_max_users_for_statistics": isDefault(*cfg.AnalyticsSettings.MaxUsersForStatistics, model.ANALYTICS_SETTINGS_DEFAULT_MAX_USERS_FOR_STATISTICS),
   507  	})
   508  
   509  	a.SendDiagnostic(TRACK_CONFIG_ANNOUNCEMENT, map[string]interface{}{
   510  		"enable_banner":               *cfg.AnnouncementSettings.EnableBanner,
   511  		"isdefault_banner_color":      isDefault(*cfg.AnnouncementSettings.BannerColor, model.ANNOUNCEMENT_SETTINGS_DEFAULT_BANNER_COLOR),
   512  		"isdefault_banner_text_color": isDefault(*cfg.AnnouncementSettings.BannerTextColor, model.ANNOUNCEMENT_SETTINGS_DEFAULT_BANNER_TEXT_COLOR),
   513  		"allow_banner_dismissal":      *cfg.AnnouncementSettings.AllowBannerDismissal,
   514  	})
   515  
   516  	a.SendDiagnostic(TRACK_CONFIG_ELASTICSEARCH, map[string]interface{}{
   517  		"isdefault_connection_url":          isDefault(*cfg.ElasticsearchSettings.ConnectionUrl, model.ELASTICSEARCH_SETTINGS_DEFAULT_CONNECTION_URL),
   518  		"isdefault_username":                isDefault(*cfg.ElasticsearchSettings.Username, model.ELASTICSEARCH_SETTINGS_DEFAULT_USERNAME),
   519  		"isdefault_password":                isDefault(*cfg.ElasticsearchSettings.Password, model.ELASTICSEARCH_SETTINGS_DEFAULT_PASSWORD),
   520  		"enable_indexing":                   *cfg.ElasticsearchSettings.EnableIndexing,
   521  		"enable_searching":                  *cfg.ElasticsearchSettings.EnableSearching,
   522  		"sniff":                             *cfg.ElasticsearchSettings.Sniff,
   523  		"post_index_replicas":               *cfg.ElasticsearchSettings.PostIndexReplicas,
   524  		"post_index_shards":                 *cfg.ElasticsearchSettings.PostIndexShards,
   525  		"isdefault_index_prefix":            isDefault(*cfg.ElasticsearchSettings.IndexPrefix, model.ELASTICSEARCH_SETTINGS_DEFAULT_INDEX_PREFIX),
   526  		"live_indexing_batch_size":          *cfg.ElasticsearchSettings.LiveIndexingBatchSize,
   527  		"bulk_indexing_time_window_seconds": *cfg.ElasticsearchSettings.BulkIndexingTimeWindowSeconds,
   528  		"request_timeout_seconds":           *cfg.ElasticsearchSettings.RequestTimeoutSeconds,
   529  	})
   530  
   531  	a.SendDiagnostic(TRACK_CONFIG_PLUGIN, map[string]interface{}{
   532  		"enable_jira":    pluginSetting(&cfg.PluginSettings, "jira", "enabled", false),
   533  		"enable_zoom":    pluginActivated(cfg.PluginSettings.PluginStates, "zoom"),
   534  		"enable":         *cfg.PluginSettings.Enable,
   535  		"enable_uploads": *cfg.PluginSettings.EnableUploads,
   536  	})
   537  
   538  	a.SendDiagnostic(TRACK_CONFIG_DATA_RETENTION, map[string]interface{}{
   539  		"enable_message_deletion": *cfg.DataRetentionSettings.EnableMessageDeletion,
   540  		"enable_file_deletion":    *cfg.DataRetentionSettings.EnableFileDeletion,
   541  		"message_retention_days":  *cfg.DataRetentionSettings.MessageRetentionDays,
   542  		"file_retention_days":     *cfg.DataRetentionSettings.FileRetentionDays,
   543  		"deletion_job_start_time": *cfg.DataRetentionSettings.DeletionJobStartTime,
   544  	})
   545  
   546  	a.SendDiagnostic(TRACK_CONFIG_MESSAGE_EXPORT, map[string]interface{}{
   547  		"enable_message_export":                 *cfg.MessageExportSettings.EnableExport,
   548  		"export_format":                         *cfg.MessageExportSettings.ExportFormat,
   549  		"daily_run_time":                        *cfg.MessageExportSettings.DailyRunTime,
   550  		"default_export_from_timestamp":         *cfg.MessageExportSettings.ExportFromTimestamp,
   551  		"batch_size":                            *cfg.MessageExportSettings.BatchSize,
   552  		"global_relay_customer_type":            *cfg.MessageExportSettings.GlobalRelaySettings.CustomerType,
   553  		"is_default_global_relay_smtp_username": isDefault(*cfg.MessageExportSettings.GlobalRelaySettings.SmtpUsername, ""),
   554  		"is_default_global_relay_smtp_password": isDefault(*cfg.MessageExportSettings.GlobalRelaySettings.SmtpPassword, ""),
   555  		"is_default_global_relay_email_address": isDefault(*cfg.MessageExportSettings.GlobalRelaySettings.EmailAddress, ""),
   556  	})
   557  
   558  	a.SendDiagnostic(TRACK_CONFIG_DISPLAY, map[string]interface{}{
   559  		"experimental_timezone":        *cfg.DisplaySettings.ExperimentalTimezone,
   560  		"isdefault_custom_url_schemes": len(*cfg.DisplaySettings.CustomUrlSchemes) != 0,
   561  	})
   562  
   563  	a.SendDiagnostic(TRACK_CONFIG_TIMEZONE, map[string]interface{}{
   564  		"isdefault_supported_timezones_path": isDefault(*cfg.TimezoneSettings.SupportedTimezonesPath, model.TIMEZONE_SETTINGS_DEFAULT_SUPPORTED_TIMEZONES_PATH),
   565  	})
   566  }
   567  
   568  func (a *App) trackLicense() {
   569  	if license := a.License(); license != nil {
   570  		data := map[string]interface{}{
   571  			"customer_id": license.Customer.Id,
   572  			"license_id":  license.Id,
   573  			"issued":      license.IssuedAt,
   574  			"start":       license.StartsAt,
   575  			"expire":      license.ExpiresAt,
   576  			"users":       *license.Features.Users,
   577  		}
   578  
   579  		features := license.Features.ToMap()
   580  		for featureName, featureValue := range features {
   581  			data["feature_"+featureName] = featureValue
   582  		}
   583  
   584  		a.SendDiagnostic(TRACK_LICENSE, data)
   585  	}
   586  }
   587  
   588  func (a *App) trackPlugins() {
   589  	if a.PluginsReady() {
   590  		totalEnabledCount := 0
   591  		webappEnabledCount := 0
   592  		backendEnabledCount := 0
   593  		totalDisabledCount := 0
   594  		webappDisabledCount := 0
   595  		backendDisabledCount := 0
   596  		brokenManifestCount := 0
   597  		settingsCount := 0
   598  
   599  		pluginStates := a.Config().PluginSettings.PluginStates
   600  		plugins, _ := a.Plugins.Available()
   601  
   602  		if pluginStates != nil && plugins != nil {
   603  			for _, plugin := range plugins {
   604  				if plugin.Manifest == nil {
   605  					brokenManifestCount += 1
   606  					continue
   607  				}
   608  				if state, ok := pluginStates[plugin.Manifest.Id]; ok && state.Enable {
   609  					totalEnabledCount += 1
   610  					if plugin.Manifest.HasServer() {
   611  						backendEnabledCount += 1
   612  					}
   613  					if plugin.Manifest.HasWebapp() {
   614  						webappEnabledCount += 1
   615  					}
   616  				} else {
   617  					totalDisabledCount += 1
   618  					if plugin.Manifest.HasServer() {
   619  						backendDisabledCount += 1
   620  					}
   621  					if plugin.Manifest.HasWebapp() {
   622  						webappDisabledCount += 1
   623  					}
   624  				}
   625  				if plugin.Manifest.SettingsSchema != nil {
   626  					settingsCount += 1
   627  				}
   628  			}
   629  		} else {
   630  			totalEnabledCount = -1  // -1 to indicate disabled or error
   631  			totalDisabledCount = -1 // -1 to indicate disabled or error
   632  		}
   633  
   634  		a.SendDiagnostic(TRACK_PLUGINS, map[string]interface{}{
   635  			"enabled_plugins":               totalEnabledCount,
   636  			"enabled_webapp_plugins":        webappEnabledCount,
   637  			"enabled_backend_plugins":       backendEnabledCount,
   638  			"disabled_plugins":              totalDisabledCount,
   639  			"disabled_webapp_plugins":       webappDisabledCount,
   640  			"disabled_backend_plugins":      backendDisabledCount,
   641  			"plugins_with_settings":         settingsCount,
   642  			"plugins_with_broken_manifests": brokenManifestCount,
   643  		})
   644  	}
   645  }
   646  
   647  func (a *App) trackServer() {
   648  	data := map[string]interface{}{
   649  		"edition":          model.BuildEnterpriseReady,
   650  		"version":          model.CurrentVersion,
   651  		"database_type":    *a.Config().SqlSettings.DriverName,
   652  		"operating_system": runtime.GOOS,
   653  	}
   654  
   655  	if scr := <-a.Srv.Store.User().AnalyticsGetSystemAdminCount(); scr.Err == nil {
   656  		data["system_admins"] = scr.Data.(int64)
   657  	}
   658  
   659  	a.SendDiagnostic(TRACK_SERVER, data)
   660  }
   661  
   662  func (a *App) trackPermissions() {
   663  	phase1Complete := false
   664  	if ph1res := <-a.Srv.Store.System().GetByName(ADVANCED_PERMISSIONS_MIGRATION_KEY); ph1res.Err == nil {
   665  		phase1Complete = true
   666  	}
   667  
   668  	phase2Complete := false
   669  	if ph2res := <-a.Srv.Store.System().GetByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2); ph2res.Err == nil {
   670  		phase2Complete = true
   671  	}
   672  
   673  	a.SendDiagnostic(TRACK_PERMISSIONS_GENERAL, map[string]interface{}{
   674  		"phase_1_migration_complete": phase1Complete,
   675  		"phase_2_migration_complete": phase2Complete,
   676  	})
   677  
   678  	systemAdminPermissions := ""
   679  	if role, err := a.GetRoleByName(model.SYSTEM_ADMIN_ROLE_ID); err == nil {
   680  		systemAdminPermissions = strings.Join(role.Permissions, " ")
   681  	}
   682  
   683  	systemUserPermissions := ""
   684  	if role, err := a.GetRoleByName(model.SYSTEM_USER_ROLE_ID); err == nil {
   685  		systemUserPermissions = strings.Join(role.Permissions, " ")
   686  	}
   687  
   688  	teamAdminPermissions := ""
   689  	if role, err := a.GetRoleByName(model.TEAM_ADMIN_ROLE_ID); err == nil {
   690  		teamAdminPermissions = strings.Join(role.Permissions, " ")
   691  	}
   692  
   693  	teamUserPermissions := ""
   694  	if role, err := a.GetRoleByName(model.TEAM_USER_ROLE_ID); err == nil {
   695  		teamUserPermissions = strings.Join(role.Permissions, " ")
   696  	}
   697  
   698  	channelAdminPermissions := ""
   699  	if role, err := a.GetRoleByName(model.CHANNEL_ADMIN_ROLE_ID); err == nil {
   700  		channelAdminPermissions = strings.Join(role.Permissions, " ")
   701  	}
   702  
   703  	channelUserPermissions := ""
   704  	if role, err := a.GetRoleByName(model.CHANNEL_USER_ROLE_ID); err == nil {
   705  		systemAdminPermissions = strings.Join(role.Permissions, " ")
   706  	}
   707  
   708  	a.SendDiagnostic(TRACK_PERMISSIONS_SYSTEM_SCHEME, map[string]interface{}{
   709  		"system_admin_permissions":  systemAdminPermissions,
   710  		"system_user_permissions":   systemUserPermissions,
   711  		"team_admin_permissions":    teamAdminPermissions,
   712  		"team_user_permissions":     teamUserPermissions,
   713  		"channel_admin_permissions": channelAdminPermissions,
   714  		"channel_user_permissions":  channelUserPermissions,
   715  	})
   716  
   717  	if schemes, err := a.GetSchemes(model.SCHEME_SCOPE_TEAM, 0, 100); err == nil {
   718  		for _, scheme := range schemes {
   719  			teamAdminPermissions := ""
   720  			if role, err := a.GetRoleByName(scheme.DefaultTeamAdminRole); err == nil {
   721  				teamAdminPermissions = strings.Join(role.Permissions, " ")
   722  			}
   723  
   724  			teamUserPermissions := ""
   725  			if role, err := a.GetRoleByName(scheme.DefaultTeamUserRole); err == nil {
   726  				teamUserPermissions = strings.Join(role.Permissions, " ")
   727  			}
   728  
   729  			channelAdminPermissions := ""
   730  			if role, err := a.GetRoleByName(scheme.DefaultChannelAdminRole); err == nil {
   731  				channelAdminPermissions = strings.Join(role.Permissions, " ")
   732  			}
   733  
   734  			channelUserPermissions := ""
   735  			if role, err := a.GetRoleByName(scheme.DefaultChannelUserRole); err == nil {
   736  				systemAdminPermissions = strings.Join(role.Permissions, " ")
   737  			}
   738  
   739  			var count int64 = 0
   740  			if res := <-a.Srv.Store.Team().AnalyticsGetTeamCountForScheme(scheme.Id); res.Err == nil {
   741  				count = res.Data.(int64)
   742  			}
   743  
   744  			a.SendDiagnostic(TRACK_PERMISSIONS_TEAM_SCHEMES, map[string]interface{}{
   745  				"scheme_id":                 scheme.Id,
   746  				"team_admin_permissions":    teamAdminPermissions,
   747  				"team_user_permissions":     teamUserPermissions,
   748  				"channel_admin_permissions": channelAdminPermissions,
   749  				"channel_user_permissions":  channelUserPermissions,
   750  				"team_count":                count,
   751  			})
   752  		}
   753  	}
   754  }