package pkg import ( "errors" "strings" ) type TCPAnalyticsProfile struct { ProfileCommon CollectCity string `json:"collect_city"` // disabled CollectContinent string `json:"collect_continent"` // enabled CollectCountry string `json:"collect_country"` // enabled CollectNexthop string `json:"collect_nexthop"` // disabled CollectPostCode string `json:"collect_post_code"` // disabled CollectRegion string `json:"collect_region"` // disabled CollectRemoteHostIP string `json:"collect_remote_host_ip"` // disabled CollectRemoteHostSubnet string `json:"collect_remote_host_subnet"` // enabled CollectedByClientSide string `json:"collected_by_client_side"` // enabled CollectedByServerSide string `json:"collected_by_server_side"` // disabled CollectedStatsExternalLogging string `json:"collected_stats_external_logging"` // disabled CollectedStatsInternalLogging string `json:"collected_stats_internal_logging"` // enabled ExternalLoggingPublisher string `json:"external_logging_publisher"` // none } func ParseTCPAnalytics(raw string) (*TCPAnalyticsProfile, error) { p := new(TCPAnalyticsProfile) split := strings.Split(raw, "\n") if !strings.Contains(split[0], "ltm profile tcp-analytics") { return nil, errors.New("not a tcp-analytics profile") } p.ProfileCommon = parseCommon(raw) for _, line := range split { f := strings.Fields(line) switch strings.ToLower(f[0]) { case "collect-city": p.CollectCity = strings.Join(f[1:], " ") case "collect-continent": p.CollectContinent = strings.Join(f[1:], " ") case "collect-country": p.CollectCountry = strings.Join(f[1:], " ") case "collect-nexthop": p.CollectNexthop = strings.Join(f[1:], " ") case "collect-post-code": p.CollectPostCode = strings.Join(f[1:], " ") case "collect-region": p.CollectRegion = strings.Join(f[1:], " ") case "collect-remote-host-ip": p.CollectRemoteHostIP = strings.Join(f[1:], " ") case "collect-remote-host-subnet": p.CollectRemoteHostSubnet = strings.Join(f[1:], " ") case "collected-by-client-side": p.CollectedByClientSide = strings.Join(f[1:], " ") case "collected-by-server-side": p.CollectedByServerSide = strings.Join(f[1:], " ") case "collected-stats-external-logging": p.CollectedStatsExternalLogging = strings.Join(f[1:], " ") case "collected-stats-internal-logging": p.CollectedStatsInternalLogging = strings.Join(f[1:], " ") case "external-logging-publisher": p.ExternalLoggingPublisher = strings.Join(f[1:], " ") } } return p, nil }