feat(kapacitor): add serviceNow alert properties to server
parent
06fca8a6a1
commit
7cdb970339
51
kapacitor.go
51
kapacitor.go
|
@ -4,26 +4,27 @@ import "encoding/json"
|
||||||
|
|
||||||
// AlertNodes defines all possible kapacitor interactions with an alert.
|
// AlertNodes defines all possible kapacitor interactions with an alert.
|
||||||
type AlertNodes struct {
|
type AlertNodes struct {
|
||||||
IsStateChangesOnly bool `json:"stateChangesOnly"` // IsStateChangesOnly will only send alerts on state changes.
|
IsStateChangesOnly bool `json:"stateChangesOnly"` // IsStateChangesOnly will only send alerts on state changes.
|
||||||
UseFlapping bool `json:"useFlapping"` // UseFlapping enables flapping detection. Flapping occurs when a service or host changes state too frequently, resulting in a storm of problem and recovery notification
|
UseFlapping bool `json:"useFlapping"` // UseFlapping enables flapping detection. Flapping occurs when a service or host changes state too frequently, resulting in a storm of problem and recovery notification
|
||||||
Posts []*Post `json:"post"` // HTTPPost will post the JSON alert data to the specified URLs.
|
Posts []*Post `json:"post"` // HTTPPost will post the JSON alert data to the specified URLs.
|
||||||
TCPs []*TCP `json:"tcp"` // TCP will send the JSON alert data to the specified endpoint via TCP.
|
TCPs []*TCP `json:"tcp"` // TCP will send the JSON alert data to the specified endpoint via TCP.
|
||||||
Email []*Email `json:"email"` // Email will send alert data to the specified emails.
|
Email []*Email `json:"email"` // Email will send alert data to the specified emails.
|
||||||
Exec []*Exec `json:"exec"` // Exec will run shell commandss when an alert triggers
|
Exec []*Exec `json:"exec"` // Exec will run shell commandss when an alert triggers
|
||||||
Log []*Log `json:"log"` // Log will log JSON alert data to files in JSON lines format.
|
Log []*Log `json:"log"` // Log will log JSON alert data to files in JSON lines format.
|
||||||
VictorOps []*VictorOps `json:"victorOps"` // VictorOps will send alert to all VictorOps
|
VictorOps []*VictorOps `json:"victorOps"` // VictorOps will send alert to all VictorOps
|
||||||
PagerDuty []*PagerDuty `json:"pagerDuty"` // PagerDuty will send alert to all PagerDuty
|
PagerDuty []*PagerDuty `json:"pagerDuty"` // PagerDuty will send alert to all PagerDuty
|
||||||
PagerDuty2 []*PagerDuty `json:"pagerDuty2"` // PagerDuty2 will send alert to PagerDuty v2
|
PagerDuty2 []*PagerDuty `json:"pagerDuty2"` // PagerDuty2 will send alert to PagerDuty v2
|
||||||
Pushover []*Pushover `json:"pushover"` // Pushover will send alert to all Pushover
|
Pushover []*Pushover `json:"pushover"` // Pushover will send alert to all Pushover
|
||||||
Sensu []*Sensu `json:"sensu"` // Sensu will send alert to all Sensu
|
Sensu []*Sensu `json:"sensu"` // Sensu will send alert to all Sensu
|
||||||
Slack []*Slack `json:"slack"` // Slack will send alert to Slack
|
Slack []*Slack `json:"slack"` // Slack will send alert to Slack
|
||||||
Telegram []*Telegram `json:"telegram"` // Telegram will send alert to all Telegram
|
Telegram []*Telegram `json:"telegram"` // Telegram will send alert to all Telegram
|
||||||
HipChat []*HipChat `json:"hipChat"` // HipChat will send alert to all HipChat
|
HipChat []*HipChat `json:"hipChat"` // HipChat will send alert to all HipChat
|
||||||
Alerta []*Alerta `json:"alerta"` // Alerta will send alert to all Alerta
|
Alerta []*Alerta `json:"alerta"` // Alerta will send alert to all Alerta
|
||||||
OpsGenie []*OpsGenie `json:"opsGenie"` // OpsGenie will send alert to all OpsGenie
|
OpsGenie []*OpsGenie `json:"opsGenie"` // OpsGenie will send alert to all OpsGenie
|
||||||
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,7 +19,17 @@ func AlertServices(rule chronograf.AlertRule) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ValidateAlert(node); err != nil {
|
if err := ValidateAlert(node); err != nil {
|
||||||
return "", err
|
// 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
|
||||||
|
}
|
||||||
|
// 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