aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.example.yaml3
-rw-r--r--internal/config/config.go1
-rw-r--r--internal/monitor/http.go8
3 files changed, 11 insertions, 1 deletions
diff --git a/config.example.yaml b/config.example.yaml
index 32229d0..50c116b 100644
--- a/config.example.yaml
+++ b/config.example.yaml
@@ -85,6 +85,7 @@ groups:
expected_status: 200
expected_content: '"status":"ok"' # Verify JSON response contains expected data
method: GET
+ # user_agent: "Mozilla/5.0 (compatible; StatusMonitor/1.0)" # Custom User-Agent (bypass bot detection)
# headers:
# Authorization: "Bearer token"
@@ -169,6 +170,8 @@ incidents:
# expected_status: int - Expected HTTP status code (default: 200)
# expected_content: string - Text that must be present in response body
# method: string - HTTP method (default: GET)
+# user_agent: string - Custom User-Agent header (default: "Kaze-Monitor/1.0")
+# Useful for bypassing bot detection (e.g., Cloudflare)
# headers: map[string]string - Custom headers to send
# body: string - Request body for POST/PUT/PATCH
# verify_ssl: bool - Verify SSL certificate (default: true, or group default)
diff --git a/internal/config/config.go b/internal/config/config.go
index 81f745c..4d428fc 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -87,6 +87,7 @@ type MonitorConfig struct {
RoundResponseTime bool `yaml:"round_response_time,omitempty"` // Round response time to nearest second
RoundUptime bool `yaml:"round_uptime,omitempty"` // Round uptime percentage (e.g., 99.99% → 100%)
Method string `yaml:"method,omitempty"`
+ UserAgent string `yaml:"user_agent,omitempty"` // Custom User-Agent header (default: "Kaze-Monitor/1.0")
Headers map[string]string `yaml:"headers,omitempty"`
Body string `yaml:"body,omitempty"`
}
diff --git a/internal/monitor/http.go b/internal/monitor/http.go
index 00e3e0a..ddf8641 100644
--- a/internal/monitor/http.go
+++ b/internal/monitor/http.go
@@ -22,6 +22,7 @@ type HTTPMonitor struct {
timeout time.Duration
retries int
method string
+ userAgent string
headers map[string]string
body string
expectedStatus int
@@ -88,6 +89,7 @@ func NewHTTPMonitor(cfg config.MonitorConfig) (*HTTPMonitor, error) {
timeout: cfg.Timeout.Duration,
retries: cfg.Retries,
method: cfg.Method,
+ userAgent: cfg.UserAgent,
headers: cfg.Headers,
body: cfg.Body,
expectedStatus: cfg.ExpectedStatus,
@@ -161,7 +163,11 @@ func (m *HTTPMonitor) Check(ctx context.Context) *Result {
}
// Set headers
- req.Header.Set("User-Agent", "Kaze-Monitor/1.0")
+ userAgent := m.userAgent
+ if userAgent == "" {
+ userAgent = "Kaze-Monitor/1.0"
+ }
+ req.Header.Set("User-Agent", userAgent)
for key, value := range m.headers {
req.Header.Set(key, value)
}