[snmp_exporter] OctetString , shown as Hex String to parse as int

I am struggling with the following issue:

diameterStackTotalSessionNbr OBJECT-TYPE
SYNTAX HpeTasLong
MAX-ACCESS read-only
STATUS current
DESCRIPTION “The total number of ProtocolSession(s) of the DiameterStack since service start, or last reset”
::= { diameterStackEntry 3 }

HpeTasLong is OctetString type

Here is the snmpwalk result:

SNMPv2-SMI::enterprises.47196.2.1.2.1.3.5.4.1.1.3.1.2.1.1 = Hex-STRING: 00 00 00 00 00 00 00 F1

When trying to override with gauge type it returns the following:

diameterStackTotalSessionNbr{diameterStackStackIdx=“1”,serverHostIdx=“1”,serverProgIdx=“2”,serviceServiceIdx=“1”} 0

For type: DisplayString + regex_replaces the metric is not displayed at all. But log shows:

level=debug ts=2022-06-02T12:34:48.856Z caller=collector.go:428 module=hpe_scp target= msg=“Error parsing float64 from value” metric=diameterStackTotalSessionNbr value="\u0000\u0000\u0000\u0000\u0000\u0000\u0001\u0016" regex=^(?:(.*))$ extracted_value="\u0000\u0000\u0000\u0000\u0000\u0000\u0001\u0016"

For type: OctetString the metric is displayed along with the label with hex value:

diameterStackTotalSessionNbr{diameterStackStackIdx=“1”,diameterStackTotalSessionNbr=“0x0000000000000116”,serverHostIdx=“1”,serverProgIdx=“2”,serviceServiceIdx=“1”} 1

after attempting to add regex_replaces - there is no metric and log shows:

level=debug ts=2022-06-02T12:38:54.999Z caller=collector.go:428 module=hpe_scp target= msg=“Error parsing float64 from value” metric=diameterStackTotalSessionNbr value=0x0000000000000116 regex=^(?:(.*))$ extracted_value=0x0000000000000116

Any suggestions?

In case if this is not yet supported and if any additional code change is required we might try to contribute conversion of such hex values with PR.

Thanks,
Gleb

This the help of a friend I was able to solve this.
The problem was exactly in the ParseFloat, or - to be more precise - in the format of the string snmp_exporter tried to parse. After quick checking of the go lang documentation of strconv.ParseFloat, strconv.FormatFloat, regex.Expand, regex.ExpandString and 1 hour in the go Playground I realized that

  1. the proper hex format of the String to be parsed as Float is 0x000000000000000016p+0. So “p+0” is the part I need to add to the end of the pduValue
    and
  2. regex.Value has to be adjusted accordingly: value: ${1}p+0. NOTE: ${1} (and not just $1) is important because regex considers variable name to be as long as possible ($1p+0 will consider variable $1p which doesn’t exist).

Summary:
For the OctetString type of MIB object which returns a Hex String the generated config has to look like:

  metrics:
  - name: diameterStackTotalSessionNbr
    oid: 1.3.6.1.4.1.47196.2.1.2.1.3.5.4.1.1.3
    type: OctetString
    help: help
    regex_extracts:
      '':
      - regex: (.*)
        value: ${1}p+0