From 0ce1f2b7263f91a62dec31c98040893fd4885ab2 Mon Sep 17 00:00:00 2001 From: Madhvi Date: Thu, 11 Jul 2024 11:32:27 +0530 Subject: [PATCH] Use Default Root and Website schema parameter fix --- logicmonitor/schemata/web_check_step_schema.go | 4 ++-- logicmonitor/schemata/website_schema.go | 15 +++++++++++++++ logicmonitor/utils/helper_functions.go | 2 +- models/web_check_step.go | 17 ++++++++++++++++- models/website.go | 4 ++++ website/docs/index.markdown | 1 + 6 files changed, 39 insertions(+), 4 deletions(-) diff --git a/logicmonitor/schemata/web_check_step_schema.go b/logicmonitor/schemata/web_check_step_schema.go index 72928bd..58f34bd 100644 --- a/logicmonitor/schemata/web_check_step_schema.go +++ b/logicmonitor/schemata/web_check_step_schema.go @@ -143,7 +143,7 @@ func WebCheckStepSchema() map[string]*schema.Schema { "use_default_root": { Type: schema.TypeBool, - Optional: true, + Required: true, }, } @@ -247,7 +247,7 @@ func WebCheckStepModel(d map[string]interface{}) *models.WebCheckStep { Timeout: timeout, Type: typeVar, URL: url, - UseDefaultRoot: useDefaultRoot, + UseDefaultRoot: &useDefaultRoot, } } diff --git a/logicmonitor/schemata/website_schema.go b/logicmonitor/schemata/website_schema.go index 78974df..933c8c1 100644 --- a/logicmonitor/schemata/website_schema.go +++ b/logicmonitor/schemata/website_schema.go @@ -89,6 +89,11 @@ func WebsiteSchema() map[string]*schema.Schema { Optional: true, }, + "schema": { + Type: schema.TypeString, + Optional: true, + }, + "status": { Type: schema.TypeString, Computed: true, @@ -254,6 +259,11 @@ func DataSourceWebsiteSchema() map[string]*schema.Schema { Optional: true, }, + "schema": { + Type: schema.TypeString, + Optional: true, + }, + "status": { Type: schema.TypeString, Optional: true, @@ -353,6 +363,7 @@ func SetWebsiteResourceData(d *schema.ResourceData, m *models.Website) { d.Set("name", m.Name) d.Set("overall_alert_level", m.OverallAlertLevel) d.Set("polling_interval", m.PollingInterval) + d.Set("schema", m.Schema) d.Set("status", m.Status) d.Set("steps", SetWebCheckStepSubResourceData(m.Steps)) d.Set("stop_monitoring", m.StopMonitoring) @@ -388,6 +399,7 @@ func SetWebsiteSubResourceData(m []*models.Website) (d []*map[string]interface{} properties["name"] = website.Name properties["overall_alert_level"] = website.OverallAlertLevel properties["polling_interval"] = website.PollingInterval + properties["schema"] = website.Schema properties["status"] = website.Status properties["steps"] = SetWebCheckStepSubResourceData(website.Steps) properties["stop_monitoring"] = website.StopMonitoring @@ -423,6 +435,7 @@ func WebsiteModel(d *schema.ResourceData) *models.Website { name := d.Get("name").(string) overallAlertLevel := d.Get("overall_alert_level").(string) pollingInterval := int32(d.Get("polling_interval").(int)) + schema := d.Get("schema").(string) steps := utils.GetPropFromSteps(d, "steps") stopMonitoring := d.Get("stop_monitoring").(bool) template := d.Get("template") @@ -451,6 +464,7 @@ func WebsiteModel(d *schema.ResourceData) *models.Website { Name: &name, OverallAlertLevel: overallAlertLevel, PollingInterval: pollingInterval, + Schema: schema, Steps: steps, StopMonitoring: stopMonitoring, Template: template, @@ -481,6 +495,7 @@ func GetWebsitePropertyFields() (t []string) { "name", "overall_alert_level", "polling_interval", + "schema", "steps", "stop_monitoring", "template", diff --git a/logicmonitor/utils/helper_functions.go b/logicmonitor/utils/helper_functions.go index 01ec03d..cab05fa 100644 --- a/logicmonitor/utils/helper_functions.go +++ b/logicmonitor/utils/helper_functions.go @@ -383,7 +383,7 @@ func getPropFromStepsInterface(r interface{}) (t []*models.WebCheckStep) { Enable: enable, Name: name, Timeout: timeout, - UseDefaultRoot: useDefaultRoot, + UseDefaultRoot: &useDefaultRoot, PostDataEditType: postDataEditType, FullpageLoad: fullpageLoad, RequireAuth: requireAuth, diff --git a/models/web_check_step.go b/models/web_check_step.go index ada0899..7b7414c 100644 --- a/models/web_check_step.go +++ b/models/web_check_step.go @@ -11,6 +11,7 @@ import ( "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" "github.com/go-openapi/swag" + "github.com/go-openapi/validate" ) // WebCheckStep web check step @@ -119,7 +120,8 @@ type WebCheckStep struct { // true | falseCheck if using the default root // Example: true - UseDefaultRoot bool `json:"useDefaultRoot,omitempty"` + // Required: true + UseDefaultRoot *bool `json:"useDefaultRoot"` } // Validate validates this web check step @@ -130,6 +132,10 @@ func (m *WebCheckStep) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateUseDefaultRoot(formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } @@ -155,6 +161,15 @@ func (m *WebCheckStep) validateAuth(formats strfmt.Registry) error { return nil } +func (m *WebCheckStep) validateUseDefaultRoot(formats strfmt.Registry) error { + + if err := validate.Required("useDefaultRoot", "body", m.UseDefaultRoot); err != nil { + return err + } + + return nil +} + // ContextValidate validate this web check step based on the context it is used func (m *WebCheckStep) ContextValidate(ctx context.Context, formats strfmt.Registry) error { var res []error diff --git a/models/website.go b/models/website.go index 279f8b6..7fc9021 100644 --- a/models/website.go +++ b/models/website.go @@ -95,6 +95,10 @@ type Website struct { // Example: 5 PollingInterval int32 `json:"pollingInterval,omitempty"` + // The scheme or protocol associated with the URL to check. Acceptable values are: http, https + // Example: https + Schema string `json:"schema,omitempty"` + // Whether is the website dead (the collector is down) or not // Read Only: true Status string `json:"status,omitempty"` diff --git a/website/docs/index.markdown b/website/docs/index.markdown index 157a53d..0c948a6 100644 --- a/website/docs/index.markdown +++ b/website/docs/index.markdown @@ -266,6 +266,7 @@ resource "logicmonitor_website" "my_website" { type = "pingcheck" host = "google.com" overall_alert_level = "warn" + schema = "http" polling_interval = 5 description = "website test" disable_alerting = true