From 60e7e7ed7cffeb7f85ecd24586ef55b155204768 Mon Sep 17 00:00:00 2001 From: Adithya B Cherunilam Date: Thu, 22 Oct 2015 19:39:51 +0530 Subject: [PATCH] MySQL Plugin - Extract the server info out of the DSN (Data Source Name) --- plugins/mysql/mysql.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/mysql/mysql.go b/plugins/mysql/mysql.go index 89c4c9b44..d3b524ac3 100644 --- a/plugins/mysql/mysql.go +++ b/plugins/mysql/mysql.go @@ -2,6 +2,7 @@ package mysql import ( "database/sql" + "regexp" "strconv" "strings" @@ -132,7 +133,8 @@ func (m *Mysql) gatherServer(serv string, acc plugins.Accumulator) error { // Parse out user/password from server address tag if given var servtag string if strings.Contains(serv, "@") { - servtag = strings.Split(serv, "@")[1] + r, _ := regexp.Compile("(.*)[:](.*)[@]([a-z]+)[(|:][/]*(.*)[:]([0-9]+)[)]?[/]([^?]*)[?]?([^?]*)") + servtag = r.FindStringSubmatch(serv)[4] } else if serv == "" { servtag = "localhost" } else {