Skip to content

Instantly share code, notes, and snippets.

@skord
Last active November 10, 2016 18:25
Show Gist options
  • Save skord/aa12874791c90b588376caaa356f287d to your computer and use it in GitHub Desktop.
Save skord/aa12874791c90b588376caaa356f287d to your computer and use it in GitHub Desktop.
---
"Server 0x1ca8fd0 (mariadb1)":
"Server": "mariadb1"
"Status": "Master, Running"
"Protocol": "MySQLBackend"
"Port": "3306"
"Server Version": "10.1.18-MariaDB"
"Node Id": "1"
"Master Id": "-1"
"Slave Ids": "2, 3 , 4 , 5"
"Repl Depth": "0"
"Number of connections": "0"
"Current no. of conns": "0"
"Current no. of operations": "0"
"Server 0x1ca8a90 (mariadb2)":
"Server": "mariadb2"
"Status": "Slave, Running"
"Protocol": "MySQLBackend"
"Port": "3306"
"Server Version": "10.1.18-MariaDB"
"Node Id": "2"
"Master Id": "1"
"Slave Ids": ""
"Repl Depth": "1"
"Number of connections": "0"
"Current no. of conns": "0"
"Current no. of operations": "0"
"Server 0x1ca8550 (mariadb3)":
"Server": "mariadb3"
"Status": "Slave, Running"
"Protocol": "MySQLBackend"
"Port": "3306"
"Server Version": "10.1.18-MariaDB"
"Node Id": "3"
"Master Id": "1"
"Slave Ids": ""
"Repl Depth": "1"
"Number of connections": "0"
"Current no. of conns": "0"
"Current no. of operations": "0"
"Server 0x1ca8010 (mariadb4)":
"Server": "mariadb4"
"Status": "Slave, Running"
"Protocol": "MySQLBackend"
"Port": "3306"
"Server Version": "10.1.18-MariaDB"
"Node Id": "4"
"Master Id": "1"
"Slave Ids": ""
"Repl Depth": "1"
"Number of connections": "0"
"Current no. of conns": "0"
"Current no. of operations": "0"
"Server 0x1ca7ad0 (mariadb5)":
"Server": "mariadb5"
"Status": "Slave, Running"
"Protocol": "MySQLBackend"
"Port": "3306"
"Server Version": "10.1.18-MariaDB"
"Node Id": "5"
"Master Id": "1"
"Slave Ids": ""
"Repl Depth": "1"
"Number of connections": "0"
"Current no. of conns": "0"
"Current no. of operations": "0"
package main
import (
"bufio"
"fmt"
"os"
"regexp"
"strings"
)
func fmtKv(x string) {
splitvals := strings.SplitN(x, ":", 2)
key := "\"" + strings.TrimSpace(splitvals[0]) + "\""
value := strings.TrimSpace(splitvals[len(splitvals)-1])
multivalue := strings.Split(value, ",")
fmt.Printf(" %s: ", key)
if len(multivalue) > 1 {
fmt.Printf("\n")
for _, v := range multivalue {
fmt.Printf(" - \"%s\"\n", strings.TrimSpace(v))
}
} else {
fmt.Printf("\"" + value + "\"\n")
}
}
func main() {
f, _ := os.Open("monitors.txt")
scanner := bufio.NewScanner(f)
fmt.Println("---")
for scanner.Scan() {
server := regexp.MustCompile("^[[:alpha:]].*")
valuere := regexp.MustCompile("^[[:blank:]].*")
line := scanner.Text()
serverMatch := server.FindString(line)
valueMatch := valuere.FindString(line)
if serverMatch != "" {
fmt.Printf("\"%s\":\n",serverMatch)
}
if valueMatch != "" {
fmtKv(valueMatch)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment