diff --git a/libs/go-kibana-rest/kbapi/api.kibana_synthetics.go b/libs/go-kibana-rest/kbapi/api.kibana_synthetics.go index 54a2f3404..d4cb97855 100644 --- a/libs/go-kibana-rest/kbapi/api.kibana_synthetics.go +++ b/libs/go-kibana-rest/kbapi/api.kibana_synthetics.go @@ -46,6 +46,10 @@ const ( ModeAll HttpMonitorMode = "all" ModeAny = "any" + + ScreenshotOn ScreenshotOption = "on" + ScreenshotOff = "off" + ScreenshotOnlyOfFailures = "only-on-failure" ) var plMu sync.Mutex @@ -65,6 +69,7 @@ type MonitorType string type MonitorLocation string type MonitorSchedule int type HttpMonitorMode string +type ScreenshotOption string type JsonObject map[string]interface{} @@ -90,6 +95,19 @@ type MonitorAlertConfig struct { Tls *SyntheticsStatusConfig `json:"tls,omitempty"` } +type ICMPMonitorFields struct { + Host string `json:"host"` + Wait string `json:"wait,omitempty"` +} + +type BrowserMonitorFields struct { + InlineScript string `json:"inline_script"` + Screenshots ScreenshotOption `json:"screenshots,omitempty"` + SyntheticsArgs []string `json:"synthetics_args,omitempty"` + IgnoreHttpsErrors *bool `json:"ignore_https_errors,omitempty"` + PlaywrightOptions JsonObject `json:"playwright_options,omitempty"` +} + type TCPMonitorFields struct { Host string `json:"host"` SslVerificationMode string `json:"ssl.verification_mode,omitempty"` @@ -207,11 +225,20 @@ type SyntheticsMonitor struct { ProxyUrl string `json:"proxy_url,omitempty"` SslVerificationMode string `json:"ssl.verification_mode"` SslSupportedProtocols []string `json:"ssl.supported_protocols"` + //tcp and icmp + Host string `json:"host,omitempty"` //tcp - Host string `json:"host,omitempty"` ProxyUseLocalResolver *bool `json:"proxy_use_local_resolver,omitempty"` CheckSend string `json:"check.send,omitempty"` CheckReceive string `json:"check.receive,omitempty"` + //icmp + Wait json.Number `json:"wait,omitempty"` + //browser + Screenshots string `json:"screenshots,omitempty"` + IgnoreHttpsErrors *bool `json:"ignore_https_errors,omitempty"` + InlineScript string `json:"inline_script"` + SyntheticsArgs []string `json:"synthetics_args,omitempty"` + PlaywrightOptions JsonObject `json:"playwright_options,omitempty"` } type MonitorTypeConfig struct { @@ -248,6 +275,36 @@ func (f TCPMonitorFields) APIRequest(config SyntheticsMonitorConfig) interface{} } } +func (f ICMPMonitorFields) APIRequest(config SyntheticsMonitorConfig) interface{} { + + mType := MonitorTypeConfig{Type: Icmp} + + return struct { + SyntheticsMonitorConfig + MonitorTypeConfig + ICMPMonitorFields + }{ + config, + mType, + f, + } +} + +func (f BrowserMonitorFields) APIRequest(config SyntheticsMonitorConfig) interface{} { + + mType := MonitorTypeConfig{Type: Browser} + + return struct { + SyntheticsMonitorConfig + MonitorTypeConfig + BrowserMonitorFields + }{ + config, + mType, + f, + } +} + type KibanaSyntheticsMonitorAdd func(ctx context.Context, config SyntheticsMonitorConfig, fields MonitorFields, namespace string) (*SyntheticsMonitor, error) type KibanaSyntheticsMonitorUpdate func(ctx context.Context, id MonitorID, config SyntheticsMonitorConfig, fields MonitorFields, namespace string) (*SyntheticsMonitor, error) diff --git a/libs/go-kibana-rest/kbapi/api.kibana_synthetics_test.go b/libs/go-kibana-rest/kbapi/api.kibana_synthetics_test.go index 351c39e5e..fd527cf17 100644 --- a/libs/go-kibana-rest/kbapi/api.kibana_synthetics_test.go +++ b/libs/go-kibana-rest/kbapi/api.kibana_synthetics_test.go @@ -236,6 +236,129 @@ func (s *KBAPITestSuite) TestKibanaSyntheticsMonitorAPI() { }, }, }, + { + name: "bare minimum icmp monitor", + input: TestConfig{ + config: SyntheticsMonitorConfig{ + Name: fmt.Sprintf("test synthetics icmp monitor %s", testUuid), + PrivateLocations: []string{location.Label}, + }, + fields: ICMPMonitorFields{ + Host: "localhost", + }, + }, + update: TestConfig{ + config: SyntheticsMonitorConfig{}, + fields: ICMPMonitorFields{ + Host: "127.0.0.1", + }, + }, + }, + { + name: "all fields icmp monitor", + input: TestConfig{ + config: SyntheticsMonitorConfig{ + Name: fmt.Sprintf("test all fields icmp monitor %s", testUuid), + Schedule: Every10Minutes, + PrivateLocations: []string{location.Label}, + Enabled: f, + Tags: []string{"aaa", "bbb"}, + Alert: &MonitorAlertConfig{ + Status: &SyntheticsStatusConfig{Enabled: t}, + Tls: &SyntheticsStatusConfig{Enabled: f}, + }, + APMServiceName: "APMServiceName", + TimeoutSeconds: 42, + Namespace: space, + Params: map[string]interface{}{ + "param1": "some-params", + "my_url": "http://localhost:8080", + }, + RetestOnFailure: f, + }, + fields: ICMPMonitorFields{ + Host: "localhost", + Wait: "10", + }, + }, + update: TestConfig{ + config: SyntheticsMonitorConfig{ + Name: fmt.Sprintf("update all fields icmp monitor %s", testUuid), + Schedule: Every30Minutes, + }, + fields: ICMPMonitorFields{ + Host: "127.0.0.1", + Wait: "5", + }, + }, + }, + { + name: "bare minimum browser monitor", + input: TestConfig{ + config: SyntheticsMonitorConfig{ + Name: fmt.Sprintf("test synthetics browser monitor %s", testUuid), + PrivateLocations: []string{location.Label}, + }, + fields: BrowserMonitorFields{ + InlineScript: `step('Go to https://google.com.co', () => page.goto('https://www.google.com'))`, + }, + }, + update: TestConfig{ + config: SyntheticsMonitorConfig{ + Name: fmt.Sprintf("test synthetics browser monitor %s", testUuid), + }, + fields: BrowserMonitorFields{ + InlineScript: `step('Go to https://www.google.de', () => page.goto('https://www.google.de'))`, + }, + }, + }, + { + name: "all fields browser monitor", + input: TestConfig{ + config: SyntheticsMonitorConfig{ + Name: fmt.Sprintf("test all fields browser monitor %s", testUuid), + Schedule: Every10Minutes, + PrivateLocations: []string{location.Label}, + Enabled: f, + Tags: []string{"aaa", "bbb"}, + Alert: &MonitorAlertConfig{ + Status: &SyntheticsStatusConfig{Enabled: t}, + Tls: &SyntheticsStatusConfig{Enabled: f}, + }, + APMServiceName: "APMServiceName", + TimeoutSeconds: 42, + Namespace: space, + Params: map[string]interface{}{ + "param1": "some-params", + "my_url": "http://localhost:8080", + }, + RetestOnFailure: f, + }, + fields: BrowserMonitorFields{ + InlineScript: `step('Go to https://google.com.co', () => page.goto('https://www.google.com'))`, + Screenshots: ScreenshotOn, + SyntheticsArgs: []string{"a", "b"}, + IgnoreHttpsErrors: t, + PlaywrightOptions: map[string]interface{}{ + "ignoreHTTPSErrors": false, + "httpCredentials": map[string]interface{}{ + "username": "test", + "password": "test", + }, + }, + }, + }, + update: TestConfig{ + config: SyntheticsMonitorConfig{ + Name: fmt.Sprintf("update all fields browser monitor %s", testUuid), + Schedule: Every30Minutes, + }, + fields: BrowserMonitorFields{ + InlineScript: `step('Go to https://google.de', () => page.goto('https://www.google.de'))`, + Screenshots: ScreenshotOff, + }, + }, + }, } for _, tc := range testCases { @@ -298,6 +421,8 @@ func updateDueToKibanaAPIDiff(m *SyntheticsMonitor) { m.CheckRequestHeaders = nil m.CheckSend = "" m.CheckReceive = "" + m.InlineScript = "" + m.SyntheticsArgs = nil } func (s *KBAPITestSuite) TestKibanaSyntheticsPrivateLocationAPI() {