Skip to content

feat: add icmp and browser monitor API support to kibana rest client #771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 58 additions & 1 deletion libs/go-kibana-rest/kbapi/api.kibana_synthetics.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ const (

ModeAll HttpMonitorMode = "all"
ModeAny = "any"

ScreenshotOn ScreenshotOption = "on"
ScreenshotOff = "off"
ScreenshotOnlyOfFailures = "only-on-failure"
)

var plMu sync.Mutex
Expand All @@ -65,6 +69,7 @@ type MonitorType string
type MonitorLocation string
type MonitorSchedule int
type HttpMonitorMode string
type ScreenshotOption string

type JsonObject map[string]interface{}

Expand All @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
125 changes: 125 additions & 0 deletions libs/go-kibana-rest/kbapi/api.kibana_synthetics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -298,6 +421,8 @@ func updateDueToKibanaAPIDiff(m *SyntheticsMonitor) {
m.CheckRequestHeaders = nil
m.CheckSend = ""
m.CheckReceive = ""
m.InlineScript = ""
m.SyntheticsArgs = nil
}

func (s *KBAPITestSuite) TestKibanaSyntheticsPrivateLocationAPI() {
Expand Down
Loading