package pkg import ( "regexp" "github.rackspace.com/gorax/tools/util" ) var ( LTMSHPOOLRE = regexp.MustCompile(`(?i)(ltm::|)pool:\s+(\S+)((.|\n)*?)(ltm::|$)`) LTMSHPOOLAVILRE = regexp.MustCompile(`(?i)availability\s+:\s+(\S+)`) STATERE = regexp.MustCompile(`(?i)state\s+:\s+(.*?)`) LTMSHPOOLREASONRE = regexp.MustCompile(`(?i)reason\s+:[ ]+(.*?)\n`) LTMSHPOOLBITSINRE = regexp.MustCompile(`(?i)bits\s+in\s+(\S+)`) LTMSHPOOLBITSOUTRE = regexp.MustCompile(`(?i)bits\s+out\s+(\S+)`) LTMSHPOOLPACKINRE = regexp.MustCompile(`(?i)packets\s+in\s+(\S+)`) LTMSHPOOLPACKOUTRE = regexp.MustCompile(`(?i)packets\s+out\s+(\S+)`) LTMSHPOOLCURCONRE = regexp.MustCompile(`(?i)current\s+connections\s+(\S+)`) LTMSHPOOLMAXCONRE = regexp.MustCompile(`(?i)maximum\s+connections\s+(\S+)`) LTMSHPOOLTOTALCONRE = regexp.MustCompile(`(?i)total\s+connections\s+(\S+)`) ) type ( PoolStats struct { PoolStats []*PoolStat `json:"pool_status"` } PoolStat struct { Name string `json:"name"` Status *Status `json:"status"` Traffic *Traffic `json:"traffic"` } Status struct { Avail string `json:"availability"` State string `json:"state"` Reason string `json:"reason"` } Traffic struct { BitsIn string `json:"bits_in"` BitsOut string `json:"bits_out"` PackIn string `json:"packets_in"` PackOut string `json:"packets_out"` CurrCon string `json:"current_connections"` MaxCon string `json:"maximum_connections"` TotalCon string `json:"total_connections"` } ) func (p *PoolStats) Parse(s string) { for _, v := range LTMSHPOOLRE.FindAllStringSubmatch(s, -1) { p.PoolStats = append(p.PoolStats, &PoolStat{ Name: v[2], Status: &Status{ Avail: util.RegexpString(LTMSHPOOLAVILRE, v[3]), State: util.RegexpString(STATERE, v[3]), Reason: util.RegexpString(LTMSHPOOLREASONRE, v[3]), }, Traffic: &Traffic{ BitsIn: util.RegexpString(LTMSHPOOLBITSINRE, v[3]), BitsOut: util.RegexpString(LTMSHPOOLBITSOUTRE, v[3]), PackIn: util.RegexpString(LTMSHPOOLPACKINRE, v[3]), PackOut: util.RegexpString(LTMSHPOOLPACKOUTRE, v[3]), CurrCon: util.RegexpString(LTMSHPOOLCURCONRE, v[3]), MaxCon: util.RegexpString(LTMSHPOOLMAXCONRE, v[3]), TotalCon: util.RegexpString(LTMSHPOOLTOTALCONRE, v[3]), }, }) } }