forked from mattermost/mattermost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
diagnostic.go
175 lines (151 loc) · 6.66 KB
/
diagnostic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package utils
import "github.com/segmentio/analytics-go"
const (
DIAGNOSTIC_URL = "https://d7zmvsa9e04kk.cloudfront.net"
SEGMENT_KEY = "ua1qQtmgOZWIM23YjD842tQAsN7Ydi5X"
PROP_DIAGNOSTIC_ID = "id"
PROP_DIAGNOSTIC_CATEGORY = "c"
VAL_DIAGNOSTIC_CATEGORY_DEFAULT = "d"
PROP_DIAGNOSTIC_BUILD = "b"
PROP_DIAGNOSTIC_ENTERPRISE_READY = "be"
PROP_DIAGNOSTIC_DATABASE = "db"
PROP_DIAGNOSTIC_OS = "os"
PROP_DIAGNOSTIC_USER_COUNT = "uc"
PROP_DIAGNOSTIC_TEAM_COUNT = "tc"
PROP_DIAGNOSTIC_ACTIVE_USER_COUNT = "auc"
PROP_DIAGNOSTIC_UNIT_TESTS = "ut"
TRACK_CONFIG_SERVICE = "service"
TRACK_CONFIG_TEAM = "team"
TRACK_CONFIG_SQL = "sql"
TRACK_CONFIG_LOG = "log"
TRACK_CONFIG_FILE = "file"
TRACK_CONFIG_RATE = "rate"
TRACK_CONFIG_EMAIL = "email"
TRACK_CONFIG_PRIVACY = "privacy"
TRACK_CONFIG_OAUTH = "oauth"
TRACK_CONFIG_LDAP = "ldap"
TRACK_CONFIG_COMPLIANCE = "compliance"
TRACK_CONFIG_LOCALIZATION = "localization"
TRACK_CONFIG_SAML = "saml"
TRACK_LICENSE = "license"
TRACK_ACTIVITY = "activity"
TRACK_VERSION = "version"
)
var client *analytics.Client
func SendGeneralDiagnostics() {
if *Cfg.LogSettings.EnableDiagnostics {
initDiagnostics()
trackConfig()
trackLicense()
}
}
func initDiagnostics() {
if client == nil {
client = analytics.New(SEGMENT_KEY)
client.Identify(&analytics.Identify{
UserId: CfgDiagnosticId,
})
}
}
func SendDiagnostic(event string, properties map[string]interface{}) {
client.Track(&analytics.Track{
Event: event,
UserId: CfgDiagnosticId,
Properties: properties,
})
}
func trackConfig() {
SendDiagnostic(TRACK_CONFIG_SERVICE, map[string]interface{}{
"web_server_mode": *Cfg.ServiceSettings.WebserverMode,
"enable_security_fix_alert": *Cfg.ServiceSettings.EnableSecurityFixAlert,
"enable_insecure_outgoing_connections": *Cfg.ServiceSettings.EnableInsecureOutgoingConnections,
"enable_incoming_webhooks": Cfg.ServiceSettings.EnableIncomingWebhooks,
"enable_outgoing_webhooks": Cfg.ServiceSettings.EnableOutgoingWebhooks,
"enable_commands": *Cfg.ServiceSettings.EnableCommands,
"enable_only_admin_integrations": *Cfg.ServiceSettings.EnableOnlyAdminIntegrations,
"enable_post_username_override": Cfg.ServiceSettings.EnablePostUsernameOverride,
"enable_post_icon_override": Cfg.ServiceSettings.EnablePostIconOverride,
"enable_custom_emoji": *Cfg.ServiceSettings.EnableCustomEmoji,
"restrict_custom_emoji_creation": *Cfg.ServiceSettings.RestrictCustomEmojiCreation,
"enable_testing": Cfg.ServiceSettings.EnableTesting,
"enable_developer": *Cfg.ServiceSettings.EnableDeveloper,
})
SendDiagnostic(TRACK_CONFIG_TEAM, map[string]interface{}{
"enable_user_creation": Cfg.TeamSettings.EnableUserCreation,
"enable_team_creation": Cfg.TeamSettings.EnableTeamCreation,
"restrict_team_names": *Cfg.TeamSettings.RestrictTeamNames,
"restrict_team_invite": *Cfg.TeamSettings.RestrictTeamInvite,
"restrict_public_channel_management": *Cfg.TeamSettings.RestrictPublicChannelManagement,
"restrict_private_channel_management": *Cfg.TeamSettings.RestrictPrivateChannelManagement,
"enable_open_server": *Cfg.TeamSettings.EnableOpenServer,
"enable_custom_brand": *Cfg.TeamSettings.EnableCustomBrand,
})
SendDiagnostic(TRACK_CONFIG_SQL, map[string]interface{}{
"driver_name": Cfg.SqlSettings.DriverName,
})
SendDiagnostic(TRACK_CONFIG_LOG, map[string]interface{}{
"enable_console": Cfg.LogSettings.EnableConsole,
"console_level": Cfg.LogSettings.ConsoleLevel,
"enable_file": Cfg.LogSettings.EnableFile,
"file_level": Cfg.LogSettings.FileLevel,
"enable_webhook_debugging": Cfg.LogSettings.EnableWebhookDebugging,
})
SendDiagnostic(TRACK_CONFIG_FILE, map[string]interface{}{
"enable_public_links": Cfg.FileSettings.EnablePublicLink,
})
SendDiagnostic(TRACK_CONFIG_RATE, map[string]interface{}{
"enable_rate_limiter": Cfg.RateLimitSettings.EnableRateLimiter,
"vary_by_remote_address": Cfg.RateLimitSettings.VaryByRemoteAddr,
})
SendDiagnostic(TRACK_CONFIG_EMAIL, map[string]interface{}{
"enable_sign_up_with_email": Cfg.EmailSettings.EnableSignUpWithEmail,
"enable_sign_in_with_email": *Cfg.EmailSettings.EnableSignInWithEmail,
"enable_sign_in_with_username": *Cfg.EmailSettings.EnableSignInWithUsername,
"require_email_verification": Cfg.EmailSettings.RequireEmailVerification,
"send_email_notifications": Cfg.EmailSettings.SendEmailNotifications,
"connection_security": Cfg.EmailSettings.ConnectionSecurity,
"send_push_notifications": *Cfg.EmailSettings.SendPushNotifications,
"push_notification_contents": *Cfg.EmailSettings.PushNotificationContents,
})
SendDiagnostic(TRACK_CONFIG_PRIVACY, map[string]interface{}{
"show_email_address": Cfg.PrivacySettings.ShowEmailAddress,
"show_full_name": Cfg.PrivacySettings.ShowFullName,
})
SendDiagnostic(TRACK_CONFIG_OAUTH, map[string]interface{}{
"gitlab": Cfg.GitLabSettings.Enable,
"google": Cfg.GoogleSettings.Enable,
"office365": Cfg.Office365Settings.Enable,
})
SendDiagnostic(TRACK_CONFIG_LDAP, map[string]interface{}{
"enable": *Cfg.LdapSettings.Enable,
"connection_security": *Cfg.LdapSettings.ConnectionSecurity,
"skip_certificate_verification": *Cfg.LdapSettings.SkipCertificateVerification,
})
SendDiagnostic(TRACK_CONFIG_COMPLIANCE, map[string]interface{}{
"enable": *Cfg.ComplianceSettings.Enable,
"enable_daily": *Cfg.ComplianceSettings.EnableDaily,
})
SendDiagnostic(TRACK_CONFIG_LOCALIZATION, map[string]interface{}{
"default_server_locale": *Cfg.LocalizationSettings.DefaultServerLocale,
"default_client_locale": *Cfg.LocalizationSettings.DefaultClientLocale,
"available_locales": *Cfg.LocalizationSettings.AvailableLocales,
})
SendDiagnostic(TRACK_CONFIG_SAML, map[string]interface{}{
"enable": *Cfg.SamlSettings.Enable,
})
}
func trackLicense() {
if IsLicensed {
SendDiagnostic(TRACK_LICENSE, map[string]interface{}{
"name": License.Customer.Name,
"company": License.Customer.Company,
"issued": License.IssuedAt,
"start": License.StartsAt,
"expire": License.ExpiresAt,
"users": *License.Features.Users,
"features": License.Features.ToMap(),
})
}
}