Skip to content

Commit

Permalink
Merge pull request #91 from logicmonitor/DEV-166942-SSLExpirationChec…
Browse files Browse the repository at this point in the history
…kAndDatasourceUpdate

SSL expiration check added for website and datasource  documentation update
  • Loading branch information
lm-madhvi authored May 28, 2024
2 parents 3f8f2ad + 1dd7810 commit af7d630
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 19 deletions.
12 changes: 7 additions & 5 deletions examples/datasource/datasource.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
resource "logicmonitor_datasource" "my_datasource"{
collect_interval = 100
applies_to = data.logicmonitor_device.my_devices.id
applies_to = "system.deviceId == \"22\""
description = "test"
collect_method = "aggregate"
collect_method = "script"
eri_discovery_interval = 1
enable_eri_discovery = true
name = "Amazon Website test"
data_points = [{
name = "CallCountTotal_mean8"
Expand All @@ -24,9 +26,9 @@ resource "logicmonitor_datasource" "my_datasource"{
post_processor_param = "{\"version\":\"1.0\",\"expression\":{\"funcName\":\"mean\",\"dataSourceName\":\"AWS_Cognito_GlobalAPICallStats\",\"dataPointName\":\"CallCountTotal\"},\"dataLack\":\"ignore\"}"
}]
display_name = "Testdemo"
collector_attribute = [{
name = "aggregate"
}]
collector_attribute {
name = "script"
}
}

data "logicmonitor_datasource" "my_datasource" {
Expand Down
12 changes: 7 additions & 5 deletions examples/datasource/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

resource "logicmonitor_datasource" "my_datasource"{
collect_interval = 100
applies_to = data.logicmonitor_device.my_devices.id
applies_to = "system.deviceId == \"22\""
description = "test"
collect_method = "aggregate"
collect_method = "script"
eri_discovery_interval = 1
enable_eri_discovery = true
name = "Amazon Website test"
data_points = [{
name = "CallCountTotal_mean8"
Expand All @@ -26,7 +28,7 @@ resource "logicmonitor_datasource" "my_datasource"{
post_processor_param = "{\"version\":\"1.0\",\"expression\":{\"funcName\":\"mean\",\"dataSourceName\":\"AWS_Cognito_GlobalAPICallStats\",\"dataPointName\":\"CallCountTotal\"},\"dataLack\":\"ignore\"}"
}]
display_name = "Testdemo"
collector_attribute = [{
name = "aggregate"
}]
collector_attribute {
name = "script"
}
}
12 changes: 12 additions & 0 deletions examples/website/datasource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ resource "logicmonitor_website" "my_website"{
disable_alerting = true
stop_monitoring = true
user_permission = "string"
test_location = [
{
all = false
collector_ids = [1, 2, 3]
collectors = null
smg_ids = [85, 90]
}
]
group_id = 8
individual_sm_alert_enable = false
steps = [
Expand Down Expand Up @@ -53,6 +61,10 @@ resource "logicmonitor_website" "my_website"{
use_default_location_setting = false
use_default_alert_setting = true
individual_alert_level = "warn"
trigger_s_s_l_expiration_alert = true
trigger_s_s_l_status_alert = true
ignore_s_s_l = false
alert_expr = "< 100"
}
data "logicmonitor_website" "my_website" {
filter = "description~\"website test\""
Expand Down
4 changes: 4 additions & 0 deletions examples/website/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,8 @@ resource "logicmonitor_website" "my_website"{
use_default_location_setting = false
use_default_alert_setting = true
individual_alert_level = "warn"
trigger_s_s_l_expiration_alert = true
trigger_s_s_l_status_alert = true
ignore_s_s_l = false
alert_expr = "< 100"
}
60 changes: 60 additions & 0 deletions logicmonitor/schemata/website_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import (

func WebsiteSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"alert_expr": {
Type: schema.TypeString,
Optional: true,
},

"description": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -44,6 +49,11 @@ func WebsiteSchema() map[string]*schema.Schema {
Computed: true,
},

"ignore_s_s_l": {
Type: schema.TypeBool,
Optional: true,
},

"individual_alert_level": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -125,6 +135,16 @@ func WebsiteSchema() map[string]*schema.Schema {
Optional: true,
},

"trigger_s_s_l_expiration_alert": {
Type: schema.TypeBool,
Optional: true,
},

"trigger_s_s_l_status_alert": {
Type: schema.TypeBool,
Optional: true,
},

"type": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -153,6 +173,11 @@ func WebsiteSchema() map[string]*schema.Schema {
// Only difference between this and WebsiteSchema() are the computabilty of the id field and the inclusion of a filter field for datasources
func DataSourceWebsiteSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"alert_expr": {
Type: schema.TypeString,
Optional: true,
},

"description": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -189,6 +214,11 @@ func DataSourceWebsiteSchema() map[string]*schema.Schema {
Optional: true,
},

"ignore_s_s_l": {
Type: schema.TypeBool,
Optional: true,
},

"individual_alert_level": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -269,6 +299,16 @@ func DataSourceWebsiteSchema() map[string]*schema.Schema {
Optional: true,
},

"trigger_s_s_l_expiration_alert": {
Type: schema.TypeBool,
Optional: true,
},

"trigger_s_s_l_status_alert": {
Type: schema.TypeBool,
Optional: true,
},

"type": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -297,13 +337,15 @@ func DataSourceWebsiteSchema() map[string]*schema.Schema {
}

func SetWebsiteResourceData(d *schema.ResourceData, m *models.Website) {
d.Set("alert_expr", m.AlertExpr)
d.Set("description", m.Description)
d.Set("disable_alerting", m.DisableAlerting)
d.Set("domain", m.Domain)
d.Set("global_sm_alert_cond", m.GlobalSmAlertCond)
d.Set("group_id", m.GroupID)
d.Set("host", m.Host)
d.Set("id", strconv.Itoa(int(m.ID)))
d.Set("ignore_s_s_l", m.IgnoreSSL)
d.Set("individual_alert_level", m.IndividualAlertLevel)
d.Set("individual_sm_alert_enable", m.IndividualSmAlertEnable)
d.Set("is_internal", m.IsInternal)
Expand All @@ -318,6 +360,8 @@ func SetWebsiteResourceData(d *schema.ResourceData, m *models.Website) {
d.Set("template", m.Template)
d.Set("test_location", SetWebsiteLocationSubResourceData([]*models.WebsiteLocation{m.TestLocation}))
d.Set("transition", m.Transition)
d.Set("trigger_s_s_l_expiration_alert", m.TriggerSSLExpirationAlert)
d.Set("trigger_s_s_l_status_alert", m.TriggerSSLStatusAlert)
d.Set("type", m.Type)
d.Set("use_default_alert_setting", m.UseDefaultAlertSetting)
d.Set("use_default_location_setting", m.UseDefaultLocationSetting)
Expand All @@ -328,13 +372,15 @@ func SetWebsiteSubResourceData(m []*models.Website) (d []*map[string]interface{}
for _, website := range m {
if website != nil {
properties := make(map[string]interface{})
properties["alert_expr"] = website.AlertExpr
properties["description"] = website.Description
properties["disable_alerting"] = website.DisableAlerting
properties["domain"] = website.Domain
properties["global_sm_alert_cond"] = website.GlobalSmAlertCond
properties["group_id"] = website.GroupID
properties["host"] = website.Host
properties["id"] = website.ID
properties["ignore_s_s_l"] = website.IgnoreSSL
properties["individual_alert_level"] = website.IndividualAlertLevel
properties["individual_sm_alert_enable"] = website.IndividualSmAlertEnable
properties["is_internal"] = website.IsInternal
Expand All @@ -349,6 +395,8 @@ func SetWebsiteSubResourceData(m []*models.Website) (d []*map[string]interface{}
properties["template"] = website.Template
properties["test_location"] = SetWebsiteLocationSubResourceData([]*models.WebsiteLocation{website.TestLocation})
properties["transition"] = website.Transition
properties["trigger_s_s_l_expiration_alert"] = website.TriggerSSLExpirationAlert
properties["trigger_s_s_l_status_alert"] = website.TriggerSSLStatusAlert
properties["type"] = website.Type
properties["use_default_alert_setting"] = website.UseDefaultAlertSetting
properties["use_default_location_setting"] = website.UseDefaultLocationSetting
Expand All @@ -360,13 +408,15 @@ func SetWebsiteSubResourceData(m []*models.Website) (d []*map[string]interface{}
}

func WebsiteModel(d *schema.ResourceData) *models.Website {
alertExpr := d.Get("alert_expr").(string)
description := d.Get("description").(string)
disableAlerting := d.Get("disable_alerting").(bool)
domain := d.Get("domain").(string)
globalSmAlertCond := int32(d.Get("global_sm_alert_cond").(int))
groupID := int32(d.Get("group_id").(int))
host := d.Get("host").(string)
id, _ := strconv.Atoi(d.Get("id").(string))
ignoreSSL := d.Get("ignore_s_s_l").(bool)
individualAlertLevel := d.Get("individual_alert_level").(string)
individualSmAlertEnable := d.Get("individual_sm_alert_enable").(bool)
isInternal := d.Get("is_internal").(bool)
Expand All @@ -378,19 +428,23 @@ func WebsiteModel(d *schema.ResourceData) *models.Website {
template := d.Get("template")
testLocation := utils.GetPropFromLocationMap(d, "test_location")
transition := int32(d.Get("transition").(int))
triggerSSLExpirationAlert := d.Get("trigger_s_s_l_expiration_alert").(bool)
triggerSSLStatusAlert := d.Get("trigger_s_s_l_status_alert").(bool)
typeVar := d.Get("type").(string)
useDefaultAlertSetting := d.Get("use_default_alert_setting").(bool)
useDefaultLocationSetting := d.Get("use_default_location_setting").(bool)
userPermission := d.Get("user_permission").(string)

return &models.Website {
AlertExpr: alertExpr,
Description: description,
DisableAlerting: disableAlerting,
Domain: domain,
GlobalSmAlertCond: globalSmAlertCond,
GroupID: groupID,
Host: host,
ID: int32(id),
IgnoreSSL: ignoreSSL,
IndividualAlertLevel: individualAlertLevel,
IndividualSmAlertEnable: individualSmAlertEnable,
IsInternal: isInternal,
Expand All @@ -402,6 +456,8 @@ func WebsiteModel(d *schema.ResourceData) *models.Website {
Template: template,
TestLocation: testLocation,
Transition: transition,
TriggerSSLExpirationAlert: triggerSSLExpirationAlert,
TriggerSSLStatusAlert: triggerSSLStatusAlert,
Type: &typeVar,
UseDefaultAlertSetting: useDefaultAlertSetting,
UseDefaultLocationSetting: useDefaultLocationSetting,
Expand All @@ -410,13 +466,15 @@ func WebsiteModel(d *schema.ResourceData) *models.Website {
}
func GetWebsitePropertyFields() (t []string) {
return []string{
"alert_expr",
"description",
"disable_alerting",
"domain",
"global_sm_alert_cond",
"group_id",
"host",
"id",
"ignore_s_s_l",
"individual_alert_level",
"individual_sm_alert_enable",
"is_internal",
Expand All @@ -428,6 +486,8 @@ func GetWebsitePropertyFields() (t []string) {
"template",
"test_location",
"transition",
"trigger_s_s_l_expiration_alert",
"trigger_s_s_l_status_alert",
"type",
"use_default_alert_setting",
"use_default_location_setting",
Expand Down
1 change: 1 addition & 0 deletions models/datasource.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions models/website.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions website/docs/index.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ resource "logicmonitor_datasource" "my_datasource" {
collect_interval = 100
applies_to = "system.deviceId == \"22\""
description = "test"
collect_method = "aggregate"
collect_method = "script"
eri_discovery_interval = 1
enable_eri_discovery = true
name = "Amazon Website test"
data_points = [{
name = "CallCountTotal_mean8"
Expand All @@ -138,9 +140,9 @@ resource "logicmonitor_datasource" "my_datasource" {
post_processor_param = "{\"version\":\"1.0\",\"expression\":{\"funcName\":\"mean\",\"dataSourceName\":\"AWS_Cognito_GlobalAPICallStats\",\"dataPointName\":\"CallCountTotal\"},\"dataLack\":\"ignore\"}"
}]
display_name = "Test demo"
collector_attribute = [{
name = "aggregate"
}]
collector_attribute {
name = "script"
}
}
```

Expand Down Expand Up @@ -294,6 +296,10 @@ resource "logicmonitor_website" "my_website" {
use_default_location_setting = false
use_default_alert_setting = true
individual_alert_level = "warn"
trigger_s_s_l_expiration_alert = true
trigger_s_s_l_status_alert = true
ignore_s_s_l = false
alert_expr = "< 100"
}
```

Expand Down
10 changes: 5 additions & 5 deletions website/docs/r/datasource.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ Provides a LogicMonitor datasource resource. This can be used to create and mana
```hcl
# Create a LogicMonitor datasource
resource "logicmonitor_datasource" "my_datasource" {
applies_to = "system.deviceId == \"22\"
applies_to = "system.deviceId == \"22\""
collect_interval = 100
collect_method = ""
collector_attribute = [{
name = "aggregate"
}]
collect_method = "script"
collector_attribute {
name = "script"
}
data_points = [
{
name = "CallCountTotal_mean8"
Expand Down
Loading

0 comments on commit af7d630

Please sign in to comment.