package parsers import ( "regexp" "github.rackspace.com/gorax/tools/util" ) // used with 'show script-profile' var ( scriptProfilesRe = regexp.MustCompile(`Script\s+profile\s+(\S+)\n((.|\n)*?)\n\n`) memoryLimitRe = regexp.MustCompile(`Memory\s+limit:\s+(\d+)`) memHighWaterMarkRe = regexp.MustCompile(`Memory\s+high\s+water\s+mark:\s+(\S+)`) timeoutRe = regexp.MustCompile(`Time\s+out:\s+(\S+)`) dataCollectionLimitRe = regexp.MustCompile(`Data\s+collection\s+limit:\s+(\d+)`) restartLimitRe = regexp.MustCompile(`Restart\s+Limit:\s+(\S+)`) printOutputRe = regexp.MustCompile(`Print\s+Output:\s+(\S+)`) ) type ( // AdxScriptProfiles type defines a listing of script-profiles in the ADX configuration AdxScriptProfiles struct { ScriptProfile []AdxScriptProfile `json:"script-profiles"` } // AdxScriptProfile is the parsed details about a script-profile AdxScriptProfile struct { Name string `json:"name"` MemoryLimit string `json:"memory limit"` MemHighWaterMark string `json:"memory high water mark"` Timeout string `json:"timeout"` DataCollectionLimit string `json:"data collection limit"` RestartLimit string `json:"restart limit"` PrintOutput string `json:"print output"` } ) // Parse method is used to implement type population of a given string // using parsers to populate the method receiver. func (a *AdxScriptProfiles) Parse(s string) { for _, v := range scriptProfilesRe.FindAllStringSubmatch(s, -1) { var p AdxScriptProfile p.Name = v[1] p.parse(v[2]) a.ScriptProfile = append(a.ScriptProfile, p) } } func (p *AdxScriptProfile) parse(s string) { p.MemoryLimit = util.RegexpFindString(memoryLimitRe, s) p.MemHighWaterMark = util.RegexpFindString(memHighWaterMarkRe, s) p.Timeout = util.RegexpFindString(timeoutRe, s) p.DataCollectionLimit = util.RegexpFindString(dataCollectionLimitRe, s) p.RestartLimit = util.RegexpFindString(restartLimitRe, s) p.PrintOutput = util.RegexpFindString(printOutputRe, s) }