package pkg import ( "errors" "strconv" "strings" ) type DiameterProfile struct { ProfileCommon ConnectionPrime string `json:"connecting_prime"` DestinationRealm string `json:"destination_realm"` HandshakeTimeout int `json:"handshake_timeout"` HostIPRewrite string `json:"host_ip_rewrite"` MaxRetransmitAttempts int `json:"max_retransmit_attempts"` MaxWatchdogFailure int `json:"max_watchdog_failure"` OriginHostToClient string `json:"origin_host_to_client"` OriginHostToServer string `json:"origin_host_to_server"` OriginRealmToClient string `json:"origin_realm_to_client"` OriginRealmToServer string `json:"origin_realm_to_server"` ParentAVP string `json:"parent_avp"` PersistAVP string `json:"persist_avp"` ResetOnTimeout string `json:"reset_on_timeout"` RetransmitTimeout int `json:"retransmit_timeout"` WatchdogTimeout int `json:"watchdog_timeout"` } func ParseDiameterProfile(raw string) (*DiameterProfile, error) { p := new(DiameterProfile) split := strings.Split(raw, "\n") if !strings.Contains(split[0], "ltm profile diameter") { return nil, errors.New("not a diameter profile") } p.ProfileCommon = parseCommon(raw) for _, line := range split { f := strings.Fields(line) switch strings.ToLower(f[0]) { case "connection-prime": p.ConnectionPrime = strings.Join(f[1:], " ") case "destination-realm": p.DestinationRealm = strings.Join(f[1:], " ") case "handshake-timeout": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.HandshakeTimeout = i case "host-ip-rewrite": p.HostIPRewrite = strings.Join(f[1:], " ") case "max-retransmit-attempts": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.MaxRetransmitAttempts = i case "max-watchdog-failure": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.MaxWatchdogFailure = i case "origin-host-to-client": p.OriginHostToClient = strings.Join(f[1:], " ") case "origin-host-to-server": p.OriginHostToServer = strings.Join(f[1:], " ") case "origin-realm-to-client": p.OriginRealmToClient = strings.Join(f[1:], " ") case "origin-realm-to-server": p.OriginRealmToServer = strings.Join(f[1:], " ") case "parent-avp": p.ParentAVP = strings.Join(f[1:], " ") case "persist-avp": p.PersistAVP = strings.Join(f[1:], " ") case "reset-on-timeout": p.ResetOnTimeout = strings.Join(f[1:], " ") case "retransmit-timeout": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.RetransmitTimeout = i case "watchdog-timeout": i, err := strconv.Atoi(f[1]) if err != nil { log.WithField("data", f[1]).Error(err.Error()) return nil, err } p.WatchdogTimeout = i } } return p, nil }