From a93b52d654c0367e35ea02efdcf9d7388563ce63 Mon Sep 17 00:00:00 2001 From: Frederic Van Espen Date: Fri, 28 Aug 2020 17:32:12 +0200 Subject: [PATCH 1/5] look up EnumAsInfo indexes in enum_values Signed-off-by: Frederic Van Espen --- collector.go | 16 ++++++++++------ config/config.go | 9 +++++---- generator/tree.go | 1 + 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/collector.go b/collector.go index 838f5647..9b621ab9 100644 --- a/collector.go +++ b/collector.go @@ -567,7 +567,7 @@ func pduValueAsString(pdu *gosnmp.SnmpPDU, typ string) string { // Prepend the length, as it is explicit in an index. parts = append([]int{len(pdu.Value.([]byte))}, parts...) } - str, _, _ := indexOidsAsString(parts, typ, 0, false) + str, _, _ := indexOidsAsString(parts, typ, 0, false, nil) return str case nil: return "" @@ -581,7 +581,7 @@ func pduValueAsString(pdu *gosnmp.SnmpPDU, typ string) string { // Convert oids to a string index value. // // Returns the string, the oids that were used and the oids left over. -func indexOidsAsString(indexOids []int, typ string, fixedSize int, implied bool) (string, []int, []int) { +func indexOidsAsString(indexOids []int, typ string, fixedSize int, implied bool, enumValues map[int]string) (string, []int, []int) { if typeMapping, ok := combinedTypeMapping[typ]; ok { subOid, valueOids := splitOid(indexOids, 2) if typ == "InetAddressMissingSize" { @@ -591,15 +591,15 @@ func indexOidsAsString(indexOids []int, typ string, fixedSize int, implied bool) var str string var used, remaining []int if t, ok := typeMapping[subOid[0]]; ok { - str, used, remaining = indexOidsAsString(valueOids, t, 0, false) + str, used, remaining = indexOidsAsString(valueOids, t, 0, false, enumValues) return str, append(subOid, used...), remaining } if typ == "InetAddressMissingSize" { // We don't know the size, so pass everything remaining. - return indexOidsAsString(indexOids, "OctetString", 0, true) + return indexOidsAsString(indexOids, "OctetString", 0, true, enumValues) } // The 2nd oid is the length. - return indexOidsAsString(indexOids, "OctetString", subOid[1]+2, false) + return indexOidsAsString(indexOids, "OctetString", subOid[1]+2, false, enumValues) } switch typ { @@ -669,6 +669,10 @@ func indexOidsAsString(indexOids []int, typ string, fixedSize int, implied bool) parts[i] = o } return fmt.Sprintf("%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X", parts...), subOid, indexOids + case "EnumAsInfo": + subOid, indexOids := splitOid(indexOids, 1) + return enumValues[subOid[0]], subOid, indexOids + default: panic(fmt.Sprintf("Unknown index type %s", typ)) return "", nil, nil @@ -681,7 +685,7 @@ func indexesToLabels(indexOids []int, metric *config.Metric, oidToPdu map[string // Covert indexes to useful strings. for _, index := range metric.Indexes { - str, subOid, remainingOids := indexOidsAsString(indexOids, index.Type, index.FixedSize, index.Implied) + str, subOid, remainingOids := indexOidsAsString(indexOids, index.Type, index.FixedSize, index.Implied, index.EnumValues) // The labelvalue is the text form of the index oids. labels[index.Labelname] = str // Save its oid in case we need it for lookups. diff --git a/config/config.go b/config/config.go index 10e053df..a97f32f8 100644 --- a/config/config.go +++ b/config/config.go @@ -181,10 +181,11 @@ type Metric struct { } type Index struct { - Labelname string `yaml:"labelname"` - Type string `yaml:"type"` - FixedSize int `yaml:"fixed_size,omitempty"` - Implied bool `yaml:"implied,omitempty"` + Labelname string `yaml:"labelname"` + Type string `yaml:"type"` + FixedSize int `yaml:"fixed_size,omitempty"` + Implied bool `yaml:"implied,omitempty"` + EnumValues map[int]string `yaml:"enum_values,omitempty"` } type Lookup struct { diff --git a/generator/tree.go b/generator/tree.go index 93684030..cb370fb9 100644 --- a/generator/tree.go +++ b/generator/tree.go @@ -358,6 +358,7 @@ func generateConfigModule(cfg *ModuleConfig, node *Node, nameToNode map[string]* if n.ImpliedIndex && count+1 == len(n.Indexes) { index.Implied = true } + index.EnumValues = indexNode.EnumValues // Convert (InetAddressType,InetAddress) to (InetAddress) if subtype, ok := combinedTypes[index.Type]; ok { From 545219dfa0c7b4fabd536addf0b859431af05fef Mon Sep 17 00:00:00 2001 From: Frederic Van Espen Date: Mon, 31 Aug 2020 10:35:20 +0200 Subject: [PATCH 2/5] some changes after review * add generator test * reformat Signed-off-by: Frederic Van Espen --- collector.go | 1 - config/config.go | 2 +- generator/tree_test.go | 51 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/collector.go b/collector.go index 9b621ab9..931bcbb4 100644 --- a/collector.go +++ b/collector.go @@ -672,7 +672,6 @@ func indexOidsAsString(indexOids []int, typ string, fixedSize int, implied bool, case "EnumAsInfo": subOid, indexOids := splitOid(indexOids, 1) return enumValues[subOid[0]], subOid, indexOids - default: panic(fmt.Sprintf("Unknown index type %s", typ)) return "", nil, nil diff --git a/config/config.go b/config/config.go index a97f32f8..9d7379fd 100644 --- a/config/config.go +++ b/config/config.go @@ -185,7 +185,7 @@ type Index struct { Type string `yaml:"type"` FixedSize int `yaml:"fixed_size,omitempty"` Implied bool `yaml:"implied,omitempty"` - EnumValues map[int]string `yaml:"enum_values,omitempty"` + EnumValues map[int]string `yaml:"enum_values,omitempty"` } type Lookup struct { diff --git a/generator/tree_test.go b/generator/tree_test.go index 13fdeae7..feef7459 100644 --- a/generator/tree_test.go +++ b/generator/tree_test.go @@ -981,6 +981,57 @@ func TestGenerateConfigModule(t *testing.T) { }, }, }, + // Basic table with integer index and enum_values, overridden as EnumAsInfo. + { + node: &Node{Oid: "1", Label: "root", + Children: []*Node{ + {Oid: "1.1", Label: "table", + Children: []*Node{ + {Oid: "1.1.1", Label: "tableEntry", Indexes: []string{"tableIndex"}, + Children: []*Node{ + {Oid: "1.1.1.1", Access: "ACCESS_READONLY", Label: "tableIndex", Type: "INTEGER", EnumValues: map[int]string{0: "a"}}, + {Oid: "1.1.1.2", Access: "ACCESS_READONLY", Label: "tableFoo", Type: "INTEGER"}, + }}}}}}, + cfg: &ModuleConfig{ + Walk: []string{"1"}, + Overrides: map[string]MetricOverrides{ + "tableIndex": MetricOverrides{Type: "EnumAsInfo"}, + }, + }, + out: &config.Module{ + Walk: []string{"1"}, + Metrics: []*config.Metric{ + { + Name: "tableIndex", + Oid: "1.1.1.1", + Type: "EnumAsInfo", + Help: " - 1.1.1.1", + Indexes: []*config.Index{ + { + Labelname: "tableIndex", + Type: "EnumAsInfo", + EnumValues: map[int]string{0: "a"}, + }, + }, + EnumValues: map[int]string{0: "a"}, + }, + { + Name: "tableFoo", + Oid: "1.1.1.2", + Type: "gauge", + Help: " - 1.1.1.2", + Indexes: []*config.Index{ + { + Labelname: "tableIndex", + Type: "EnumAsInfo", + EnumValues: map[int]string{0: "a"}, + }, + }, + }, + }, + }, + }, + // One table lookup, lookup not walked, labels kept. { node: &Node{Oid: "1", Label: "root", From 025cc837e99630e3c6befd7bf81032dfc1dfc939 Mon Sep 17 00:00:00 2001 From: Frederic Van Espen Date: Mon, 31 Aug 2020 10:49:44 +0200 Subject: [PATCH 3/5] update snmp.yml Signed-off-by: Frederic Van Espen --- snmp.yml | 324 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 324 insertions(+) diff --git a/snmp.yml b/snmp.yml index 6e87b85d..f1f3f58e 100644 --- a/snmp.yml +++ b/snmp.yml @@ -3012,6 +3012,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 enum_values: 0: unknown 1: ipv4 @@ -3024,6 +3028,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsHCInReceives oid: 1.3.6.1.4.1.30065.3.1.1.1.1.4 type: counter @@ -3032,6 +3040,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsInOctets oid: 1.3.6.1.4.1.30065.3.1.1.1.1.5 type: counter @@ -3040,6 +3052,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsHCInOctets oid: 1.3.6.1.4.1.30065.3.1.1.1.1.6 type: counter @@ -3048,6 +3064,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsInHdrErrors oid: 1.3.6.1.4.1.30065.3.1.1.1.1.7 type: counter @@ -3057,6 +3077,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsInNoRoutes oid: 1.3.6.1.4.1.30065.3.1.1.1.1.8 type: counter @@ -3065,6 +3089,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsInAddrErrors oid: 1.3.6.1.4.1.30065.3.1.1.1.1.9 type: counter @@ -3074,6 +3102,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsInUnknownProtos oid: 1.3.6.1.4.1.30065.3.1.1.1.1.10 type: counter @@ -3082,6 +3114,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsInTruncatedPkts oid: 1.3.6.1.4.1.30065.3.1.1.1.1.11 type: counter @@ -3090,6 +3126,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsInForwDatagrams oid: 1.3.6.1.4.1.30065.3.1.1.1.1.12 type: counter @@ -3099,6 +3139,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsHCInForwDatagrams oid: 1.3.6.1.4.1.30065.3.1.1.1.1.13 type: counter @@ -3108,6 +3152,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsReasmReqds oid: 1.3.6.1.4.1.30065.3.1.1.1.1.14 type: counter @@ -3116,6 +3164,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsReasmOKs oid: 1.3.6.1.4.1.30065.3.1.1.1.1.15 type: counter @@ -3123,6 +3175,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsReasmFails oid: 1.3.6.1.4.1.30065.3.1.1.1.1.16 type: counter @@ -3131,6 +3187,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsInDiscards oid: 1.3.6.1.4.1.30065.3.1.1.1.1.17 type: counter @@ -3140,6 +3200,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsInDelivers oid: 1.3.6.1.4.1.30065.3.1.1.1.1.18 type: counter @@ -3148,6 +3212,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsHCInDelivers oid: 1.3.6.1.4.1.30065.3.1.1.1.1.19 type: counter @@ -3156,6 +3224,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsOutRequests oid: 1.3.6.1.4.1.30065.3.1.1.1.1.20 type: counter @@ -3164,6 +3236,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsHCOutRequests oid: 1.3.6.1.4.1.30065.3.1.1.1.1.21 type: counter @@ -3172,6 +3248,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsOutNoRoutes oid: 1.3.6.1.4.1.30065.3.1.1.1.1.22 type: counter @@ -3180,6 +3260,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsOutForwDatagrams oid: 1.3.6.1.4.1.30065.3.1.1.1.1.23 type: counter @@ -3189,6 +3273,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsHCOutForwDatagrams oid: 1.3.6.1.4.1.30065.3.1.1.1.1.24 type: counter @@ -3198,6 +3286,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsOutDiscards oid: 1.3.6.1.4.1.30065.3.1.1.1.1.25 type: counter @@ -3207,6 +3299,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsOutFragReqds oid: 1.3.6.1.4.1.30065.3.1.1.1.1.26 type: counter @@ -3215,6 +3311,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsOutFragOKs oid: 1.3.6.1.4.1.30065.3.1.1.1.1.27 type: counter @@ -3222,6 +3322,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsOutFragFails oid: 1.3.6.1.4.1.30065.3.1.1.1.1.28 type: counter @@ -3230,6 +3334,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsOutFragCreates oid: 1.3.6.1.4.1.30065.3.1.1.1.1.29 type: counter @@ -3238,6 +3346,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsOutTransmits oid: 1.3.6.1.4.1.30065.3.1.1.1.1.30 type: counter @@ -3246,6 +3358,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsHCOutTransmits oid: 1.3.6.1.4.1.30065.3.1.1.1.1.31 type: counter @@ -3254,6 +3370,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsOutOctets oid: 1.3.6.1.4.1.30065.3.1.1.1.1.32 type: counter @@ -3262,6 +3382,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsHCOutOctets oid: 1.3.6.1.4.1.30065.3.1.1.1.1.33 type: counter @@ -3270,6 +3394,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsInMcastPkts oid: 1.3.6.1.4.1.30065.3.1.1.1.1.34 type: counter @@ -3277,6 +3405,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsHCInMcastPkts oid: 1.3.6.1.4.1.30065.3.1.1.1.1.35 type: counter @@ -3284,6 +3416,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsInMcastOctets oid: 1.3.6.1.4.1.30065.3.1.1.1.1.36 type: counter @@ -3292,6 +3428,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsHCInMcastOctets oid: 1.3.6.1.4.1.30065.3.1.1.1.1.37 type: counter @@ -3300,6 +3440,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsOutMcastPkts oid: 1.3.6.1.4.1.30065.3.1.1.1.1.38 type: counter @@ -3307,6 +3451,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsHCOutMcastPkts oid: 1.3.6.1.4.1.30065.3.1.1.1.1.39 type: counter @@ -3314,6 +3462,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsOutMcastOctets oid: 1.3.6.1.4.1.30065.3.1.1.1.1.40 type: counter @@ -3322,6 +3474,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsHCOutMcastOctets oid: 1.3.6.1.4.1.30065.3.1.1.1.1.41 type: counter @@ -3330,6 +3486,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsInBcastPkts oid: 1.3.6.1.4.1.30065.3.1.1.1.1.42 type: counter @@ -3337,6 +3497,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsHCInBcastPkts oid: 1.3.6.1.4.1.30065.3.1.1.1.1.43 type: counter @@ -3344,6 +3508,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsOutBcastPkts oid: 1.3.6.1.4.1.30065.3.1.1.1.1.44 type: counter @@ -3351,6 +3519,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsHCOutBcastPkts oid: 1.3.6.1.4.1.30065.3.1.1.1.1.45 type: counter @@ -3358,6 +3530,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsDiscontinuityTime oid: 1.3.6.1.4.1.30065.3.1.1.1.1.46 type: gauge @@ -3366,6 +3542,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 - name: aristaSwFwdIpStatsRefreshRate oid: 1.3.6.1.4.1.30065.3.1.1.1.1.47 type: gauge @@ -3373,6 +3553,10 @@ arista_sw: indexes: - labelname: aristaSwFwdIpStatsIPVersion type: gauge + enum_values: + 0: unknown + 1: ipv4 + 2: ipv6 cisco_wlc: walk: - 1.3.6.1.2.1.2 @@ -7306,6 +7490,8 @@ keepalived: indexes: - labelname: vrrpInstanceIndex type: gauge + enum_values: + 0: static enum_values: 0: static - name: vrrpInstanceName @@ -7315,6 +7501,8 @@ keepalived: indexes: - labelname: vrrpInstanceIndex type: gauge + enum_values: + 0: static - name: vrrpInstanceVirtualRouterId oid: 1.3.6.1.4.1.9586.100.5.2.3.1.3 type: gauge @@ -7322,6 +7510,8 @@ keepalived: indexes: - labelname: vrrpInstanceIndex type: gauge + enum_values: + 0: static - name: vrrpInstanceState oid: 1.3.6.1.4.1.9586.100.5.2.3.1.4 type: gauge @@ -7329,6 +7519,8 @@ keepalived: indexes: - labelname: vrrpInstanceIndex type: gauge + enum_values: + 0: static enum_values: 0: init 1: backup @@ -7344,6 +7536,8 @@ keepalived: indexes: - labelname: vrrpInstanceIndex type: gauge + enum_values: + 0: static enum_values: 0: init 1: backup @@ -7359,6 +7553,8 @@ keepalived: indexes: - labelname: vrrpInstanceIndex type: gauge + enum_values: + 0: static enum_values: 0: init 1: backup @@ -7375,6 +7571,8 @@ keepalived: indexes: - labelname: vrrpInstanceIndex type: gauge + enum_values: + 0: static - name: vrrpInstanceEffectivePriority oid: 1.3.6.1.4.1.9586.100.5.2.3.1.8 type: gauge @@ -7382,6 +7580,8 @@ keepalived: indexes: - labelname: vrrpInstanceIndex type: gauge + enum_values: + 0: static - name: vrrpInstanceVipsStatus oid: 1.3.6.1.4.1.9586.100.5.2.3.1.9 type: gauge @@ -7389,6 +7589,8 @@ keepalived: indexes: - labelname: vrrpInstanceIndex type: gauge + enum_values: + 0: static enum_values: 1: allSet 2: notAllSet @@ -7399,6 +7601,8 @@ keepalived: indexes: - labelname: vrrpInstanceIndex type: gauge + enum_values: + 0: static - name: vrrpInstanceTrackPrimaryIf oid: 1.3.6.1.4.1.9586.100.5.2.3.1.11 type: gauge @@ -7406,6 +7610,8 @@ keepalived: indexes: - labelname: vrrpInstanceIndex type: gauge + enum_values: + 0: static enum_values: 1: tracked 2: notTracked @@ -7417,6 +7623,8 @@ keepalived: indexes: - labelname: vrrpInstanceIndex type: gauge + enum_values: + 0: static - name: vrrpInstancePreempt oid: 1.3.6.1.4.1.9586.100.5.2.3.1.13 type: gauge @@ -7424,6 +7632,8 @@ keepalived: indexes: - labelname: vrrpInstanceIndex type: gauge + enum_values: + 0: static enum_values: 1: preempt 2: noPreempt @@ -7435,6 +7645,8 @@ keepalived: indexes: - labelname: vrrpInstanceIndex type: gauge + enum_values: + 0: static - name: vrrpInstanceAuthType oid: 1.3.6.1.4.1.9586.100.5.2.3.1.15 type: gauge @@ -7442,6 +7654,8 @@ keepalived: indexes: - labelname: vrrpInstanceIndex type: gauge + enum_values: + 0: static enum_values: 0: none 1: password @@ -7454,6 +7668,8 @@ keepalived: indexes: - labelname: vrrpInstanceIndex type: gauge + enum_values: + 0: static - name: vrrpInstanceGarpDelay oid: 1.3.6.1.4.1.9586.100.5.2.3.1.19 type: gauge @@ -7461,6 +7677,8 @@ keepalived: indexes: - labelname: vrrpInstanceIndex type: gauge + enum_values: + 0: static - name: vrrpInstanceSmtpAlert oid: 1.3.6.1.4.1.9586.100.5.2.3.1.20 type: gauge @@ -7468,6 +7686,8 @@ keepalived: indexes: - labelname: vrrpInstanceIndex type: gauge + enum_values: + 0: static enum_values: 1: enabled 2: disabled @@ -7478,6 +7698,8 @@ keepalived: indexes: - labelname: vrrpInstanceIndex type: gauge + enum_values: + 0: static enum_values: 1: enabled 2: disabled @@ -7489,6 +7711,8 @@ keepalived: indexes: - labelname: vrrpInstanceIndex type: gauge + enum_values: + 0: static enum_values: 1: "true" 2: "false" @@ -7499,6 +7723,8 @@ keepalived: indexes: - labelname: vrrpInstanceIndex type: gauge + enum_values: + 0: static enum_values: 1: "true" 2: "false" @@ -7509,6 +7735,8 @@ keepalived: indexes: - labelname: vrrpInstanceIndex type: gauge + enum_values: + 0: static enum_values: 1: "true" 2: "false" @@ -7519,6 +7747,8 @@ keepalived: indexes: - labelname: vrrpInstanceIndex type: gauge + enum_values: + 0: static enum_values: 2: vrrpv2 3: vrrpv3 @@ -7529,6 +7759,8 @@ keepalived: indexes: - labelname: vrrpInstanceIndex type: gauge + enum_values: + 0: static - name: vrrpInstanceNotifyDeleted oid: 1.3.6.1.4.1.9586.100.5.2.3.1.33 type: gauge @@ -7537,6 +7769,8 @@ keepalived: indexes: - labelname: vrrpInstanceIndex type: gauge + enum_values: + 0: static enum_values: 1: "true" 2: "false" @@ -9074,10 +9308,20 @@ nec_ix: indexes: - labelname: pikePeerLocalType type: gauge + enum_values: + 1: idIpv4Addr + 2: idFqdn + 3: idDn + 4: idIpv6Addr - labelname: pikePeerLocalValue type: DisplayString - labelname: pikePeerRemoteType type: gauge + enum_values: + 1: idIpv4Addr + 2: idFqdn + 3: idDn + 4: idIpv6Addr - labelname: pikePeerRemoteValue type: DisplayString - labelname: pikePeerIntIndex @@ -9094,10 +9338,20 @@ nec_ix: indexes: - labelname: pikePeerLocalType type: gauge + enum_values: + 1: idIpv4Addr + 2: idFqdn + 3: idDn + 4: idIpv6Addr - labelname: pikePeerLocalValue type: DisplayString - labelname: pikePeerRemoteType type: gauge + enum_values: + 1: idIpv4Addr + 2: idFqdn + 3: idDn + 4: idIpv6Addr - labelname: pikePeerRemoteValue type: DisplayString - labelname: pikePeerIntIndex @@ -9109,10 +9363,20 @@ nec_ix: indexes: - labelname: pikePeerLocalType type: gauge + enum_values: + 1: idIpv4Addr + 2: idFqdn + 3: idDn + 4: idIpv6Addr - labelname: pikePeerLocalValue type: DisplayString - labelname: pikePeerRemoteType type: gauge + enum_values: + 1: idIpv4Addr + 2: idFqdn + 3: idDn + 4: idIpv6Addr - labelname: pikePeerRemoteValue type: DisplayString - labelname: pikePeerIntIndex @@ -9129,10 +9393,20 @@ nec_ix: indexes: - labelname: pikePeerLocalType type: gauge + enum_values: + 1: idIpv4Addr + 2: idFqdn + 3: idDn + 4: idIpv6Addr - labelname: pikePeerLocalValue type: DisplayString - labelname: pikePeerRemoteType type: gauge + enum_values: + 1: idIpv4Addr + 2: idFqdn + 3: idDn + 4: idIpv6Addr - labelname: pikePeerRemoteValue type: DisplayString - labelname: pikePeerIntIndex @@ -9144,10 +9418,20 @@ nec_ix: indexes: - labelname: pikePeerLocalType type: gauge + enum_values: + 1: idIpv4Addr + 2: idFqdn + 3: idDn + 4: idIpv6Addr - labelname: pikePeerLocalValue type: DisplayString - labelname: pikePeerRemoteType type: gauge + enum_values: + 1: idIpv4Addr + 2: idFqdn + 3: idDn + 4: idIpv6Addr - labelname: pikePeerRemoteValue type: DisplayString - labelname: pikePeerIntIndex @@ -9159,10 +9443,20 @@ nec_ix: indexes: - labelname: pikePeerLocalType type: gauge + enum_values: + 1: idIpv4Addr + 2: idFqdn + 3: idDn + 4: idIpv6Addr - labelname: pikePeerLocalValue type: DisplayString - labelname: pikePeerRemoteType type: gauge + enum_values: + 1: idIpv4Addr + 2: idFqdn + 3: idDn + 4: idIpv6Addr - labelname: pikePeerRemoteValue type: DisplayString - labelname: pikePeerIntIndex @@ -9174,10 +9468,20 @@ nec_ix: indexes: - labelname: pikePeerLocalType type: gauge + enum_values: + 1: idIpv4Addr + 2: idFqdn + 3: idDn + 4: idIpv6Addr - labelname: pikePeerLocalValue type: DisplayString - labelname: pikePeerRemoteType type: gauge + enum_values: + 1: idIpv4Addr + 2: idFqdn + 3: idDn + 4: idIpv6Addr - labelname: pikePeerRemoteValue type: DisplayString - labelname: pikePeerIntIndex @@ -9190,10 +9494,20 @@ nec_ix: indexes: - labelname: pikePeerLocalType type: gauge + enum_values: + 1: idIpv4Addr + 2: idFqdn + 3: idDn + 4: idIpv6Addr - labelname: pikePeerLocalValue type: DisplayString - labelname: pikePeerRemoteType type: gauge + enum_values: + 1: idIpv4Addr + 2: idFqdn + 3: idDn + 4: idIpv6Addr - labelname: pikePeerRemoteValue type: DisplayString - labelname: pikePeerIntIndex @@ -9206,10 +9520,20 @@ nec_ix: indexes: - labelname: pikePeerLocalType type: gauge + enum_values: + 1: idIpv4Addr + 2: idFqdn + 3: idDn + 4: idIpv6Addr - labelname: pikePeerLocalValue type: DisplayString - labelname: pikePeerRemoteType type: gauge + enum_values: + 1: idIpv4Addr + 2: idFqdn + 3: idDn + 4: idIpv6Addr - labelname: pikePeerRemoteValue type: DisplayString - labelname: pikePeerIntIndex From fd20382b1dcc913560ef0a8a49dd60829282e98c Mon Sep 17 00:00:00 2001 From: Frederic Van Espen Date: Mon, 31 Aug 2020 11:03:57 +0200 Subject: [PATCH 4/5] fall back to the value in case it's not listed in enum_values Signed-off-by: Frederic Van Espen --- collector.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/collector.go b/collector.go index 931bcbb4..8b705aa5 100644 --- a/collector.go +++ b/collector.go @@ -671,7 +671,12 @@ func indexOidsAsString(indexOids []int, typ string, fixedSize int, implied bool, return fmt.Sprintf("%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X", parts...), subOid, indexOids case "EnumAsInfo": subOid, indexOids := splitOid(indexOids, 1) - return enumValues[subOid[0]], subOid, indexOids + value, ok := enumValues[subOid[0]] + if ok { + return value, subOid, indexOids + } else { + return fmt.Sprintf("%d", subOid[0]), subOid, indexOids + } default: panic(fmt.Sprintf("Unknown index type %s", typ)) return "", nil, nil From 764b5fb24c18451c4e109962671cee3222b9a1d9 Mon Sep 17 00:00:00 2001 From: Frederic Van Espen Date: Mon, 31 Aug 2020 11:26:21 +0200 Subject: [PATCH 5/5] add collector tests Signed-off-by: Frederic Van Espen --- collector_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/collector_test.go b/collector_test.go index d4b1c4b5..22084953 100644 --- a/collector_test.go +++ b/collector_test.go @@ -887,6 +887,18 @@ func TestIndexesToLabels(t *testing.T) { oidToPdu: map[string]gosnmp.SnmpPDU{}, result: map[string]string{"l": "A "}, }, + { + oid: []int{0}, + metric: config.Metric{Indexes: []*config.Index{{Labelname: "l", Type: "EnumAsInfo", EnumValues: map[int]string{0: "foo", 1: "bar", 2: "baz"}}}}, + oidToPdu: map[string]gosnmp.SnmpPDU{}, + result: map[string]string{"l": "foo"}, + }, + { + oid: []int{3}, + metric: config.Metric{Indexes: []*config.Index{{Labelname: "l", Type: "EnumAsInfo", EnumValues: map[int]string{0: "foo", 1: "bar", 2: "baz"}}}}, + oidToPdu: map[string]gosnmp.SnmpPDU{}, + result: map[string]string{"l": "3"}, + }, { oid: []int{3, 65, 32, 255}, metric: config.Metric{