Explorar el Código

mssql: allow host without port and fallback to default port 1433

Marcus Efraimsson hace 7 años
padre
commit
24c0f28f41

+ 7 - 4
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,

+ 1 - 1
public/app/plugins/datasource/mssql/partials/config.html

@@ -4,7 +4,7 @@
 <div class="gf-form-group">
 	<div class="gf-form max-width-30">
 		<span class="gf-form-label width-7">Host</span>
-		<input type="text" class="gf-form-input" ng-model='ctrl.current.url' placeholder="localhost:1433" bs-typeahead="{{['localhost:1433']}}" required></input>
+		<input type="text" class="gf-form-input" ng-model='ctrl.current.url' placeholder="localhost:1433" bs-typeahead="{{['localhost', 'localhost:1433']}}" required></input>
 	</div>
 
 	<div class="gf-form max-width-30">