@cryptotaxi247 / netdata-1 / commits / dcf507fa7

improve(go.d/snmp-profiles): extend transformEntitySensorValue (#20594)

Ilya Mashchenko committed Jun 29, 2025 at 12:36 UTC dcf507fa7551126262ca652b057eb8ce6b8bbd8b
3 files changed +71 -34
src/go/plugin/go.d/collector/snmp/ddsnmp/transform.go
+36 -21
@@ -140,28 +140,30 @@ func newMetricTransformFuncMap() template.FuncMap {
140 "pow": func(base float64, exp int) float64 {
141 return math.Pow(base, float64(exp))
142 },
143 - "transformEntPhySensor": func(m *Metric) string {
143 + "transformEntitySensorValue": func(m *Metric) string {
144 /*
145 - transformEntPhySensor applies standardized normalization to metrics
146 - from the ENTITY-SENSOR-MIB's entPhySensorTable:
145 + transformEntitySensorValue normalizes metrics from ENTITY-SENSOR-MIB and
146 + CISCO-ENTITY-SENSOR-MIB.
147
148 - OID base: .1.3.6.1.2.1.99.1.1
149 - Spec: https://datatracker.ietf.org/doc/html/rfc3433
150 - Applies to: entPhySensorValue (.1.3.6.1.2.1.99.1.1.1.4)
148 + Supported MIBs:
149 + - ENTITY-SENSOR-MIB (RFC 3433): .1.3.6.1.2.1.99.1.1
150 + - CISCO-ENTITY-SENSOR-MIB: .1.3.6.1.4.1.9.9.91.1.1.1
151
152 - Uses the following tags:
153 - - sensor_type (entPhySensorType: integer value 1–12)
154 - - sensor_scale (entPhySensorScale: integer value 1–14)
155 - - sensor_precision (entPhySensorPrecision: integer)
152 + Expected metric:
153 + - entPhySensorValue / entSensorValue: .*.1.4
154
157 - This function:
158 - - Assigns proper name, unit, family, description
159 - - Applies scaling using sensor_scale and sensor_precision
160 - - Optionally maps values to human-readable labels (e.g., "true"/"false")
155 + Required metric tags:
156 + - sensor_type (entPhySensorType / entSensorType)
157 + - sensor_scale (entPhySensorScale / entSensorScale)
158 + - sensor_precision (entPhySensorPrecision / entSensorPrecision)
159
162 - This supports multiple vendors implementing ENTITY-SENSOR-MIB:
163 - Cisco, Juniper, HPE, Dell, Supermicro, etc.
160 + What it does:
161 + - Sets a descriptive name, unit, family, and description
162 + - Applies scaling using sensor_scale and sensor_precision
163 + - Applies value mappings for boolean/enumerated types
164 + - Works across vendors (Cisco, Juniper, HPE, Dell, etc.)
165 */
166 +
167 sensorType := m.Tags["sensor_type"]
168 sensorScale := m.Tags["sensor_scale"]
169 sensorPrecision := m.Tags["sensor_precision"]
@@ -187,16 +189,29 @@ func newMetricTransformFuncMap() template.FuncMap {
189 "12": {"name": "sensor_state", "family": "Status", "desc": "Boolean sensor state", "mapping": map[int64]string{
190 0: "false", 1: "true", 2: "true",
191 }},
192 + "13": {"name": "special_enum", "family": "Status", "desc": "Vendor-specific enumerated sensor"},
193 + "14": {"name": "power_dbm", "unit": "dBm", "family": "Power", "desc": "Power in decibel-milliwatts"},
194 }
195
196 scaleMap := map[string]float64{
193 - "1": 1.0, "2": 0.001, "3": 0.000001, "4": 0.000000001,
194 - "5": 0.000000000001, "6": 0.000000000000001, "7": 0.000000000000000001,
195 - "8": 0.000000000000000000001, "9": 0.000000000000000000000001,
196 - "10": 0.1, "11": 0.01, "12": 1000.0, "13": 1000000.0, "14": 1000000000.0,
197 + "1": 1e-24, // yocto (10^-24)
198 + "2": 1e-21, // zepto (10^-21)
199 + "3": 1e-18, // atto (10^-18)
200 + "4": 1e-15, // femto (10^-15)
201 + "5": 1e-12, // pico (10^-12)
202 + "6": 1e-9, // nano (10^-9)
203 + "7": 1e-6, // micro (10^-6)
204 + "8": 1e-3, // milli (10^-3)
205 + "9": 1, // units (10^0)
206 + "10": 1e3, // kilo (10^3)
207 + "11": 1e6, // mega (10^6)
208 + "12": 1e9, // giga (10^9)
209 + "13": 1e12, // tera (10^12)
210 }
211 +
212 scale := scaleMap[sensorScale]
199 - if scale == 0 {
213 + if scale == 0 || scale == 1e-24 {
214 + // Workaround for Cisco ASA (MIMIC) temperature bug: treat scale=1 (yocto) as units
215 scale = 1.0
216 }
217
src/go/plugin/go.d/config/go.d/snmp.profiles/default/_cisco-asa.yaml
+13 -7
@@ -132,8 +132,20 @@ metrics:
132 unit: "1"
133 family: Sensor/Value
134 transform: |
135 - {{- transformEntPhySensor .Metric -}}
135 + {{- transformEntitySensorValue .Metric -}}
136 metric_tags:
137 + - tag: sensor_index
138 + index: 1
139 + - tag: _ent_phys_descr
140 + MIB: ENTITY-MIB
141 + table: entPhysicalTable
142 + symbol:
143 + OID: 1.3.6.1.2.1.47.1.1.1.1.2
144 + name: entPhysicalDescr
145 + - tag: _sensor_desc
146 + symbol:
147 + OID: 1.3.6.1.2.1.99.1.1.1.6
148 + name: entPhySensorUnitsDisplay
149 - tag: sensor_type # needed for transform
150 symbol:
151 OID: 1.3.6.1.2.1.99.1.1.1.1
@@ -146,9 +158,3 @@ metrics:
158 symbol:
159 OID: 1.3.6.1.2.1.99.1.1.1.3
160 name: entPhySensorPrecision
149 - - tag: _sensor_desc
150 - symbol:
151 - OID: 1.3.6.1.2.1.99.1.1.1.6
152 - name: entPhySensorUnitsDisplay
153 - - tag: sensor_id
154 - index: 1
src/go/plugin/go.d/config/go.d/snmp.profiles/default/_cisco-catalyst.yaml
+22 -6
@@ -20,23 +20,39 @@ metadata:
20 name: chassisSerialNumberString
21
22 metrics:
23 - - MIB: CISCO-ENTITY-SENSOR-MIB # TODO: sensors of different types in one chart, transformation required
23 + - MIB: CISCO-ENTITY-SENSOR-MIB # TODO: this is not Catalyst-specific, need to add to other Cisco devices
24 table:
25 OID: 1.3.6.1.4.1.9.9.91.1.1.1
26 name: entSensorValueTable
27 symbols:
28 - OID: 1.3.6.1.4.1.9.9.91.1.1.1.1.4
29 name: entSensorValue
30 - description: "The most recent measurement seen by the sensor"
31 - family: Sensors
30 + description: Most recent measurement obtained by the agent for this sensor
31 unit: "1"
32 + family: Sensor/Value
33 + transform: |
34 + {{- transformEntitySensorValue .Metric -}}
35 metric_tags:
34 - - tag: sensor_type
36 + - tag: sensor_index
37 + index: 1
38 + - tag: _ent_phys_descr
39 + MIB: ENTITY-MIB
40 + table: entPhysicalTable
41 + symbol:
42 + OID: 1.3.6.1.2.1.47.1.1.1.1.2
43 + name: entPhysicalDescr
44 + - tag: sensor_type # needed for transform
45 symbol:
46 OID: 1.3.6.1.4.1.9.9.91.1.1.1.1.1
47 name: entSensorType
38 - - tag: sensor_id
39 - index: 1
48 + - tag: sensor_scale # needed for transform
49 + symbol:
50 + OID: 1.3.6.1.4.1.9.9.91.1.1.1.1.2
51 + name: entSensorScale
52 + - tag: sensor_precision # needed for transform
53 + symbol:
54 + OID: 1.3.6.1.4.1.9.9.91.1.1.1.1.3
55 + name: entSensorPrecision
56 - MIB: CISCO-IF-EXTENSION-MIB # TODO: this is not Catalyst-specific, need to add to other Cisco devices
57 table:
58 OID: 1.3.6.1.4.1.9.9.276.1.1.1