package pkg import ( "errors" "strconv" "strings" ) type DNSProfile struct { ProfileCommon AVRDNSStatSampleRate int `json:"avr_dnsstat_sample_rate"` Cache string `json:"cache"` DNS64 string `json:"dns64"` DNS64AdditionalSectionRewrite string `json:"dns64_additional_section_rewrite"` DNS64Prefix string `json:"dns64_prefix"` DNSSecurity string `json:"dns_security"` EnableCache string `json:"enable_cache"` EnableDNSExpress string `json:"enable_dns_express"` EnableDNSFirewall string `json:"enable_dns_firewall"` EnableDNSSec string `json:"enable_dnssec"` EnableGTM string `json:"enable_gtm"` EnableHardwareQueryValidation string `json:"enable_hardware_query_validation"` EnableHardwareResponseCache string `json:"enable_hardware_response_cache"` EnableLogging string `json:"enable_logging"` EnableRapidResponse string `json:"enable_rapid_response"` LogProfile string `json:"log_profile"` ProcessRD string `json:"process_rd"` ProcessXFR string `json:"process_xfr"` RapidResponseLastAction string `json:"rapid_response_last_action"` UnhandledQueryAction string `json:"unhandled_query_action"` UseLocalBind string `json:"use_local_bind"` } func ParseDNSProfile(raw string) (*DNSProfile, error) { p := new(DNSProfile) split := strings.Split(raw, "\n") if !strings.Contains(split[0], "ltm profile dns") { return nil, errors.New("not a dns profile") } p.ProfileCommon = parseCommon(raw) for _, line := range split { f := strings.Fields(line) switch strings.ToLower(f[0]) { case "avr-dnsstat-sample-rate": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.AVRDNSStatSampleRate = i case "cache": p.Cache = strings.Join(f[1:], " ") case "dns64": p.DNS64 = strings.Join(f[1:], " ") case "dns64-additional-section-rewrite": p.DNS64AdditionalSectionRewrite = strings.Join(f[1:], " ") case "dns64-prefix": p.DNS64Prefix = strings.Join(f[1:], " ") case "dns-security": p.DNSSecurity = strings.Join(f[1:], " ") case "enable-cache": p.EnableCache = strings.Join(f[1:], " ") case "enable-dns-express": p.EnableDNSExpress = strings.Join(f[1:], " ") case "enable-dns-firewall": p.EnableDNSFirewall = strings.Join(f[1:], " ") case "enable-dnssec": p.EnableDNSSec = strings.Join(f[1:], " ") case "enable-gtm": p.EnableGTM = strings.Join(f[1:], " ") case "enable-hardware-query-validation": p.EnableHardwareQueryValidation = strings.Join(f[1:], " ") case "enable-hardware-response-cache": p.EnableHardwareResponseCache = strings.Join(f[1:], " ") case "enable-logging": p.EnableLogging = strings.Join(f[1:], " ") case "enable-rapid-response": p.EnableRapidResponse = strings.Join(f[1:], " ") case "log-profile": p.LogProfile = strings.Join(f[1:], " ") case "process-rd": p.ProcessRD = strings.Join(f[1:], " ") case "process-xfr": p.ProcessXFR = strings.Join(f[1:], " ") case "rapid-response-last-action": p.RapidResponseLastAction = strings.Join(f[1:], " ") case "unhandled-query-action": p.UnhandledQueryAction = strings.Join(f[1:], " ") case "use-local-bind": p.UseLocalBind = strings.Join(f[1:], " ") } } return p, nil }