Skip to content
This repository was archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from sja/application_config_alerts
Browse files Browse the repository at this point in the history
Add Application Alert Config for Log Messages
  • Loading branch information
martinei authored Nov 26, 2020
2 parents 89273fd + 036fb6b commit eb6fffa
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 34 deletions.
96 changes: 62 additions & 34 deletions instana/resource-application-alert-configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const (
ApplicationAlertConfigsFieldRuleAlertType = "rule_alert_type"
ApplicationAlertConfigsFieldRuleMetricName = "rule_metric_name"
ApplicationAlertConfigsFieldRuleAggregation = "rule_aggregation"
// Addition for alert_type = logs
ApplicationAlertConfigsFieldRuleMessage = "rule_message"
ApplicationAlertConfigsFieldRuleOperator = "rule_operator"
ApplicationAlertConfigsFieldRuleLevel = "rule_level"

ApplicationAlertConfigsFieldAlertChannelIds = "integration_ids"

Expand Down Expand Up @@ -59,7 +63,7 @@ var ApplicationAlertConfigsRuleAlertType = &schema.Schema{
Required: true,
Description: "Type of the Alert Rule",
// TODO: Just support slowness for now
ValidateFunc: validation.StringInSlice([]string{"slowness"}, true),
ValidateFunc: validation.StringInSlice([]string{"slowness", "logs"}, true),
}

var ApplicationAlertConfigsRuleMetricName = &schema.Schema{
Expand All @@ -74,7 +78,21 @@ var ApplicationAlertConfigsRuleAggregation = &schema.Schema{
Required: true,
Description: "Aggregation for given Metrics",
ValidateFunc: validation.StringInSlice([]string{"sum", "mean", "max", "min", "p25",
"p50", "p75", "p90","p95", "p98", "p99", "distinct_count"}, true),
"p50", "p75", "p90", "p95", "p98", "p99", "distinct_count"}, true),
}

var ApplicationAlertConfigsRuleMessage = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "Message of the alert",
ValidateFunc: validation.StringLenBetween(0, 256),
}

var ApplicationAlertConfigsRuleLevel = &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "Rule Alerting Level",
ValidateFunc: validation.StringInSlice([]string{"WARN", "ERROR"}, true),
}

