Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove metric.Point from metric interface #2365

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ It is highly recommended that all users migrate to the new riemann output plugin
- [#2201](https://github.com/influxdata/telegraf/pull/2201): Add lock option to the IPtables input plugin.
- [#2244](https://github.com/influxdata/telegraf/pull/2244): Support ipmi_sensor plugin querying local ipmi sensors.
- [#2339](https://github.com/influxdata/telegraf/pull/2339): Increment gather_errors for all errors emitted by inputs.
- [#1948](https://github.com/influxdata/telegraf/pull/1948): Support adding SNMP table indexes as tags.

### Bugfixes

Expand Down
1 change: 1 addition & 0 deletions plugins/inputs/snmp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testdata
3 changes: 3 additions & 0 deletions plugins/inputs/snmp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ If not specified, it defaults to the value of `oid`. If `oid` is numeric, an at
* `inherit_tags`:
Which tags to inherit from the top-level config and to use in the output of this table's measurement.

* `index_as_tag`:
Adds each row's index within the table as a tag.

### MIB lookups
If the plugin is configured such that it needs to perform lookups from the MIB, it will use the net-snmp utilities `snmptranslate` and `snmptable`.

Expand Down
15 changes: 12 additions & 3 deletions plugins/inputs/snmp/snmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ type Table struct {
// Which tags to inherit from the top-level config.
InheritTags []string

// Adds each row's table index as a tag.
IndexAsTag bool

// Fields is the tags and values to look up.
Fields []Field `toml:"field"`

Expand Down Expand Up @@ -464,13 +467,19 @@ func (t Table) Build(gs snmpConnection, walk bool) (*RTable, error) {
}
}

for i, v := range ifv {
rtr, ok := rows[i]
for idx, v := range ifv {
rtr, ok := rows[idx]
if !ok {
rtr = RTableRow{}
rtr.Tags = map[string]string{}
rtr.Fields = map[string]interface{}{}
rows[i] = rtr
rows[idx] = rtr
}
if t.IndexAsTag && idx != "" {
if idx[0] == '.' {
idx = idx[1:]
}
rtr.Tags["index"] = idx
}
// don't add an empty string
if vs, ok := v.(string); !ok || vs != "" {
Expand Down
21 changes: 16 additions & 5 deletions plugins/inputs/snmp/snmp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@ func TestGosnmpWrapper_get_retry(t *testing.T) {

func TestTableBuild_walk(t *testing.T) {
tbl := Table{
Name: "mytable",
Name: "mytable",
IndexAsTag: true,
Fields: []Field{
{
Name: "myfield1",
Expand Down Expand Up @@ -442,30 +443,40 @@ func TestTableBuild_walk(t *testing.T) {

assert.Equal(t, tb.Name, "mytable")
rtr1 := RTableRow{
Tags: map[string]string{"myfield1": "foo"},
Tags: map[string]string{
"myfield1": "foo",
"index": "0",
},
Fields: map[string]interface{}{
"myfield2": 1,
"myfield3": float64(0.123),
"myfield4": 11,
},
}
rtr2 := RTableRow{
Tags: map[string]string{"myfield1": "bar"},
Tags: map[string]string{
"myfield1": "bar",
"index": "1",
},
Fields: map[string]interface{}{
"myfield2": 2,
"myfield3": float64(0.456),
"myfield4": 22,
},
}
rtr3 := RTableRow{
Tags: map[string]string{},
Tags: map[string]string{
"index": "2",
},
Fields: map[string]interface{}{
"myfield2": 0,
"myfield3": float64(0.0),
},
}
rtr4 := RTableRow{
Tags: map[string]string{},
Tags: map[string]string{
"index": "3",
},
Fields: map[string]interface{}{
"myfield3": float64(9.999),
},
Expand Down