From a872e724026e20e1384258345d63a66c3b3db5df Mon Sep 17 00:00:00 2001 From: Ranjib Dey Date: Sun, 21 Aug 2016 00:35:45 -0700 Subject: [PATCH] make tag separate type --- plugins/outputs/pagerduty/README.md | 5 +++++ plugins/outputs/pagerduty/pagerduty.go | 26 +++++++++++++++----------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/plugins/outputs/pagerduty/README.md b/plugins/outputs/pagerduty/README.md index 940c38dba..12d9db415 100644 --- a/plugins/outputs/pagerduty/README.md +++ b/plugins/outputs/pagerduty/README.md @@ -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 = "" @@ -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" ``` diff --git a/plugins/outputs/pagerduty/pagerduty.go b/plugins/outputs/pagerduty/pagerduty.go index 14bbe9c34..15b3623b5 100644 --- a/plugins/outputs/pagerduty/pagerduty.go +++ b/plugins/outputs/pagerduty/pagerduty.go @@ -6,14 +6,19 @@ 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"` - incidentKey string `toml:"-"` + ServiceKey string `toml:"service_key"` + Desc string `toml:"description"` + Metric string `toml:"metric"` + Field string `toml:"field"` + Expression string `toml:"expression"` + TagFilter []Tag `toml:"tags"` + incidentKey string `toml:"-"` } var sampleConfig = ` @@ -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 } }