summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config/config.json3
-rw-r--r--docker/dev/config_docker.json3
-rw-r--r--docker/local/config_docker.json3
-rw-r--r--mattermost.go51
-rw-r--r--model/config.go1
-rw-r--r--model/version.go4
-rw-r--r--utils/diagnostic.go45
-rw-r--r--web/react/components/admin_console/privacy_settings.jsx34
8 files changed, 141 insertions, 3 deletions
diff --git a/config/config.json b/config/config.json
index 38acee85a..48514e1a4 100644
--- a/config/config.json
+++ b/config/config.json
@@ -75,7 +75,8 @@
},
"PrivacySettings": {
"ShowEmailAddress": true,
- "ShowFullName": true
+ "ShowFullName": true,
+ "EnableDiagnostic": false
},
"GitLabSettings": {
"Enable": false,
diff --git a/docker/dev/config_docker.json b/docker/dev/config_docker.json
index 733267f74..2611a63ce 100644
--- a/docker/dev/config_docker.json
+++ b/docker/dev/config_docker.json
@@ -75,7 +75,8 @@
},
"PrivacySettings": {
"ShowEmailAddress": true,
- "ShowFullName": true
+ "ShowFullName": true,
+ "EnableDiagnostic": false
},
"GitLabSettings": {
"Enable": false,
diff --git a/docker/local/config_docker.json b/docker/local/config_docker.json
index 733267f74..2611a63ce 100644
--- a/docker/local/config_docker.json
+++ b/docker/local/config_docker.json
@@ -75,7 +75,8 @@
},
"PrivacySettings": {
"ShowEmailAddress": true,
- "ShowFullName": true
+ "ShowFullName": true,
+ "EnableDiagnostic": false
},
"GitLabSettings": {
"Enable": false,
diff --git a/mattermost.go b/mattermost.go
index 94bbe344d..e78e8d04a 100644
--- a/mattermost.go
+++ b/mattermost.go
@@ -8,6 +8,8 @@ import (
"fmt"
"os"
"os/signal"
+ "runtime"
+ "strconv"
"strings"
"syscall"
"time"
@@ -61,6 +63,8 @@ func main() {
manualtesting.InitManualTesting()
}
+ diagnosticsJob()
+
// wait for kill signal before attempting to gracefully shutdown
// the running service
c := make(chan os.Signal)
@@ -71,6 +75,53 @@ func main() {
}
}
+func diagnosticsJob() {
+ go func() {
+ for {
+ if utils.Cfg.PrivacySettings.EnableDiagnostic && !model.IsOfficalBuild() {
+ if result := <-api.Srv.Store.System().Get(); result.Err == nil {
+ props := result.Data.(model.StringMap)
+ lastTime, _ := strconv.ParseInt(props["LastDiagnosticTime"], 10, 0)
+ currentTime := model.GetMillis()
+
+ if (currentTime - lastTime) > 1000*60*60*24*7 {
+ l4g.Info("Sending error and diagnostic information to mattermost")
+
+ id := props["DiagnosticId"]
+ if len(id) == 0 {
+ id = model.NewId()
+ systemId := &model.System{Name: "DiagnosticId", Value: id}
+ <-api.Srv.Store.System().Save(systemId)
+ }
+
+ systemLastTime := &model.System{Name: "LastDiagnosticTime", Value: strconv.FormatInt(currentTime, 10)}
+ if lastTime == 0 {
+ <-api.Srv.Store.System().Save(systemLastTime)
+ } else {
+ <-api.Srv.Store.System().Update(systemLastTime)
+ }
+
+ m := make(map[string]string)
+ m[utils.PROP_DIAGNOSTIC_ID] = id
+ m[utils.PROP_DIAGNOSTIC_BUILD] = model.CurrentVersion + "." + model.BuildNumber
+ m[utils.PROP_DIAGNOSTIC_DATABASE] = utils.Cfg.SqlSettings.DriverName
+ m[utils.PROP_DIAGNOSTIC_OS] = runtime.GOOS
+ m[utils.PROP_DIAGNOSTIC_CATEGORY] = utils.VAL_DIAGNOSTIC_CATEGORY_DEFALUT
+
+ if ucr := <-api.Srv.Store.User().GetTotalUsersCount(); ucr.Err == nil {
+ m[utils.PROP_DIAGNOSTIC_USER_COUNT] = strconv.FormatInt(ucr.Data.(int64), 10)
+ }
+
+ utils.SendDiagnostic(m)
+ }
+ }
+ }
+
+ time.Sleep(time.Hour * 24)
+ }
+ }()
+}
+
func parseCmds() {
flag.Usage = func() {
fmt.Fprintln(os.Stderr, usage)
diff --git a/model/config.go b/model/config.go
index 5d822e263..35ceb7f4a 100644
--- a/model/config.go
+++ b/model/config.go
@@ -110,6 +110,7 @@ type RateLimitSettings struct {
type PrivacySettings struct {
ShowEmailAddress bool
ShowFullName bool
+ EnableDiagnostic bool
}
type TeamSettings struct {
diff --git a/model/version.go b/model/version.go
index 233fc3747..efa1697db 100644
--- a/model/version.go
+++ b/model/version.go
@@ -67,6 +67,10 @@ func GetPreviousVersion(currentVersion string) (int64, int64) {
return 0, 0
}
+func IsOfficalBuild() bool {
+ return BuildNumber != "_BUILD_NUMBER_"
+}
+
func IsCurrentVersion(versionToCheck string) bool {
currentMajor, currentMinor, _ := SplitVersion(CurrentVersion)
toCheckMajor, toCheckMinor, _ := SplitVersion(versionToCheck)
diff --git a/utils/diagnostic.go b/utils/diagnostic.go
new file mode 100644
index 000000000..9a61ae934
--- /dev/null
+++ b/utils/diagnostic.go
@@ -0,0 +1,45 @@
+// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package utils
+
+import (
+ "net/http"
+
+ l4g "code.google.com/p/log4go"
+
+ "github.com/mattermost/platform/model"
+)
+
+const (
+ PROP_DIAGNOSTIC_ID = "id"
+ PROP_DIAGNOSTIC_CATEGORY = "c"
+ VAL_DIAGNOSTIC_CATEGORY_DEFALUT = "d"
+ PROP_DIAGNOSTIC_BUILD = "b"
+ PROP_DIAGNOSTIC_DATABASE = "db"
+ PROP_DIAGNOSTIC_OS = "os"
+ PROP_DIAGNOSTIC_USER_COUNT = "uc"
+)
+
+func SendDiagnostic(data model.StringMap) *model.AppError {
+ if Cfg.PrivacySettings.EnableDiagnostic && !model.IsOfficalBuild() {
+
+ query := "?"
+ for name, value := range data {
+ if len(query) > 1 {
+ query += "&"
+ }
+
+ query += name + "=" + UrlEncode(value)
+ }
+
+ res, err := http.Get("http://d7zmvsa9e04kk.cloudfront.net/i" + query)
+ if err != nil {
+ l4g.Error("Failed to send diagnostics %v", err.Error())
+ }
+
+ res.Body.Close()
+ }
+
+ return nil
+}
diff --git a/web/react/components/admin_console/privacy_settings.jsx b/web/react/components/admin_console/privacy_settings.jsx
index affd8ae11..c74d321e6 100644
--- a/web/react/components/admin_console/privacy_settings.jsx
+++ b/web/react/components/admin_console/privacy_settings.jsx
@@ -30,6 +30,7 @@ export default class PrivacySettings extends React.Component {
var config = this.props.config;
config.PrivacySettings.ShowEmailAddress = React.findDOMNode(this.refs.ShowEmailAddress).checked;
config.PrivacySettings.ShowFullName = React.findDOMNode(this.refs.ShowFullName).checked;
+ config.PrivacySettings.EnableDiagnostic = React.findDOMNode(this.refs.EnableDiagnostic).checked;
Client.saveConfig(
config,
@@ -137,6 +138,39 @@ export default class PrivacySettings extends React.Component {
</div>
<div className='form-group'>
+ <label
+ className='control-label col-sm-4'
+ htmlFor='EnableDiagnostic'
+ >
+ {'Send Error and Diagnostic: '}
+ </label>
+ <div className='col-sm-8'>
+ <label className='radio-inline'>
+ <input
+ type='radio'
+ name='EnableDiagnostic'
+ value='true'
+ ref='EnableDiagnostic'
+ defaultChecked={this.props.config.PrivacySettings.EnableDiagnostic}
+ onChange={this.handleChange}
+ />
+ {'true'}
+ </label>
+ <label className='radio-inline'>
+ <input
+ type='radio'
+ name='EnableDiagnostic'
+ value='false'
+ defaultChecked={!this.props.config.PrivacySettings.EnableDiagnostic}
+ onChange={this.handleChange}
+ />
+ {'false'}
+ </label>
+ <p className='help-text'>{'When true, The server will periodically send error and diagnostic information to Mattermost.'}</p>
+ </div>
+ </div>
+
+ <div className='form-group'>
<div className='col-sm-12'>
{serverError}
<button