Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

fix: availability probes fail with exec.Command fallback for local network

rcourtman25c93bf77f31
diff --git a/frontend-modern/src/components/Workloads/GuestRowCells.tsx b/frontend-modern/src/components/Workloads/GuestRowCells.tsx
index f70287fac0..12189cb5e0 100644
--- a/frontend-modern/src/components/Workloads/GuestRowCells.tsx
+++ b/frontend-modern/src/components/Workloads/GuestRowCells.tsx
@@ -408,7 +408,6 @@ function InfoTooltipCell(props: { value: string; tooltip: string; type: string }
function AvailabilityProbeCell(props: {
presentation: AvailabilityProbePresentation;
}) {
- const tip = useTooltip();
const p = createMemo(() => props.presentation);
const protocolLabel = createMemo(() => {
@@ -417,35 +416,22 @@ function AvailabilityProbeCell(props: {
return spaceIdx > 0 ? method.slice(0, spaceIdx) : method;
});
+ const dotClass = createMemo(() => {
+ const tone = p().toneClassName;
+ if (tone.includes('emerald')) return 'bg-emerald-500';
+ if (tone.includes('red')) return 'bg-red-500';
+ if (tone.includes('amber')) return 'bg-amber-500';
+ return 'bg-slate-400';
+ });
+
return (
- <>
- <span
- class={`inline-flex items-center gap-1 rounded px-1 py-0.5 text-[9px] font-semibold leading-none whitespace-nowrap ${p().toneClassName}`}
- onMouseEnter={tip.onMouseEnter}
- onMouseLeave={tip.onMouseLeave}
- >
- {protocolLabel()}
- <span
- class={`inline-block h-1.5 w-1.5 rounded-full ${
- p().toneClassName.includes('emerald')
- ? 'bg-emerald-500'
- : p().toneClassName.includes('red')
- ? 'bg-red-500'
- : p().toneClassName.includes('amber')
- ? 'bg-amber-500'
- : 'bg-slate-400'
- }`}
- />
- </span>
- <TooltipPortal when={tip.show()} x={tip.pos().x} y={tip.pos().y}>
- <div class="min-w-[140px] max-w-[260px]">
- <div class="font-medium mb-1 text-slate-300 border-b border-border pb-1">
- Availability Probe
- </div>
- <div class="py-0.5 text-xs text-base-content">{p().detailLabel}</div>
- </div>
- </TooltipPortal>
- </>
+ <span
+ class={`inline-flex items-center gap-1 rounded px-1 py-0.5 text-[9px] font-semibold leading-none whitespace-nowrap ${p().toneClassName}`}
+ title={p().rowLabel}
+ >
+ {protocolLabel()}
+ <span class={`inline-block h-1.5 w-1.5 rounded-full ${dotClass()}`} />
+ </span>
);
}
diff --git a/internal/config/availability.go b/internal/config/availability.go
index fa03e86f88..c4977c9830 100644
--- a/internal/config/availability.go
+++ b/internal/config/availability.go
@@ -18,9 +18,10 @@ const (
type AvailabilityProbeProtocol string
const (
- AvailabilityProbeICMP AvailabilityProbeProtocol = "icmp"
- AvailabilityProbeTCP AvailabilityProbeProtocol = "tcp"
- AvailabilityProbeHTTP AvailabilityProbeProtocol = "http"
+ AvailabilityProbeICMP AvailabilityProbeProtocol = "icmp"
+ AvailabilityProbeTCP AvailabilityProbeProtocol = "tcp"
+ AvailabilityProbeHTTP AvailabilityProbeProtocol = "http"
+ AvailabilityProbeHTTPS AvailabilityProbeProtocol = "https"
)
type AvailabilityTargetKind string
@@ -135,7 +136,7 @@ func (t AvailabilityTarget) Validate() error {
if t.Port <= 0 || t.Port > 65535 {
return fmt.Errorf("tcp availability targets require a valid port")
}
- case AvailabilityProbeHTTP:
+ case AvailabilityProbeHTTP, AvailabilityProbeHTTPS:
if t.Port < 0 || t.Port > 65535 {
return fmt.Errorf("http availability target port must be valid")
}
@@ -151,7 +152,7 @@ func (t AvailabilityTarget) Validate() error {
if t.FailureThreshold > 0 && t.FailureThreshold > 10 {
return fmt.Errorf("availability failure threshold must be 10 or less")
}
- if t.Protocol == AvailabilityProbeHTTP {
+ if t.Protocol == AvailabilityProbeHTTP || t.Protocol == AvailabilityProbeHTTPS {
if _, err := t.HTTPURL(); err != nil {
return err
}
@@ -173,7 +174,11 @@ func (t AvailabilityTarget) HTTPURL() (*url.URL, error) {
return nil, fmt.Errorf("availability target address is required")
}
if !strings.Contains(raw, "://") {
- raw = "http://" + raw
+ if t.Protocol == AvailabilityProbeHTTPS {
+ raw = "https://" + raw
+ } else {
+ raw = "http://" + raw
+ }
}
u, err := url.Parse(raw)
if err != nil {
@@ -202,7 +207,7 @@ func NormalizeAvailabilityTarget(target AvailabilityTarget) AvailabilityTarget {
target.Name = strings.TrimSpace(target.Name)
target.TargetKind = AvailabilityTargetKind(strings.ToLower(strings.TrimSpace(string(target.TargetKind))))
target.Protocol = AvailabilityProbeProtocol(strings.ToLower(strings.TrimSpace(string(target.Protocol))))
- if target.Protocol == AvailabilityProbeHTTP {
+ if target.Protocol == AvailabilityProbeHTTP || target.Protocol == AvailabilityProbeHTTPS {
target.Address = strings.TrimSpace(target.Address)
} else {
target.Address = normalizeAvailabilityAddress(target.Address)
diff --git a/internal/monitoring/availability_poller.go b/internal/monitoring/availability_poller.go
index fd5220a93f..a1792e7123 100644
--- a/internal/monitoring/availability_poller.go
+++ b/internal/monitoring/availability_poller.go
@@ -2,6 +2,7 @@ package monitoring
import (
"context"
+ "crypto/tls"
"fmt"
"net"
"net/http"
@@ -317,7 +318,7 @@ func ProbeAvailabilityTarget(ctx context.Context, target config.AvailabilityTarg
return probeICMP(probeCtx, target)
case config.AvailabilityProbeTCP:
return probeTCP(probeCtx, target)
- case config.AvailabilityProbeHTTP:
+ case config.AvailabilityProbeHTTP, config.AvailabilityProbeHTTPS:
return probeHTTP(probeCtx, target, timeout)
default:
return fmt.Errorf("unsupported availability protocol %q", target.Protocol)
@@ -371,16 +372,51 @@ func probeTCP(ctx context.Context, target config.AvailabilityTarget) error {
if host == "" {
return fmt.Errorf("tcp availability target host is required")
}
+ addr := net.JoinHostPort(host, strconv.Itoa(target.Port))
+
dialer := net.Dialer{}
- conn, err := dialer.DialContext(ctx, "tcp", net.JoinHostPort(host, strconv.Itoa(target.Port)))
- if err != nil {
- if ctxErr := ctx.Err(); ctxErr != nil {
- return ctxErr
- }
+ conn, err := dialer.DialContext(ctx, "tcp", addr)
+ if err == nil {
+ conn.Close()
+ return nil
+ }
+ if ctxErr := ctx.Err(); ctxErr != nil {
+ return ctxErr
+ }
+
+ return probeTCPViaSystem(ctx, host, target.Port, target.EffectiveTimeoutMillis())
+}
+
+func probeTCPViaSystem(ctx context.Context, host string, port, timeoutMillis int) error {
+ timeoutSecs := (timeoutMillis + 999) / 1000
+ if timeoutSecs < 1 {
+ timeoutSecs = 1
+ }
+ portStr := strconv.Itoa(port)
+
+ var args []string
+ if runtime.GOOS == "darwin" {
+ args = []string{"-z", "-G", strconv.Itoa(timeoutSecs), host, portStr}
+ } else {
+ args = []string{"-z", "-w", strconv.Itoa(timeoutSecs), host, portStr}
+ }
+
+ cmd := exec.CommandContext(ctx, "nc", args...)
+ output, err := cmd.CombinedOutput()
+ if err == nil {
+ return nil
+ }
+ if ctxErr := ctx.Err(); ctxErr != nil {
+ return ctxErr
+ }
+ details := strings.TrimSpace(string(output))
+ if details == "" {
return fmt.Errorf("tcp probe failed: %w", err)
}
- _ = conn.Close()
- return nil
+ if len(details) > 240 {
+ details = details[:240]
+ }
+ return fmt.Errorf("tcp probe failed: %s", details)
}
func probeHTTP(ctx context.Context, target config.AvailabilityTarget, timeout time.Duration) error {
@@ -388,26 +424,69 @@ func probeHTTP(ctx context.Context, target config.AvailabilityTarget, timeout ti
if err != nil {
return err
}
- client := http.Client{Timeout: timeout}
+ transport := &http.Transport{
+ TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
+ }
+ client := http.Client{Timeout: timeout, Transport: transport}
req, err := http.NewRequestWithContext(ctx, http.MethodHead, u.String(), nil)
if err != nil {
return fmt.Errorf("build http availability request: %w", err)
}
req.Header.Set("User-Agent", "Pulse availability probe")
resp, err := client.Do(req)
+ if err == nil {
+ defer resp.Body.Close()
+ if resp.StatusCode == http.StatusMethodNotAllowed {
+ return probeHTTPGet(ctx, client, u.String())
+ }
+ if resp.StatusCode >= http.StatusInternalServerError {
+ return fmt.Errorf("http probe returned %s", resp.Status)
+ }
+ return nil
+ }
+ if ctxErr := ctx.Err(); ctxErr != nil {
+ return ctxErr
+ }
+
+ return probeHTTPViaSystem(ctx, u.String(), target.EffectiveTimeoutMillis())
+}
+
+func probeHTTPViaSystem(ctx context.Context, rawURL string, timeoutMillis int) error {
+ timeoutSecs := (timeoutMillis + 999) / 1000
+ if timeoutSecs < 1 {
+ timeoutSecs = 1
+ }
+ timeoutStr := strconv.Itoa(timeoutSecs)
+
+ args := []string{
+ "-s", "-o", "/dev/null",
+ "-w", "%{http_code}",
+ "--connect-timeout", timeoutStr,
+ "--max-time", timeoutStr,
+ "-k",
+ rawURL,
+ }
+
+ cmd := exec.CommandContext(ctx, "curl", args...)
+ output, err := cmd.CombinedOutput()
if err != nil {
if ctxErr := ctx.Err(); ctxErr != nil {
return ctxErr
}
- return fmt.Errorf("http probe failed: %w", err)
+ details := strings.TrimSpace(string(output))
+ if len(details) > 240 {
+ details = details[:240]
+ }
+ if details == "" {
+ return fmt.Errorf("http probe failed: %w", err)
+ }
+ return fmt.Errorf("http probe failed: %s", details)
}
- defer resp.Body.Close()
- if resp.StatusCode == http.StatusMethodNotAllowed {
- return probeHTTPGet(ctx, client, u.String())
- }
- if resp.StatusCode >= http.StatusInternalServerError {
- return fmt.Errorf("http probe returned %s", resp.Status)
+ statusCode := strings.TrimSpace(string(output))
+ code, _ := strconv.Atoi(statusCode)
+ if code >= 500 {
+ return fmt.Errorf("http probe returned status %s", statusCode)
}
return nil
}