make tag separate type
This commit is contained in:
parent
8a8b9893aa
commit
a872e72402
|
@ -6,6 +6,8 @@ Following is an example of send PagerDuty alerts based on "time_iowait" field
|
|||
of the "cpu" metric. It will send PagerDyty alert any time the "time_iowait"
|
||||
value is more than 50
|
||||
|
||||
Optionally, alerts can be restriced to metrics with a given set of tags
|
||||
|
||||
```toml
|
||||
[[outputs.pagerduty]]
|
||||
service_key = "<SERVICE KEY>"
|
||||
|
@ -13,4 +15,7 @@ value is more than 50
|
|||
description = "Check CPU"
|
||||
field = "time_iowait"
|
||||
expression = "> 50.0"
|
||||
[[outputs.pagerduty.tags]]
|
||||
name = "role"
|
||||
value = "web"
|
||||
```
|
||||
|
|
|
@ -6,13 +6,18 @@ import (
|
|||
"github.com/influxdata/telegraf/plugins/outputs"
|
||||
)
|
||||
|
||||
type Tag struct {
|
||||
Name string `toml:"name"`
|
||||
Value string `toml:"value"`
|
||||
}
|
||||
|
||||
type PD struct {
|
||||
ServiceKey string `toml:"service_key"`
|
||||
Desc string `toml:"description"`
|
||||
Metric string `toml:"metric"`
|
||||
Field string `toml:"field"`
|
||||
Expression string `toml:"expression"`
|
||||
TagFilter map[string]string `toml:"tag_filter"`
|
||||
TagFilter []Tag `toml:"tags"`
|
||||
incidentKey string `toml:"-"`
|
||||
}
|
||||
|
||||
|
@ -29,7 +34,6 @@ var sampleConfig = `
|
|||
## will be considered for further processing
|
||||
[[outputs.pagerduty.tag_filter]]
|
||||
role = "web-server"
|
||||
region = "us-west1"
|
||||
## Expression is used to evaluate the alert
|
||||
expression = "> 50.0"
|
||||
`
|
||||
|
@ -54,9 +58,9 @@ func (p *PD) isMatch(metric telegraf.Metric) bool {
|
|||
if p.Metric != metric.Name() {
|
||||
return false
|
||||
}
|
||||
for k, v := range p.TagFilter {
|
||||
t, ok := metric.Tags()[k]
|
||||
if !ok || (t != v) {
|
||||
for _, tag := range p.TagFilter {
|
||||
v, ok := metric.Tags()[tag.Name]
|
||||
if !ok || (v != tag.Value) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue