fix translating snmp fields not in MIB (#1846)
This commit is contained in:
parent
ce5054c850
commit
9feb639bbd
|
@ -43,6 +43,7 @@
|
||||||
- [#1772](https://github.com/influxdata/telegraf/pull/1772): Windows remote management interactive service fix.
|
- [#1772](https://github.com/influxdata/telegraf/pull/1772): Windows remote management interactive service fix.
|
||||||
- [#1702](https://github.com/influxdata/telegraf/issues/1702): sqlserver, fix issue when case sensitive collation is activated.
|
- [#1702](https://github.com/influxdata/telegraf/issues/1702): sqlserver, fix issue when case sensitive collation is activated.
|
||||||
- [#1823](https://github.com/influxdata/telegraf/issues/1823): Fix huge allocations in http_listener when dealing with huge payloads.
|
- [#1823](https://github.com/influxdata/telegraf/issues/1823): Fix huge allocations in http_listener when dealing with huge payloads.
|
||||||
|
- [#1833](https://github.com/influxdata/telegraf/issues/1833): Fix translating SNMP fields not in MIB.
|
||||||
|
|
||||||
## v1.0.1 [unreleased]
|
## v1.0.1 [unreleased]
|
||||||
|
|
||||||
|
|
|
@ -850,11 +850,16 @@ func snmpTranslate(oid string) (mibName string, oidNum string, oidText string, c
|
||||||
|
|
||||||
i := strings.Index(oidText, "::")
|
i := strings.Index(oidText, "::")
|
||||||
if i == -1 {
|
if i == -1 {
|
||||||
// was not found in MIB. Value is numeric
|
// was not found in MIB.
|
||||||
return "", oidText, oidText, "", nil
|
if bytes.Index(bb.Bytes(), []byte(" [TRUNCATED]")) >= 0 {
|
||||||
|
return "", oid, oid, "", nil
|
||||||
|
}
|
||||||
|
// not truncated, but not fully found. We still need to parse out numeric OID, so keep going
|
||||||
|
oidText = oid
|
||||||
|
} else {
|
||||||
|
mibName = oidText[:i]
|
||||||
|
oidText = oidText[i+2:]
|
||||||
}
|
}
|
||||||
mibName = oidText[:i]
|
|
||||||
oidText = oidText[i+2:]
|
|
||||||
|
|
||||||
if i := bytes.Index(bb.Bytes(), []byte(" -- TEXTUAL CONVENTION ")); i != -1 {
|
if i := bytes.Index(bb.Bytes(), []byte(" -- TEXTUAL CONVENTION ")); i != -1 {
|
||||||
bb.Next(i + len(" -- TEXTUAL CONVENTION "))
|
bb.Next(i + len(" -- TEXTUAL CONVENTION "))
|
||||||
|
|
|
@ -21,6 +21,8 @@ var mockedCommands = [][]string{
|
||||||
{"snmptranslate", "-Td", "-Ob", "-m", "all", "1.0.0.1.1"},
|
{"snmptranslate", "-Td", "-Ob", "-m", "all", "1.0.0.1.1"},
|
||||||
{"snmptranslate", "-Td", "-Ob", "-m", "all", ".1.0.0.0.1.1"},
|
{"snmptranslate", "-Td", "-Ob", "-m", "all", ".1.0.0.0.1.1"},
|
||||||
{"snmptranslate", "-Td", "-Ob", "-m", "all", ".1.0.0.0.1.1.0"},
|
{"snmptranslate", "-Td", "-Ob", "-m", "all", ".1.0.0.0.1.1.0"},
|
||||||
|
{"snmptranslate", "-Td", "-Ob", "-m", "all", ".1.2.3"},
|
||||||
|
{"snmptranslate", "-Td", "-Ob", ".iso.2.3"},
|
||||||
{"snmptranslate", "-Td", "-Ob", "-m", "all", ".999"},
|
{"snmptranslate", "-Td", "-Ob", "-m", "all", ".999"},
|
||||||
{"snmptranslate", "-Td", "-Ob", "TEST::server"},
|
{"snmptranslate", "-Td", "-Ob", "TEST::server"},
|
||||||
{"snmptranslate", "-Td", "-Ob", "TEST::server.0"},
|
{"snmptranslate", "-Td", "-Ob", "TEST::server.0"},
|
||||||
|
|
|
@ -67,6 +67,8 @@ var mockedCommandResults = map[string]mockedCommandResult{
|
||||||
"snmptranslate\x00-Td\x00-Ob\x00-m\x00all\x001.0.0.1.1": mockedCommandResult{stdout: "TEST::hostname\nhostname OBJECT-TYPE\n -- FROM\tTEST\n SYNTAX\tOCTET STRING\n MAX-ACCESS\tread-only\n STATUS\tcurrent\n::= { iso(1) 0 testOID(0) 1 1 }\n", stderr: "", exitError: false},
|
"snmptranslate\x00-Td\x00-Ob\x00-m\x00all\x001.0.0.1.1": mockedCommandResult{stdout: "TEST::hostname\nhostname OBJECT-TYPE\n -- FROM\tTEST\n SYNTAX\tOCTET STRING\n MAX-ACCESS\tread-only\n STATUS\tcurrent\n::= { iso(1) 0 testOID(0) 1 1 }\n", stderr: "", exitError: false},
|
||||||
"snmptranslate\x00-Td\x00-Ob\x00-m\x00all\x00.1.0.0.0.1.1": mockedCommandResult{stdout: "TEST::server\nserver OBJECT-TYPE\n -- FROM\tTEST\n SYNTAX\tOCTET STRING\n MAX-ACCESS\tread-only\n STATUS\tcurrent\n::= { iso(1) 0 testOID(0) testTable(0) testTableEntry(1) 1 }\n", stderr: "", exitError: false},
|
"snmptranslate\x00-Td\x00-Ob\x00-m\x00all\x00.1.0.0.0.1.1": mockedCommandResult{stdout: "TEST::server\nserver OBJECT-TYPE\n -- FROM\tTEST\n SYNTAX\tOCTET STRING\n MAX-ACCESS\tread-only\n STATUS\tcurrent\n::= { iso(1) 0 testOID(0) testTable(0) testTableEntry(1) 1 }\n", stderr: "", exitError: false},
|
||||||
"snmptranslate\x00-Td\x00-Ob\x00-m\x00all\x00.1.0.0.0.1.1.0": mockedCommandResult{stdout: "TEST::server.0\nserver OBJECT-TYPE\n -- FROM\tTEST\n SYNTAX\tOCTET STRING\n MAX-ACCESS\tread-only\n STATUS\tcurrent\n::= { iso(1) 0 testOID(0) testTable(0) testTableEntry(1) server(1) 0 }\n", stderr: "", exitError: false},
|
"snmptranslate\x00-Td\x00-Ob\x00-m\x00all\x00.1.0.0.0.1.1.0": mockedCommandResult{stdout: "TEST::server.0\nserver OBJECT-TYPE\n -- FROM\tTEST\n SYNTAX\tOCTET STRING\n MAX-ACCESS\tread-only\n STATUS\tcurrent\n::= { iso(1) 0 testOID(0) testTable(0) testTableEntry(1) server(1) 0 }\n", stderr: "", exitError: false},
|
||||||
|
"snmptranslate\x00-Td\x00-Ob\x00-m\x00all\x00.1.2.3": mockedCommandResult{stdout: "iso.2.3\niso OBJECT-TYPE\n -- FROM\t#-1\n::= { iso(1) 2 3 }\n", stderr: "", exitError: false},
|
||||||
|
"snmptranslate\x00-Td\x00-Ob\x00.iso.2.3": mockedCommandResult{stdout: "iso.2.3\niso OBJECT-TYPE\n -- FROM\t#-1\n::= { iso(1) 2 3 }\n", stderr: "", exitError: false},
|
||||||
"snmptranslate\x00-Td\x00-Ob\x00-m\x00all\x00.999": mockedCommandResult{stdout: ".999\n [TRUNCATED]\n", stderr: "", exitError: false},
|
"snmptranslate\x00-Td\x00-Ob\x00-m\x00all\x00.999": mockedCommandResult{stdout: ".999\n [TRUNCATED]\n", stderr: "", exitError: false},
|
||||||
"snmptranslate\x00-Td\x00-Ob\x00TEST::server": mockedCommandResult{stdout: "TEST::server\nserver OBJECT-TYPE\n -- FROM\tTEST\n SYNTAX\tOCTET STRING\n MAX-ACCESS\tread-only\n STATUS\tcurrent\n::= { iso(1) 0 testOID(0) testTable(0) testTableEntry(1) 1 }\n", stderr: "", exitError: false},
|
"snmptranslate\x00-Td\x00-Ob\x00TEST::server": mockedCommandResult{stdout: "TEST::server\nserver OBJECT-TYPE\n -- FROM\tTEST\n SYNTAX\tOCTET STRING\n MAX-ACCESS\tread-only\n STATUS\tcurrent\n::= { iso(1) 0 testOID(0) testTable(0) testTableEntry(1) 1 }\n", stderr: "", exitError: false},
|
||||||
"snmptranslate\x00-Td\x00-Ob\x00TEST::server.0": mockedCommandResult{stdout: "TEST::server.0\nserver OBJECT-TYPE\n -- FROM\tTEST\n SYNTAX\tOCTET STRING\n MAX-ACCESS\tread-only\n STATUS\tcurrent\n::= { iso(1) 0 testOID(0) testTable(0) testTableEntry(1) server(1) 0 }\n", stderr: "", exitError: false},
|
"snmptranslate\x00-Td\x00-Ob\x00TEST::server.0": mockedCommandResult{stdout: "TEST::server.0\nserver OBJECT-TYPE\n -- FROM\tTEST\n SYNTAX\tOCTET STRING\n MAX-ACCESS\tread-only\n STATUS\tcurrent\n::= { iso(1) 0 testOID(0) testTable(0) testTableEntry(1) server(1) 0 }\n", stderr: "", exitError: false},
|
||||||
|
|
|
@ -128,6 +128,8 @@ func TestFieldInit(t *testing.T) {
|
||||||
expectedName string
|
expectedName string
|
||||||
expectedConversion string
|
expectedConversion string
|
||||||
}{
|
}{
|
||||||
|
{".1.2.3", "foo", "", ".1.2.3", "foo", ""},
|
||||||
|
{".iso.2.3", "foo", "", ".1.2.3", "foo", ""},
|
||||||
{".1.0.0.0.1.1", "", "", ".1.0.0.0.1.1", "server", ""},
|
{".1.0.0.0.1.1", "", "", ".1.0.0.0.1.1", "server", ""},
|
||||||
{".1.0.0.0.1.1.0", "", "", ".1.0.0.0.1.1.0", "server.0", ""},
|
{".1.0.0.0.1.1.0", "", "", ".1.0.0.0.1.1.0", "server.0", ""},
|
||||||
{".999", "", "", ".999", ".999", ""},
|
{".999", "", "", ".999", ".999", ""},
|
||||||
|
|
Loading…
Reference in New Issue