MySQL Plugin - Extract the server info out of the DSN (Data Source Name)
This commit is contained in:
parent
2f08577967
commit
60e7e7ed7c
|
@ -2,6 +2,7 @@ package mysql
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"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
|
// Parse out user/password from server address tag if given
|
||||||
var servtag string
|
var servtag string
|
||||||
if strings.Contains(serv, "@") {
|
if strings.Contains(serv, "@") {
|
||||||
servtag = strings.Split(serv, "@")[1]
|
r, _ := regexp.Compile("(.*)[:](.*)[@]([a-z]+)[(|:][/]*(.*)[:]([0-9]+)[)]?[/]([^?]*)[?]?([^?]*)")
|
||||||
|
servtag = r.FindStringSubmatch(serv)[4]
|
||||||
} else if serv == "" {
|
} else if serv == "" {
|
||||||
servtag = "localhost"
|
servtag = "localhost"
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue