From 24c0f28f417f2eacf909f9fe9a3ab98605a12db3 Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Mon, 19 Mar 2018 13:24:31 +0100 Subject: [PATCH] mssql: allow host without port and fallback to default port 1433 --- pkg/tsdb/mssql/mssql.go | 11 +++++++---- .../app/plugins/datasource/mssql/partials/config.html | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/tsdb/mssql/mssql.go b/pkg/tsdb/mssql/mssql.go index 38e10d77eec..ab4998b2183 100644 --- a/pkg/tsdb/mssql/mssql.go +++ b/pkg/tsdb/mssql/mssql.go @@ -38,10 +38,13 @@ func NewMssqlQueryEndpoint(datasource *models.DataSource) (tsdb.TsdbQueryEndpoin MacroEngine: NewMssqlMacroEngine(), } - serport := datasource.Url - // fix me: need to have a default port if user did not provide. i.e. 1433 - words := strings.Split(serport, ":") - server, port := words[0], words[1] + hostParts := strings.Split(datasource.Url, ":") + if len(hostParts) < 2 { + hostParts = append(hostParts, "1433") + } + + server, port := hostParts[0], hostParts[1] + endpoint.log.Debug("cnnstr", "hostParts len", len(hostParts)) cnnstr := fmt.Sprintf("server=%s;port=%s;database=%s;user id=%s;password=%s;", server, port, diff --git a/public/app/plugins/datasource/mssql/partials/config.html b/public/app/plugins/datasource/mssql/partials/config.html index 9da64fa12c2..d0bfcc84546 100644 --- a/public/app/plugins/datasource/mssql/partials/config.html +++ b/public/app/plugins/datasource/mssql/partials/config.html @@ -4,7 +4,7 @@
Host - +