feat(kapacitor): add serviceNow alert properties to server
parent
06fca8a6a1
commit
7cdb970339
11
kapacitor.go
11
kapacitor.go
|
@ -24,6 +24,7 @@ type AlertNodes struct {
|
||||||
OpsGenie2 []*OpsGenie `json:"opsGenie2"` // OpsGenie2 will send alert to all OpsGenie v2
|
OpsGenie2 []*OpsGenie `json:"opsGenie2"` // OpsGenie2 will send alert to all OpsGenie v2
|
||||||
Talk []*Talk `json:"talk"` // Talk will send alert to all Talk
|
Talk []*Talk `json:"talk"` // Talk will send alert to all Talk
|
||||||
Kafka []*Kafka `json:"kafka"` // Kafka will send alert to all Kafka
|
Kafka []*Kafka `json:"kafka"` // Kafka will send alert to all Kafka
|
||||||
|
ServiceNow []*ServiceNow `json:"serviceNow"` // ServiceNow alert options
|
||||||
}
|
}
|
||||||
|
|
||||||
// Post will POST alerts to a destination URL
|
// Post will POST alerts to a destination URL
|
||||||
|
@ -144,6 +145,16 @@ type Kafka struct {
|
||||||
Template string `json:"template"`
|
Template string `json:"template"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ServiceNow properties
|
||||||
|
type ServiceNow struct {
|
||||||
|
Source string `json:"source"`
|
||||||
|
Node string `json:"node"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Resource string `json:"resource"`
|
||||||
|
MetricName string `json:"metric_name"`
|
||||||
|
MessageKey string `json:"message_key"`
|
||||||
|
}
|
||||||
|
|
||||||
// MarshalJSON converts AlertNodes to JSON
|
// MarshalJSON converts AlertNodes to JSON
|
||||||
func (n *AlertNodes) MarshalJSON() ([]byte, error) {
|
func (n *AlertNodes) MarshalJSON() ([]byte, error) {
|
||||||
type Alias AlertNodes
|
type Alias AlertNodes
|
||||||
|
|
|
@ -19,8 +19,18 @@ func AlertServices(rule chronograf.AlertRule) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ValidateAlert(node); err != nil {
|
if err := ValidateAlert(node); err != nil {
|
||||||
|
// workaround for not-yet released fix https://github.com/influxdata/kapacitor/pull/2488
|
||||||
|
// it can be deleted once kapacitor 1.5.9+ is released
|
||||||
|
// can be simply: return "", err
|
||||||
|
if !strings.Contains(err.Error(), `property "servicenow"`) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
// no method or property "servicenow" on *pipeline.AlertNode
|
||||||
|
node = strings.Replace(node, ".servicenow()", ".serviceNow()", 1)
|
||||||
|
if err2 := ValidateAlert(node); err2 != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
}
|
||||||
return node, nil
|
return node, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -139,6 +139,30 @@ func TestAlertServices(t *testing.T) {
|
||||||
want: `alert()
|
want: `alert()
|
||||||
.post('http://myaddress')
|
.post('http://myaddress')
|
||||||
.header('key', 'value')
|
.header('key', 'value')
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Test serviceNow",
|
||||||
|
rule: chronograf.AlertRule{
|
||||||
|
AlertNodes: chronograf.AlertNodes{
|
||||||
|
ServiceNow: []*chronograf.ServiceNow{{
|
||||||
|
Source: "a",
|
||||||
|
Type: "b",
|
||||||
|
Node: "c",
|
||||||
|
Resource: "d",
|
||||||
|
MetricName: "e",
|
||||||
|
MessageKey: "f",
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: `alert()
|
||||||
|
.serviceNow()
|
||||||
|
.source('a')
|
||||||
|
.node('c')
|
||||||
|
.type('b')
|
||||||
|
.resource('d')
|
||||||
|
.metricName('e')
|
||||||
|
.messageKey('f')
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue