diff --git a/agent/structs/check_definition.go b/agent/structs/check_definition.go index 9c0f007975..434f35e65f 100644 --- a/agent/structs/check_definition.go +++ b/agent/structs/check_definition.go @@ -76,9 +76,17 @@ func (t *CheckDefinition) UnmarshalJSON(data []byte) (err error) { }{ Alias: (*Alias)(t), } - // Set default values - aux.H2PingUseTLS = true - aux.H2PingUseTLSSnake = true + + // Preevaluate struct values to determine where to set defaults + if err = lib.UnmarshalJSON(data, &aux); err != nil { + return err + } + // Set defaults + if aux.H2PING != "" { + aux.H2PingUseTLS = true + aux.H2PingUseTLSSnake = true + } + if err = lib.UnmarshalJSON(data, &aux); err != nil { return err } @@ -108,14 +116,10 @@ func (t *CheckDefinition) UnmarshalJSON(data []byte) (err error) { if t.ServiceID == "" { t.ServiceID = aux.ServiceIDSnake } - if !aux.H2PingUseTLSSnake { + + if (aux.H2PING != "" && !aux.H2PingUseTLSSnake) || (aux.H2PING == "" && aux.H2PingUseTLSSnake) { t.H2PingUseTLS = aux.H2PingUseTLSSnake } - // unset default values if it is not an H2Ping check - if t.H2PING == "" { - aux.H2PingUseTLS = false - aux.H2PingUseTLSSnake = false - } // Parse special values if aux.Interval != nil { diff --git a/agent/structs/check_type.go b/agent/structs/check_type.go index 13a06e0aab..7f3b583707 100644 --- a/agent/structs/check_type.go +++ b/agent/structs/check_type.go @@ -93,9 +93,16 @@ func (t *CheckType) UnmarshalJSON(data []byte) (err error) { }{ Alias: (*Alias)(t), } - // set default values - aux.H2PingUseTLS = true - aux.H2PingUseTLSSnake = true + + // Preevaluate struct values to determine where to set defaults + if err = lib.UnmarshalJSON(data, aux); err != nil { + return err + } + // Set defaults + if aux.H2PING != "" { + aux.H2PingUseTLS = true + aux.H2PingUseTLSSnake = true + } if err = lib.UnmarshalJSON(data, aux); err != nil { return err @@ -161,14 +168,9 @@ func (t *CheckType) UnmarshalJSON(data []byte) (err error) { t.DeregisterCriticalServiceAfter = time.Duration(v) } } - if !aux.H2PingUseTLSSnake { + if (aux.H2PING != "" && !aux.H2PingUseTLSSnake) || (aux.H2PING == "" && aux.H2PingUseTLSSnake) { t.H2PingUseTLS = aux.H2PingUseTLSSnake } - // unset default values if it is not an H2Ping check - if t.H2PING == "" { - aux.H2PingUseTLS = false - aux.H2PingUseTLSSnake = false - } return nil