var ApplicationAlertConfigsIntergrationIds = &schema.Schema{
Expand Down Expand Up @@ -105,15 +123,37 @@ var ApplicationAlertConfigsThresholdOperator = &schema.Schema{
Description: "The Operator to compare Threshold",
}


const (
TagFilterName = "name"
TagFilterEntity = "entity"
TagFilterStringValue ="string_value"
TagFilterNumberValue = "number_value"
TagFilterName = "name"
TagFilterEntity = "entity"
TagFilterStringValue = "string_value"
TagFilterNumberValue = "number_value"
TagFilterBooleanValue = "boolean_value"
TagFilterOperator = "operator"
TagFilterOperator = "operator"
)

var ApplicationFilterOperator = &schema.Schema{
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(
[]string{"EQUALS",
"CONTAINS",
"LESS_THAN",
"LESS_OR_EQUAL_THAN",
"GREATER_THAN",
"GREATER_OR_EQUAL_THAN",
"NOT_EMPTY",
"NOT_EQUAL",
"IS_EMPTY",
"NOT_BLANK",
"IS_BLANK",
"STARTS_WITH",
"ENDS_WITH",
"NOT_STARTS_WITH",
"NOT_ENDS_WITH",
}, false),
}

var ApplicationAlertConfigsTagFilter = &schema.Schema{
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -143,27 +183,7 @@ var ApplicationAlertConfigsTagFilter = &schema.Schema{
Required: false,
Optional: true,
},
TagFilterOperator: {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(
[]string{"EQUALS",
"CONTAINS",
"LESS_THAN",
"LESS_OR_EQUAL_THAN",
"GREATER_THAN",
"GREATER_OR_EQUAL_THAN",
"NOT_EMPTY",
"NOT_EQUAL",
"IS_EMPTY",
"NOT_BLANK",
"IS_BLANK",
"STARTS_WITH",
"ENDS_WITH",
"NOT_STARTS_WITH",
"NOT_ENDS_WITH",
}, false),
},
TagFilterOperator: ApplicationFilterOperator,
},
},
}
Expand All @@ -180,6 +200,9 @@ func NewApplicationAlertConfigsResourceHandle() *ResourceHandle {
ApplicationAlertConfigsFieldRuleAlertType: ApplicationAlertConfigsRuleAlertType,
ApplicationAlertConfigsFieldRuleMetricName: ApplicationAlertConfigsRuleMetricName,
ApplicationAlertConfigsFieldRuleAggregation: ApplicationAlertConfigsRuleAggregation,
ApplicationAlertConfigsFieldRuleMessage: ApplicationAlertConfigsRuleMessage,
ApplicationAlertConfigsFieldRuleOperator: ApplicationFilterOperator,
ApplicationAlertConfigsFieldRuleLevel: ApplicationAlertConfigsRuleLevel,
ApplicationAlertConfigsFieldAlertChannelIds: ApplicationAlertConfigsIntergrationIds,
ApplicationAlertConfigsFieldThresholdValue: ApplicationAlertConfigsThresholdValue,
ApplicationAlertConfigsFieldThresholdType: ApplicationAlertConfigsThresholdType,
Expand All @@ -205,6 +228,9 @@ func updateStateForApplicationAlertConfigs(d *schema.ResourceData, obj restapi.I
d.Set(ApplicationAlertConfigsFieldApplicationId, config.ApplicationId)
d.Set(ApplicationAlertConfigsFieldRuleAlertType, config.Rule.AlertType)
d.Set(ApplicationAlertConfigsFieldRuleAggregation, config.Rule.Aggregation)
d.Set(ApplicationAlertConfigsFieldRuleMessage, config.Rule.Message)
d.Set(ApplicationAlertConfigsFieldRuleOperator, config.Rule.Operator)
d.Set(ApplicationAlertConfigsFieldRuleLevel, config.Rule.Level)
d.Set(ApplicationAlertConfigsFieldRuleMetricName, config.Rule.MetricName)
d.Set(ApplicationAlertConfigsFieldAlertChannelIds, config.AlertChannelIds)
d.Set(ApplicationAlertConfigsFieldThresholdValue, config.Threshold.Value)
Expand All @@ -217,12 +243,12 @@ func updateStateForApplicationAlertConfigs(d *schema.ResourceData, obj restapi.I

func mapStateToDataObjectForApplicationAlertConfigs(d *schema.ResourceData, formatter utils.ResourceNameFormatter) (restapi.InstanaDataObject, error) {
name := computeFullApplicationAlertConfigsAlertNameString(d, formatter)
//panic: interface conversion: interface {} is *schema.Set, not []restapi.ApplicationAlertConfigsTagFilter
//panic: interface conversion: interface {} is *schema.Set, not []restapi.ApplicationAlertConfigsTagFilter

list := d.Get(ApplicationAlertConfigsFieldTagFilter).(*schema.Set).List()
tagFilters := make([]restapi.ApplicationAlertConfigsTagFilter, len(list))
for i := range list {
tagFilterMap := list[i].( map[string]interface {})
tagFilterMap := list[i].(map[string]interface{})

tagFilters[i] = restapi.ApplicationAlertConfigsTagFilter{
Type: "TAG_FILTER",
Expand All @@ -245,16 +271,18 @@ func mapStateToDataObjectForApplicationAlertConfigs(d *schema.ResourceData, form
AlertType: d.Get(ApplicationAlertConfigsFieldRuleAlertType).(string),
Aggregation: d.Get(ApplicationAlertConfigsFieldRuleAggregation).(string),
MetricName: d.Get(ApplicationAlertConfigsFieldRuleMetricName).(string),
Message: d.Get(ApplicationAlertConfigsFieldRuleMessage).(string),
Operator: d.Get(ApplicationAlertConfigsFieldRuleOperator).(string),
Level: d.Get(ApplicationAlertConfigsFieldRuleLevel).(string),
},
Threshold: restapi.Threshold{
Type: d.Get(ApplicationAlertConfigsFieldThresholdType).(string),
Operator: d.Get(ApplicationAlertConfigsFieldThresholdOperator).(string),
LastUpdated: 0,
Value: d.Get(ApplicationAlertConfigsFieldThresholdValue).(float64),
},
Description: d.Get(ApplicationAlertConfigsFieldDescription).(string),
TagFilters: tagFilters,

Description: d.Get(ApplicationAlertConfigsFieldDescription).(string),
TagFilters: tagFilters,

AlertChannelIds: ReadStringSetParameterFromResource(d, ApplicationAlertConfigsFieldAlertChannelIds),
Severity: 5,
Expand Down
4 changes: 4 additions & 0 deletions instana/restapi/application-alert-configs-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ type ApplicationAlertConfigsRule struct {
AlertType string `json:"alertType"`
MetricName string `json:"metricName"`
Aggregation string `json:"aggregation"`

Operator string `json:"operator"`
Message string `json:"message"`
Level string `json:"level"`
}

type Threshold struct {
Expand Down

0 comments on commit eb6fffa

Please sign in to comment.