mirror of https://github.com/grafana/grafana
commit
619c5c4f1b
@ -1,4 +1,4 @@ |
||||
{ |
||||
"stable": "4.0.1", |
||||
"testing": "4.0.1" |
||||
"stable": "4.0.2", |
||||
"testing": "4.0.2" |
||||
} |
||||
|
@ -0,0 +1,95 @@ |
||||
package models |
||||
|
||||
import ( |
||||
"crypto/tls" |
||||
"crypto/x509" |
||||
"net" |
||||
"net/http" |
||||
"sync" |
||||
"time" |
||||
) |
||||
|
||||
type proxyTransportCache struct { |
||||
cache map[int64]cachedTransport |
||||
sync.Mutex |
||||
} |
||||
|
||||
type cachedTransport struct { |
||||
updated time.Time |
||||
|
||||
*http.Transport |
||||
} |
||||
|
||||
var ptc = proxyTransportCache{ |
||||
cache: make(map[int64]cachedTransport), |
||||
} |
||||
|
||||
func (ds *DataSource) GetHttpClient() (*http.Client, error) { |
||||
transport, err := ds.GetHttpTransport() |
||||
|
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
|
||||
return &http.Client{ |
||||
Timeout: time.Duration(30 * time.Second), |
||||
Transport: transport, |
||||
}, nil |
||||
} |
||||
|
||||
func (ds *DataSource) GetHttpTransport() (*http.Transport, error) { |
||||
ptc.Lock() |
||||
defer ptc.Unlock() |
||||
|
||||
if t, present := ptc.cache[ds.Id]; present && ds.Updated.Equal(t.updated) { |
||||
return t.Transport, nil |
||||
} |
||||
|
||||
transport := &http.Transport{ |
||||
TLSClientConfig: &tls.Config{ |
||||
InsecureSkipVerify: true, |
||||
}, |
||||
Proxy: http.ProxyFromEnvironment, |
||||
Dial: (&net.Dialer{ |
||||
Timeout: 30 * time.Second, |
||||
KeepAlive: 30 * time.Second, |
||||
}).Dial, |
||||
TLSHandshakeTimeout: 10 * time.Second, |
||||
ExpectContinueTimeout: 1 * time.Second, |
||||
MaxIdleConns: 100, |
||||
IdleConnTimeout: 90 * time.Second, |
||||
} |
||||
|
||||
var tlsAuth, tlsAuthWithCACert bool |
||||
if ds.JsonData != nil { |
||||
tlsAuth = ds.JsonData.Get("tlsAuth").MustBool(false) |
||||
tlsAuthWithCACert = ds.JsonData.Get("tlsAuthWithCACert").MustBool(false) |
||||
} |
||||
|
||||
if tlsAuth { |
||||
transport.TLSClientConfig.InsecureSkipVerify = false |
||||
|
||||
decrypted := ds.SecureJsonData.Decrypt() |
||||
|
||||
if tlsAuthWithCACert && len(decrypted["tlsCACert"]) > 0 { |
||||
caPool := x509.NewCertPool() |
||||
ok := caPool.AppendCertsFromPEM([]byte(decrypted["tlsCACert"])) |
||||
if ok { |
||||
transport.TLSClientConfig.RootCAs = caPool |
||||
} |
||||
} |
||||
|
||||
cert, err := tls.X509KeyPair([]byte(decrypted["tlsClientCert"]), []byte(decrypted["tlsClientKey"])) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
transport.TLSClientConfig.Certificates = []tls.Certificate{cert} |
||||
} |
||||
|
||||
ptc.cache[ds.Id] = cachedTransport{ |
||||
Transport: transport, |
||||
updated: ds.Updated, |
||||
} |
||||
|
||||
return transport, nil |
||||
} |
@ -0,0 +1,157 @@ |
||||
package models |
||||
|
||||
import ( |
||||
"testing" |
||||
"time" |
||||
|
||||
. "github.com/smartystreets/goconvey/convey" |
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson" |
||||
"github.com/grafana/grafana/pkg/setting" |
||||
"github.com/grafana/grafana/pkg/util" |
||||
) |
||||
|
||||
func TestDataSourceCache(t *testing.T) { |
||||
Convey("When caching a datasource proxy", t, func() { |
||||
clearCache() |
||||
ds := DataSource{ |
||||
Id: 1, |
||||
Url: "http://k8s:8001", |
||||
Type: "Kubernetes", |
||||
} |
||||
|
||||
t1, err := ds.GetHttpTransport() |
||||
So(err, ShouldBeNil) |
||||
|
||||
t2, err := ds.GetHttpTransport() |
||||
So(err, ShouldBeNil) |
||||
|
||||
Convey("Should be using the cached proxy", func() { |
||||
So(t2, ShouldEqual, t1) |
||||
}) |
||||
}) |
||||
|
||||
Convey("When getting kubernetes datasource proxy", t, func() { |
||||
clearCache() |
||||
setting.SecretKey = "password" |
||||
|
||||
json := simplejson.New() |
||||
json.Set("tlsAuth", true) |
||||
json.Set("tlsAuthWithCACert", true) |
||||
|
||||
t := time.Now() |
||||
ds := DataSource{ |
||||
Url: "http://k8s:8001", |
||||
Type: "Kubernetes", |
||||
Updated: t.Add(-2 * time.Minute), |
||||
} |
||||
|
||||
transport, err := ds.GetHttpTransport() |
||||
So(err, ShouldBeNil) |
||||
|
||||
Convey("Should have no cert", func() { |
||||
So(transport.TLSClientConfig.InsecureSkipVerify, ShouldEqual, true) |
||||
}) |
||||
|
||||
ds.JsonData = json |
||||
ds.SecureJsonData = map[string][]byte{ |
||||
"tlsCACert": util.Encrypt([]byte(caCert), "password"), |
||||
"tlsClientCert": util.Encrypt([]byte(clientCert), "password"), |
||||
"tlsClientKey": util.Encrypt([]byte(clientKey), "password"), |
||||
} |
||||
ds.Updated = t.Add(-1 * time.Minute) |
||||
|
||||
transport, err = ds.GetHttpTransport() |
||||
So(err, ShouldBeNil) |
||||
|
||||
Convey("Should add cert", func() { |
||||
So(transport.TLSClientConfig.InsecureSkipVerify, ShouldEqual, false) |
||||
So(len(transport.TLSClientConfig.Certificates), ShouldEqual, 1) |
||||
}) |
||||
|
||||
ds.JsonData = nil |
||||
ds.SecureJsonData = map[string][]byte{} |
||||
ds.Updated = t |
||||
|
||||
transport, err = ds.GetHttpTransport() |
||||
So(err, ShouldBeNil) |
||||
|
||||
Convey("Should remove cert", func() { |
||||
So(transport.TLSClientConfig.InsecureSkipVerify, ShouldEqual, true) |
||||
So(len(transport.TLSClientConfig.Certificates), ShouldEqual, 0) |
||||
}) |
||||
}) |
||||
} |
||||
|
||||
func clearCache() { |
||||
ptc.Lock() |
||||
defer ptc.Unlock() |
||||
|
||||
ptc.cache = make(map[int64]cachedTransport) |
||||
} |
||||
|
||||
const caCert string = `-----BEGIN CERTIFICATE----- |
||||
MIIDATCCAemgAwIBAgIJAMQ5hC3CPDTeMA0GCSqGSIb3DQEBCwUAMBcxFTATBgNV |
||||
BAMMDGNhLWs4cy1zdGhsbTAeFw0xNjEwMjcwODQyMjdaFw00NDAzMTQwODQyMjda |
||||
MBcxFTATBgNVBAMMDGNhLWs4cy1zdGhsbTCCASIwDQYJKoZIhvcNAQEBBQADggEP |
||||
ADCCAQoCggEBAMLe2AmJ6IleeUt69vgNchOjjmxIIxz5sp1vFu94m1vUip7CqnOg |
||||
QkpUsHeBPrGYv8UGloARCL1xEWS+9FVZeXWQoDmbC0SxXhFwRIESNCET7Q8KMi/4 |
||||
4YPvnMLGZi3Fjwxa8BdUBCN1cx4WEooMVTWXm7RFMtZgDfuOAn3TNXla732sfT/d |
||||
1HNFrh48b0wA+HhmA3nXoBnBEblA665hCeo7lIAdRr0zJxJpnFnWXkyTClsAUTMN |
||||
iL905LdBiiIRenojipfKXvMz88XSaWTI7JjZYU3BvhyXndkT6f12cef3I96NY3WJ |
||||
0uIK4k04WrbzdYXMU3rN6NqlvbHqnI+E7aMCAwEAAaNQME4wHQYDVR0OBBYEFHHx |
||||
2+vSPw9bECHj3O51KNo5VdWOMB8GA1UdIwQYMBaAFHHx2+vSPw9bECHj3O51KNo5 |
||||
VdWOMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAH2eV5NcV3LBJHs9 |
||||
I+adbiTPg2vyumrGWwy73T0X8Dtchgt8wU7Q9b9Ucg2fOTmSSyS0iMqEu1Yb2ORB |
||||
CknM9mixHC9PwEBbkGCom3VVkqdLwSP6gdILZgyLoH4i8sTUz+S1yGPepi+Vzhs7 |
||||
adOXtryjcGnwft6HdfKPNklMOHFnjw6uqpho54oj/z55jUpicY/8glDHdrr1bh3k |
||||
MHuiWLGewHXPvxfG6UoUx1te65IhifVcJGFZDQwfEmhBflfCmtAJlZEsgTLlBBCh |
||||
FHoXIyGOdq1chmRVocdGBCF8fUoGIbuF14r53rpvcbEKtKnnP8+96luKAZLq0a4n |
||||
3lb92xM= |
||||
-----END CERTIFICATE-----` |
||||
|
||||
const clientCert string = `-----BEGIN CERTIFICATE----- |
||||
MIICsjCCAZoCCQCcd8sOfstQLzANBgkqhkiG9w0BAQsFADAXMRUwEwYDVQQDDAxj |
||||
YS1rOHMtc3RobG0wHhcNMTYxMTAyMDkyNTE1WhcNMTcxMTAyMDkyNTE1WjAfMR0w |
||||
GwYDVQQDDBRhZG0tZGFuaWVsLWs4cy1zdGhsbTCCASIwDQYJKoZIhvcNAQEBBQAD |
||||
ggEPADCCAQoCggEBAOMliaWyNEUJKM37vWCl5bGub3lMicyRAqGQyY/qxD9yKKM2 |
||||
FbucVcmWmg5vvTqQVl5rlQ+c7GI8OD6ptmFl8a26coEki7bFr8bkpSyBSEc5p27b |
||||
Z0ORFSqBHWHQbr9PkxPLYW6T3gZYUtRYv3OQgGxLXlvUh85n/mQfuR3N1FgmShHo |
||||
GtAFi/ht6leXa0Ms+jNSDLCmXpJm1GIEqgyKX7K3+g3vzo9coYqXq4XTa8Efs2v8 |
||||
SCwqWfBC3rHfgs/5DLB8WT4Kul8QzxkytzcaBQfRfzhSV6bkgm7oTzt2/1eRRsf4 |
||||
YnXzLE9YkCC9sAn+Owzqf+TYC1KRluWDfqqBTJUCAwEAATANBgkqhkiG9w0BAQsF |
||||
AAOCAQEAdMsZg6edWGC+xngizn0uamrUg1ViaDqUsz0vpzY5NWLA4MsBc4EtxWRP |
||||
ueQvjUimZ3U3+AX0YWNLIrH1FCVos2jdij/xkTUmHcwzr8rQy+B17cFi+a8jtpgw |
||||
AU6WWoaAIEhhbWQfth/Diz3mivl1ARB+YqiWca2mjRPLTPcKJEURDVddQ423el0Q |
||||
4JNxS5icu7T2zYTYHAo/cT9zVdLZl0xuLxYm3asK1IONJ/evxyVZima3il6MPvhe |
||||
58Hwz+m+HdqHxi24b/1J/VKYbISG4huOQCdLzeNXgvwFlGPUmHSnnKo1/KbQDAR5 |
||||
llG/Sw5+FquFuChaA6l5KWy7F3bQyA== |
||||
-----END CERTIFICATE-----` |
||||
|
||||
const clientKey string = `-----BEGIN RSA PRIVATE KEY----- |
||||
MIIEpQIBAAKCAQEA4yWJpbI0RQkozfu9YKXlsa5veUyJzJECoZDJj+rEP3IoozYV |
||||
u5xVyZaaDm+9OpBWXmuVD5zsYjw4Pqm2YWXxrbpygSSLtsWvxuSlLIFIRzmnbttn |
||||
Q5EVKoEdYdBuv0+TE8thbpPeBlhS1Fi/c5CAbEteW9SHzmf+ZB+5Hc3UWCZKEega |
||||
0AWL+G3qV5drQyz6M1IMsKZekmbUYgSqDIpfsrf6De/Oj1yhiperhdNrwR+za/xI |
||||
LCpZ8ELesd+Cz/kMsHxZPgq6XxDPGTK3NxoFB9F/OFJXpuSCbuhPO3b/V5FGx/hi |
||||
dfMsT1iQIL2wCf47DOp/5NgLUpGW5YN+qoFMlQIDAQABAoIBAQCzy4u312XeW1Cs |
||||
Mx6EuOwmh59/ESFmBkZh4rxZKYgrfE5EWlQ7i5SwG4BX+wR6rbNfy6JSmHDXlTkk |
||||
CKvvToVNcW6fYHEivDnVojhIERFIJ4+rhQmpBtcNLOQ3/4cZ8X/GxE6b+3lb5l+x |
||||
64mnjPLKRaIr5/+TVuebEy0xNTJmjnJ7yiB2HRz7uXEQaVSk/P7KAkkyl/9J3/LM |
||||
8N9AX1w6qDaNQZ4/P0++1H4SQenosM/b/GqGTomarEk/GE0NcB9rzmR9VCXa7FRh |
||||
WV5jyt9vUrwIEiK/6nUnOkGO8Ei3kB7Y+e+2m6WdaNoU5RAfqXmXa0Q/a0lLRruf |
||||
vTMo2WrBAoGBAPRaK4cx76Q+3SJ/wfznaPsMM06OSR8A3ctKdV+ip/lyKtb1W8Pz |
||||
k8MYQDH7GwPtSu5QD8doL00pPjugZL/ba7X9nAsI+pinyEErfnB9y7ORNEjIYYzs |
||||
DiqDKup7ANgw1gZvznWvb9Ge0WUSXvWS0pFkgootQAf+RmnnbWGH6l6RAoGBAO35 |
||||
aGUrLro5u9RD24uSXNU3NmojINIQFK5dHAT3yl0BBYstL43AEsye9lX95uMPTvOQ |
||||
Cqcn42Hjp/bSe3n0ObyOZeXVrWcDFAfE0wwB1BkvL1lpgnFO9+VQORlH4w3Ppnpo |
||||
jcPkR2TFeDaAYtvckhxe/Bk3OnuFmnsQ3VzM75fFAoGBAI6PvS2XeNU+yA3EtA01 |
||||
hg5SQ+zlHswz2TMuMeSmJZJnhY78f5mHlwIQOAPxGQXlf/4iP9J7en1uPpzTK3S0 |
||||
M9duK4hUqMA/w5oiIhbHjf0qDnMYVbG+V1V+SZ+cPBXmCDihKreGr5qBKnHpkfV8 |
||||
v9WL6o1rcRw4wiQvnaV1gsvBAoGBALtzVTczr6gDKCAIn5wuWy+cQSGTsBunjRLX |
||||
xuVm5iEiV+KMYkPvAx/pKzMLP96lRVR3ptyKgAKwl7LFk3u50+zh4gQLr35QH2wL |
||||
Lw7rNc3srAhrItPsFzqrWX6/cGuFoKYVS239l/sZzRppQPXcpb7xVvTp2whHcir0 |
||||
Wtnpl+TdAoGAGqKqo2KU3JoY3IuTDUk1dsNAm8jd9EWDh+s1x4aG4N79mwcss5GD |
||||
FF8MbFPneK7xQd8L6HisKUDAUi2NOyynM81LAftPkvN6ZuUVeFDfCL4vCA0HUXLD |
||||
+VrOhtUZkNNJlLMiVRJuQKUOGlg8PpObqYbstQAf/0/yFJMRHG82Tcg= |
||||
-----END RSA PRIVATE KEY-----` |
@ -0,0 +1,18 @@ |
||||
package models |
||||
|
||||
type HelpFlags1 uint64 |
||||
|
||||
const ( |
||||
HelpFlagGettingStartedPanelDismissed HelpFlags1 = 1 << iota |
||||
HelpFlagDashboardHelp1 |
||||
) |
||||
|
||||
func (f HelpFlags1) HasFlag(flag HelpFlags1) bool { return f&flag != 0 } |
||||
func (f *HelpFlags1) AddFlag(flag HelpFlags1) { *f |= flag } |
||||
func (f *HelpFlags1) ClearFlag(flag HelpFlags1) { *f &= ^flag } |
||||
func (f *HelpFlags1) ToggleFlag(flag HelpFlags1) { *f ^= flag } |
||||
|
||||
type SetUserHelpFlagCommand struct { |
||||
HelpFlags1 HelpFlags1 |
||||
UserId int64 |
||||
} |
@ -0,0 +1,118 @@ |
||||
package notifiers |
||||
|
||||
import ( |
||||
"fmt" |
||||
"strconv" |
||||
|
||||
"github.com/grafana/grafana/pkg/bus" |
||||
"github.com/grafana/grafana/pkg/components/simplejson" |
||||
"github.com/grafana/grafana/pkg/log" |
||||
"github.com/grafana/grafana/pkg/metrics" |
||||
m "github.com/grafana/grafana/pkg/models" |
||||
"github.com/grafana/grafana/pkg/services/alerting" |
||||
) |
||||
|
||||
func init() { |
||||
alerting.RegisterNotifier("opsgenie", NewOpsGenieNotifier) |
||||
} |
||||
|
||||
var ( |
||||
opsgenieCreateAlertURL string = "https://api.opsgenie.com/v1/json/alert" |
||||
opsgenieCloseAlertURL string = "https://api.opsgenie.com/v1/json/alert/close" |
||||
) |
||||
|
||||
func NewOpsGenieNotifier(model *m.AlertNotification) (alerting.Notifier, error) { |
||||
autoClose := model.Settings.Get("autoClose").MustBool(true) |
||||
apiKey := model.Settings.Get("apiKey").MustString() |
||||
if apiKey == "" { |
||||
return nil, alerting.ValidationError{Reason: "Could not find api key property in settings"} |
||||
} |
||||
|
||||
return &OpsGenieNotifier{ |
||||
NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.Settings), |
||||
ApiKey: apiKey, |
||||
AutoClose: autoClose, |
||||
log: log.New("alerting.notifier.opsgenie"), |
||||
}, nil |
||||
} |
||||
|
||||
type OpsGenieNotifier struct { |
||||
NotifierBase |
||||
ApiKey string |
||||
AutoClose bool |
||||
log log.Logger |
||||
} |
||||
|
||||
func (this *OpsGenieNotifier) Notify(evalContext *alerting.EvalContext) error { |
||||
metrics.M_Alerting_Notification_Sent_OpsGenie.Inc(1) |
||||
|
||||
var err error |
||||
switch evalContext.Rule.State { |
||||
case m.AlertStateOK: |
||||
if this.AutoClose { |
||||
err = this.closeAlert(evalContext) |
||||
} |
||||
case m.AlertStateAlerting: |
||||
err = this.createAlert(evalContext) |
||||
} |
||||
return err |
||||
} |
||||
|
||||
func (this *OpsGenieNotifier) createAlert(evalContext *alerting.EvalContext) error { |
||||
this.log.Info("Creating OpsGenie alert", "ruleId", evalContext.Rule.Id, "notification", this.Name) |
||||
|
||||
ruleUrl, err := evalContext.GetRuleUrl() |
||||
if err != nil { |
||||
this.log.Error("Failed get rule link", "error", err) |
||||
return err |
||||
} |
||||
|
||||
bodyJSON := simplejson.New() |
||||
bodyJSON.Set("apiKey", this.ApiKey) |
||||
bodyJSON.Set("message", evalContext.Rule.Name) |
||||
bodyJSON.Set("source", "Grafana") |
||||
bodyJSON.Set("alias", "alertId-"+strconv.FormatInt(evalContext.Rule.Id, 10)) |
||||
bodyJSON.Set("description", fmt.Sprintf("%s - %s\n%s", evalContext.Rule.Name, ruleUrl, evalContext.Rule.Message)) |
||||
|
||||
details := simplejson.New() |
||||
details.Set("url", ruleUrl) |
||||
if evalContext.ImagePublicUrl != "" { |
||||
details.Set("image", evalContext.ImagePublicUrl) |
||||
} |
||||
|
||||
bodyJSON.Set("details", details) |
||||
body, _ := bodyJSON.MarshalJSON() |
||||
|
||||
cmd := &m.SendWebhookSync{ |
||||
Url: opsgenieCreateAlertURL, |
||||
Body: string(body), |
||||
HttpMethod: "POST", |
||||
} |
||||
|
||||
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { |
||||
this.log.Error("Failed to send notification to OpsGenie", "error", err, "body", string(body)) |
||||
} |
||||
|
||||
return nil |
||||
} |
||||
|
||||
func (this *OpsGenieNotifier) closeAlert(evalContext *alerting.EvalContext) error { |
||||
this.log.Info("Closing OpsGenie alert", "ruleId", evalContext.Rule.Id, "notification", this.Name) |
||||
|
||||
bodyJSON := simplejson.New() |
||||
bodyJSON.Set("apiKey", this.ApiKey) |
||||
bodyJSON.Set("alias", "alertId-"+strconv.FormatInt(evalContext.Rule.Id, 10)) |
||||
body, _ := bodyJSON.MarshalJSON() |
||||
|
||||
cmd := &m.SendWebhookSync{ |
||||
Url: opsgenieCloseAlertURL, |
||||
Body: string(body), |
||||
HttpMethod: "POST", |
||||
} |
||||
|
||||
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { |
||||
this.log.Error("Failed to send notification to OpsGenie", "error", err, "body", string(body)) |
||||
} |
||||
|
||||
return nil |
||||
} |
@ -0,0 +1,52 @@ |
||||
package notifiers |
||||
|
||||
import ( |
||||
"testing" |
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson" |
||||
m "github.com/grafana/grafana/pkg/models" |
||||
. "github.com/smartystreets/goconvey/convey" |
||||
) |
||||
|
||||
func TestOpsGenieNotifier(t *testing.T) { |
||||
Convey("OpsGenie notifier tests", t, func() { |
||||
|
||||
Convey("Parsing alert notification from settings", func() { |
||||
Convey("empty settings should return error", func() { |
||||
json := `{ }` |
||||
|
||||
settingsJSON, _ := simplejson.NewJson([]byte(json)) |
||||
model := &m.AlertNotification{ |
||||
Name: "opsgenie_testing", |
||||
Type: "opsgenie", |
||||
Settings: settingsJSON, |
||||
} |
||||
|
||||
_, err := NewOpsGenieNotifier(model) |
||||
So(err, ShouldNotBeNil) |
||||
}) |
||||
|
||||
Convey("settings should trigger incident", func() { |
||||
json := ` |
||||
{ |
||||
"apiKey": "abcdefgh0123456789" |
||||
}` |
||||
|
||||
settingsJSON, _ := simplejson.NewJson([]byte(json)) |
||||
model := &m.AlertNotification{ |
||||
Name: "opsgenie_testing", |
||||
Type: "opsgenie", |
||||
Settings: settingsJSON, |
||||
} |
||||
|
||||
not, err := NewOpsGenieNotifier(model) |
||||
opsgenieNotifier := not.(*OpsGenieNotifier) |
||||
|
||||
So(err, ShouldBeNil) |
||||
So(opsgenieNotifier.Name, ShouldEqual, "opsgenie_testing") |
||||
So(opsgenieNotifier.Type, ShouldEqual, "opsgenie") |
||||
So(opsgenieNotifier.ApiKey, ShouldEqual, "abcdefgh0123456789") |
||||
}) |
||||
}) |
||||
}) |
||||
} |
@ -1,29 +0,0 @@ |
||||
package tsdb |
||||
|
||||
import ( |
||||
"crypto/tls" |
||||
"net" |
||||
"net/http" |
||||
"time" |
||||
) |
||||
|
||||
func GetDefaultClient() *http.Client { |
||||
tr := &http.Transport{ |
||||
Proxy: http.ProxyFromEnvironment, |
||||
DialContext: (&net.Dialer{ |
||||
Timeout: 30 * time.Second, |
||||
KeepAlive: 30 * time.Second, |
||||
}).DialContext, |
||||
MaxIdleConns: 100, |
||||
IdleConnTimeout: 90 * time.Second, |
||||
TLSHandshakeTimeout: 10 * time.Second, |
||||
ExpectContinueTimeout: 1 * time.Second, |
||||
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, |
||||
} |
||||
|
||||
return &http.Client{ |
||||
Timeout: time.Duration(30 * time.Second), |
||||
Transport: tr, |
||||
} |
||||
} |
@ -0,0 +1,2 @@ |
||||
# Plugin List Panel - Native Plugin |
||||
|
@ -0,0 +1,40 @@ |
||||
<div class="gf-form-group"> |
||||
<div class="gf-form-inline"> |
||||
<div class="gf-form"> |
||||
<span class="gf-form-label width-10">Mode</span> |
||||
<div class="gf-form-select-wrapper max-width-10"> |
||||
<select class="gf-form-input" ng-model="ctrl.panel.mode" ng-options="f for f in ctrl.modes" ng-change="ctrl.refresh()"></select> |
||||
</div> |
||||
</div> |
||||
<div class="gf-form" ng-show="ctrl.panel.mode === 'recently viewed'"> |
||||
<span class="gf-form-label"> |
||||
<i class="grafana-tip fa fa-question-circle ng-scope" bs-tooltip="'WARNING: This list will be cleared when clearing browser cache'" data-original-title="" title=""></i> |
||||
</span> |
||||
</div> |
||||
</div> |
||||
|
||||
<div class="gf-form-inline" ng-if="ctrl.panel.mode === 'search'"> |
||||
<div class="gf-form"> |
||||
<span class="gf-form-label width-10">Search options</span> |
||||
<span class="gf-form-label">Query</span> |
||||
|
||||
<input type="text" class="gf-form-input" placeholder="title query" |
||||
ng-model="ctrl.panel.query" ng-change="ctrl.refresh()" ng-model-onblur> |
||||
|
||||
</div> |
||||
|
||||
<div class="gf-form"> |
||||
<span class="gf-form-label">Tags</span> |
||||
|
||||
<bootstrap-tagsinput ng-model="ctrl.panel.tags" tagclass="label label-tag" placeholder="add tags" on-tags-updated="ctrl.refresh()"> |
||||
</bootstrap-tagsinput> |
||||
</div> |
||||
</div> |
||||
|
||||
<div class="gf-form-inline"> |
||||
<div class="gf-form"> |
||||
<span class="gf-form-label width-10">Limit number to</span> |
||||
<input class="gf-form-input" type="number" ng-model="ctrl.panel.limit" ng-model-onblur ng-change="ctrl.refresh()"> |
||||
</div> |
||||
</div> |
||||
</div> |
After Width: | Height: | Size: 8.8 KiB |
@ -0,0 +1,19 @@ |
||||
<div class="dashlist" ng-if="ctrl.checksDone"> |
||||
<div class="dashlist-section"> |
||||
<h6 class="dashlist-section-header"> |
||||
Getting Started with Grafana |
||||
<button class="dashlist-cta-close-btn" ng-click="ctrl.dismiss()"> |
||||
<i class="fa fa-remove"></i> |
||||
</button> |
||||
</h6> |
||||
<ul class="progress-tracker"> |
||||
<li class="progress-step" ng-repeat="step in ctrl.steps" ng-class="step.cssClass"> |
||||
<a class="progress-link" ng-href="{{step.href}}" target="{{step.target}}" title="{{step.note}}"> |
||||
<span class="progress-marker" ng-class="step.cssClass"><i class="{{step.icon}}"></i></span> |
||||
<span class="progress-text" ng-href="{{step.href}}" target="{{step.target}}">{{step.title}}</span> |
||||
</a> |
||||
<a class="btn progress-step-cta" ng-href="{{step.href}}" target="{{step.target}}">{{step.cta}}</a> |
||||
</li> |
||||
</ul> |
||||
</div> |
||||
</div> |
@ -0,0 +1,119 @@ |
||||
///<reference path="../../../headers/common.d.ts" />
|
||||
|
||||
import {PanelCtrl} from 'app/plugins/sdk'; |
||||
|
||||
import {contextSrv} from 'app/core/core'; |
||||
|
||||
class GettingStartedPanelCtrl extends PanelCtrl { |
||||
static templateUrl = 'public/app/plugins/panel/gettingstarted/module.html'; |
||||
checksDone: boolean; |
||||
stepIndex: number; |
||||
steps: any; |
||||
|
||||
/** @ngInject **/ |
||||
constructor($scope, $injector, private backendSrv, private datasourceSrv, private $q) { |
||||
super($scope, $injector); |
||||
|
||||
this.stepIndex = 0; |
||||
this.steps = []; |
||||
|
||||
this.steps.push({ |
||||
title: 'Install Grafana', |
||||
icon: 'icon-gf icon-gf-check', |
||||
href: 'http://docs.grafana.org/', |
||||
target: '_blank', |
||||
note: 'Review the installation docs', |
||||
check: () => $q.when(true), |
||||
}); |
||||
|
||||
this.steps.push({ |
||||
title: 'Create your first data source', |
||||
cta: 'Add data source', |
||||
icon: 'icon-gf icon-gf-datasources', |
||||
href: 'datasources/new?gettingstarted', |
||||
check: () => { |
||||
return $q.when( |
||||
datasourceSrv.getMetricSources().filter(item => { |
||||
return item.meta.builtIn === false; |
||||
}).length > 0 |
||||
); |
||||
} |
||||
}); |
||||
|
||||
this.steps.push({ |
||||
title: 'Create your first dashboard', |
||||
cta: 'New dashboard', |
||||
icon: 'icon-gf icon-gf-dashboard', |
||||
href: 'dashboard/new?gettingstarted', |
||||
check: () => { |
||||
return this.backendSrv.search({limit: 1}).then(result => { |
||||
return result.length > 0; |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
this.steps.push({ |
||||
title: 'Invite your team', |
||||
cta: 'Add Users', |
||||
icon: 'icon-gf icon-gf-users', |
||||
href: 'org/users?gettingstarted', |
||||
check: () => { |
||||
return this.backendSrv.get('api/org/users').then(res => { |
||||
return res.length > 1; |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
|
||||
this.steps.push({ |
||||
title: 'Install apps & plugins', |
||||
cta: 'Explore plugin repository', |
||||
icon: 'icon-gf icon-gf-apps', |
||||
href: 'https://grafana.net/plugins?utm_source=grafana_getting_started', |
||||
check: () => { |
||||
return this.backendSrv.get('api/plugins', {embedded: 0, core: 0}).then(plugins => { |
||||
return plugins.length > 0; |
||||
}); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
$onInit() { |
||||
this.stepIndex = -1; |
||||
return this.nextStep().then(res => { |
||||
this.checksDone = true; |
||||
}); |
||||
} |
||||
|
||||
nextStep() { |
||||
if (this.stepIndex === this.steps.length - 1) { |
||||
return this.$q.when(); |
||||
} |
||||
|
||||
this.stepIndex += 1; |
||||
var currentStep = this.steps[this.stepIndex]; |
||||
return currentStep.check().then(passed => { |
||||
if (passed) { |
||||
currentStep.cssClass = 'completed'; |
||||
return this.nextStep(); |
||||
} |
||||
|
||||
currentStep.cssClass = 'active'; |
||||
return this.$q.when(); |
||||
}); |
||||
} |
||||
|
||||
dismiss() { |
||||
this.row.removePanel(this.panel, false); |
||||
|
||||
this.backendSrv.request({ |
||||
method: 'PUT', |
||||
url: '/api/user/helpflags/1', |
||||
showSuccessAlert: false, |
||||
}).then(res => { |
||||
contextSrv.user.helpFlags1 = res.helpFlags1; |
||||
}); |
||||
} |
||||
} |
||||
|
||||
export {GettingStartedPanelCtrl, GettingStartedPanelCtrl as PanelCtrl} |
@ -0,0 +1,18 @@ |
||||
{ |
||||
"type": "panel", |
||||
"name": "Getting Started", |
||||
"id": "gettingstarted", |
||||
|
||||
"hideFromList": true, |
||||
|
||||
"info": { |
||||
"author": { |
||||
"name": "Grafana Project", |
||||
"url": "http://grafana.org" |
||||
}, |
||||
"logos": { |
||||
"small": "img/icn-dashlist-panel.svg", |
||||
"large": "img/icn-dashlist-panel.svg" |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,171 @@ |
||||
|
||||
// Colours |
||||
$progress-color-dark: $panel-bg !default; |
||||
$progress-color: $panel-bg !default; |
||||
$progress-color-light: $panel-bg !default; |
||||
$progress-color-grey-light: $body-bg !default; |
||||
$progress-color-shadow: $panel-border !default; |
||||
$progress-color-grey: $iconContainerBackground !default; |
||||
$progress-color-grey-dark: $iconContainerBackground !default; |
||||
|
||||
// Sizing |
||||
$marker-size: 60px !default; |
||||
$marker-size-half: ($marker-size / 2); |
||||
$path-height: 2px !default; |
||||
$path-position: $marker-size-half - ($path-height / 2); |
||||
|
||||
|
||||
.dashlist-cta-close-btn { |
||||
color: $text-color-weak; |
||||
float: right; |
||||
padding: 0; |
||||
margin: 0 2px 0 0; |
||||
background-color: transparent; |
||||
border: none; |
||||
|
||||
i { |
||||
font-size: 80%; |
||||
} |
||||
|
||||
&:hover { |
||||
color: $white; |
||||
} |
||||
} |
||||
|
||||
// Container element |
||||
.progress-tracker { |
||||
display: flex; |
||||
margin: 20px auto; |
||||
padding: 0; |
||||
list-style: none; |
||||
} |
||||
|
||||
// Step container that creates lines between steps |
||||
.progress-step { |
||||
text-align: center; |
||||
position: relative; |
||||
flex: 1 1 0%; |
||||
margin: 0; |
||||
padding: 0; |
||||
color: $text-color-weak; |
||||
|
||||
// For a flexbox bug in firefox that wont allow the text overflow on the text |
||||
min-width: $marker-size; |
||||
|
||||
&::after { |
||||
right: -50%; |
||||
content: ''; |
||||
display: block; |
||||
position: absolute; |
||||
z-index: 1; |
||||
top: $path-position; |
||||
bottom: $path-position; |
||||
right: - $marker-size-half; |
||||
width: 100%; |
||||
height: $path-height; |
||||
border-top: 2px solid $progress-color-grey-light; |
||||
border-bottom: $progress-color-shadow; |
||||
background: $progress-color-grey-light; |
||||
} |
||||
|
||||
&:first-child { |
||||
&::after { |
||||
left: 50%; |
||||
} |
||||
} |
||||
&:last-child { |
||||
&::after { |
||||
right: 50%; |
||||
} |
||||
} |
||||
|
||||
// Active state |
||||
&.active { |
||||
.progress-step-cta { |
||||
display: inline-block; |
||||
} |
||||
.progress-title { |
||||
font-weight: 400; |
||||
} |
||||
.progress-text { |
||||
display: none; |
||||
} |
||||
.progress-marker { |
||||
.icon-gf { |
||||
color: $brand-primary; |
||||
-webkit-text-fill-color: transparent; |
||||
background: $brand-gradient; |
||||
-webkit-background-clip: text; |
||||
text-decoration:none; |
||||
} |
||||
} |
||||
} |
||||
|
||||
&.completed { |
||||
.progress-marker { |
||||
color: $online; |
||||
|
||||
// change icon to check |
||||
.icon-gf::before { |
||||
content: "\e604"; |
||||
} |
||||
} |
||||
.progress-text { |
||||
text-decoration: line-through; |
||||
} |
||||
&::after { |
||||
background: $progress-color-grey-light; |
||||
} |
||||
} |
||||
} |
||||
|
||||
.progress-step-cta { |
||||
@include button-size($btn-padding-y-sm, $btn-padding-x-sm, $font-size-sm, $btn-border-radius); |
||||
@include buttonBackground($btn-success-bg, $btn-success-bg-hl); |
||||
display: none; |
||||
} |
||||
|
||||
// Progress marker |
||||
.progress-marker { |
||||
display: flex; |
||||
justify-content: center; |
||||
align-items: center; |
||||
position: relative; |
||||
width: $marker-size; |
||||
height: $marker-size; |
||||
padding-bottom: 2px; // To align text within the marker |
||||
z-index: 20; |
||||
background-color: $panel-bg; |
||||
margin-left: auto; |
||||
margin-right: auto; |
||||
margin-bottom: $spacer; |
||||
color: $text-color-weak; |
||||
font-size: 35px; |
||||
vertical-align: sub; |
||||
} |
||||
|
||||
// Progress text |
||||
.progress-text { |
||||
display: block; |
||||
overflow: hidden; |
||||
text-overflow: ellipsis; |
||||
color: $text-muted; |
||||
} |
||||
|
||||
.progress-marker { |
||||
color: $text-color-weak; |
||||
text-decoration:none; |
||||
font-size: 35px; |
||||
vertical-align: sub; |
||||
} |
||||
|
||||
a.progress-link { |
||||
&:hover { |
||||
.progress-marker, .progress-text { |
||||
color: $link-hover-color; |
||||
} |
||||
&:hover .progress-marker.completed { |
||||
color: $online; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue