mirror of
https://github.com/fosrl/newt.git
synced 2026-03-08 03:36:40 +00:00
@@ -61,6 +61,7 @@ type Target struct {
|
|||||||
timer *time.Timer
|
timer *time.Timer
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
|
client *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
// StatusChangeCallback is called when any target's status changes
|
// StatusChangeCallback is called when any target's status changes
|
||||||
@@ -185,6 +186,16 @@ func (m *Monitor) addTargetUnsafe(config Config) error {
|
|||||||
Status: StatusUnknown,
|
Status: StatusUnknown,
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
cancel: cancel,
|
cancel: cancel,
|
||||||
|
client: &http.Client{
|
||||||
|
Transport: &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{
|
||||||
|
// Configure TLS settings based on certificate enforcement
|
||||||
|
InsecureSkipVerify: !m.enforceCert,
|
||||||
|
// Use SNI TLS header if present
|
||||||
|
ServerName: config.TLSServerName,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
m.targets[config.ID] = target
|
m.targets[config.ID] = target
|
||||||
@@ -378,17 +389,6 @@ func (m *Monitor) performHealthCheck(target *Target) {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(target.Config.Timeout)*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(target.Config.Timeout)*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
client := &http.Client{
|
|
||||||
Transport: &http.Transport{
|
|
||||||
TLSClientConfig: &tls.Config{
|
|
||||||
// Configure TLS settings based on certificate enforcement
|
|
||||||
InsecureSkipVerify: !m.enforceCert,
|
|
||||||
// Use SNI TLS header if present
|
|
||||||
ServerName: target.Config.TLSServerName,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, target.Config.Method, url, nil)
|
req, err := http.NewRequestWithContext(ctx, target.Config.Method, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
target.Status = StatusUnhealthy
|
target.Status = StatusUnhealthy
|
||||||
@@ -408,7 +408,7 @@ func (m *Monitor) performHealthCheck(target *Target) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Perform request
|
// Perform request
|
||||||
resp, err := client.Do(req)
|
resp, err := target.client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
target.Status = StatusUnhealthy
|
target.Status = StatusUnhealthy
|
||||||
target.LastError = fmt.Sprintf("request failed: %v", err)
|
target.LastError = fmt.Sprintf("request failed: %v", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user