How convert OCTET STRING to FLOAT?

503 views
Skip to first unread message

konst...@mironovs.com

unread,
Nov 10, 2018, 4:07:03 PM11/10/18
to Prometheus Users
Hello.

I have OCTET STRING OID's like this:

rptPaTemprature OBJECT-TYPE
    SYNTAX  OCTET STRING
(SIZE(4))
    MAX
-ACCESS read-only
    STATUS  mandatory
    DESCRIPTION
       
"The temperature.
         It should be changed to float format.
         The value is invalid, if the repeater is rd960."

   
-- 1.3.6.1.4.1.40297.1.2.1.2.2
   
::= { rptDataInfo 2 }

How I can collect this OID to Prometheus?

# snmpwalk -v 1 -c public -m HYTERA-REPEATER-MIB 192.168.88.190 HYTERA-REPEATER-MIB::rptPaTemprature.0
HYTERA
-REPEATER-MIB::rptPaTemprature.0 = Hex-STRING: 00 00 C0 41


Ben Kochie

unread,
Nov 10, 2018, 6:24:11 PM11/10/18
to konst...@mironovs.com, Prometheus Users
That looks like it needs to be converted to a 32-bit float.

generator.yml:

modules:
  hytera:
    walk:
    - rptPaTemprature
    overrides:
      rptPaTemprature:
        type: Float

snmp.yml:

hytera:
  get:
  - 1.3.6.1.4.1.40297.1.2.1.2.2.0
  metrics:
  - name: rptPaTemprature
    oid: 1.3.6.1.4.1.40297.1.2.1.2.2
    type: Float
    help: The temperature - 1.3.6.1.4.1.40297.1.2.1.2.2


--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To post to this group, send email to promethe...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/2d222ff7-387d-44e5-9737-5ccd23bf0306%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

konst...@mironovs.com

unread,
Nov 11, 2018, 3:20:21 AM11/11/18
to Prometheus Users
Thank you!

I can make snmp.conf without snmp-generator? Place to snmp.conf this:

hytera:
  get:
  - 1.3.6.1.4.1.40297.1.2.1.2.2.0
  metrics:
  - name: rptPaTemprature
    oid: 1.3.6.1.4.1.40297.1.2.1.2.2
    type: Float
    help: The temperature - 1.3.6.1.4.1.40297.1.2.1.2.2



воскресенье, 11 ноября 2018 г., 0:07:03 UTC+3 пользователь konst...@mironovs.com написал:

konst...@mironovs.com

unread,
Nov 11, 2018, 4:32:30 AM11/11/18
to Prometheus Users
I try make config:

hytera:
  version: 1
  auth:
    community: public
  get:
  - 1.3.6.1.4.1.40297.1.2.1.2.2.0
  metrics:
  - name: rptPaTemprature
    oid: 1.3.6.1.4.1.40297.1.2.1.2.2
    type: Float
    help: The temperature - 1.3.6.1.4.1.40297.1.2.1.2.2

But can't take right temperature:


# HELP rptPaTemprature The temperature - 1.3.6.1.4.1.40297.1.2.1.2.2
# TYPE rptPaTemprature gauge
rptPaTemprature 0
# HELP snmp_scrape_duration_seconds Total SNMP time scrape took (walk and processing).
# TYPE snmp_scrape_duration_seconds gauge
snmp_scrape_duration_seconds 0.005580182
# HELP snmp_scrape_pdus_returned PDUs returned from walk.
# TYPE snmp_scrape_pdus_returned gauge
snmp_scrape_pdus_returned 1
# HELP snmp_scrape_walk_duration_seconds Time SNMP walk/bulkwalk took.
# TYPE snmp_scrape_walk_duration_seconds gauge
snmp_scrape_walk_duration_seconds 0.005494467

What is wrong?


воскресенье, 11 ноября 2018 г., 11:20:21 UTC+3 пользователь konst...@mironovs.com написал:

Ben Kochie

unread,
Nov 11, 2018, 4:51:53 AM11/11/18
to Константин Миронов, Prometheus Users
What happens if you replace "Float" with "DisplayString"?

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To post to this group, send email to promethe...@googlegroups.com.

Константин Миронов

unread,
Nov 11, 2018, 4:58:10 AM11/11/18
to Prometheus Users
If I change type to DisplayString then downloaded file snmp.dms with content:

2320 4845 4c50 2072 7074 5061 5465 6d70
7261 7475 7265 2054 6865 2074 656d 7065
7261 7475 7265 202d 2031 2e33 2e36 2e31
2e34 2e31 2e34 3032 3937 2e31 2e32 2e31
2e32 2e32 0a23 2054 5950 4520 7270 7450
6154 656d 7072 6174 7572 6520 6761 7567
650a 7270 7450 6154 656d 7072 6174 7572
657b 7270 7450 6154 656d 7072 6174 7572
653d 2200 0060 4122 7d20 310a 2320 4845
4c50 2073 6e6d 705f 7363 7261 7065 5f64
7572 6174 696f 6e5f 7365 636f 6e64 7320
546f 7461 6c20 534e 4d50 2074 696d 6520
7363 7261 7065 2074 6f6f 6b20 2877 616c
6b20 616e 6420 7072 6f63 6573 7369 6e67
292e 0a23 2054 5950 4520 736e 6d70 5f73
6372 6170 655f 6475 7261 7469 6f6e 5f73
6563 6f6e 6473 2067 6175 6765 0a73 6e6d
705f 7363 7261 7065 5f64 7572 6174 696f
6e5f 7365 636f 6e64 7320 302e 3031 3239
3631 3138 370a 2320 4845 4c50 2073 6e6d
705f 7363 7261 7065 5f70 6475 735f 7265
7475 726e 6564 2050 4455 7320 7265 7475
726e 6564 2066 726f 6d20 7761 6c6b 2e0a
2320 5459 5045 2073 6e6d 705f 7363 7261
7065 5f70 6475 735f 7265 7475 726e 6564
2067 6175 6765 0a73 6e6d 705f 7363 7261
7065 5f70 6475 735f 7265 7475 726e 6564
2031 0a23 2048 454c 5020 736e 6d70 5f73
6372 6170 655f 7761 6c6b 5f64 7572 6174
696f 6e5f 7365 636f 6e64 7320 5469 6d65
2053 4e4d 5020 7761 6c6b 2f62 756c 6b77
616c 6b20 746f 6f6b 2e0a 2320 5459 5045
2073 6e6d 705f 7363 7261 7065 5f77 616c
6b5f 6475 7261 7469 6f6e 5f73 6563 6f6e
6473 2067 6175 6765 0a73 6e6d 705f 7363
7261 7065 5f77 616c 6b5f 6475 7261 7469
6f6e 5f73 6563 6f6e 6473 2030 2e30 3132
3738 3138 3135 0a

воскресенье, 11 ноября 2018 г., 12:51:53 UTC+3 пользователь Ben Kochie написал:

Brian Brazil

unread,
Nov 11, 2018, 6:21:44 AM11/11/18
to konst...@mironovs.com, promethe...@googlegroups.com
It looks like it's exposing it with the wrong endianness.

Brian
 

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To post to this group, send email to promethe...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Константин Миронов

unread,
Nov 11, 2018, 6:43:26 AM11/11/18
to Prometheus Users
Are there any solutions?

воскресенье, 11 ноября 2018 г., 14:21:44 UTC+3 пользователь Brian Brazil написал:

Ben Kochie

unread,
Nov 11, 2018, 7:01:14 AM11/11/18
to Константин Миронов, Prometheus Users
In theory, we could add a special override for this conversion.

Константин Миронов

unread,
Nov 11, 2018, 7:04:03 AM11/11/18
to Prometheus Users
Can I do this or should make changes to the code?

воскресенье, 11 ноября 2018 г., 15:01:14 UTC+3 пользователь Ben Kochie написал:

Ben Kochie

unread,
Nov 11, 2018, 9:55:33 AM11/11/18
to Константин Миронов, Prometheus Users
This would require changes to the code.

If you're interested in making the code change, you're welcome to send us a PR on GitHub.

Brian Brazil

unread,
Nov 11, 2018, 9:56:00 AM11/11/18
to Ben Kochie, konst...@mironovs.com, promethe...@googlegroups.com
On Sun, 11 Nov 2018 at 12:01, Ben Kochie <sup...@gmail.com> wrote:
In theory, we could add a special override for this conversion.

This one is handled by the SNMP client though.

Brian
 

For more options, visit https://groups.google.com/d/optout.

Константин Миронов

unread,
Nov 12, 2018, 12:54:47 AM11/12/18
to Prometheus Users
Sorry, but I'm not a programmer :(

воскресенье, 11 ноября 2018 г., 17:55:33 UTC+3 пользователь Ben Kochie написал:

Константин Миронов

unread,
Nov 12, 2018, 5:14:42 PM11/12/18
to Prometheus Users
This not standard OID? Why not working change type?

воскресенье, 11 ноября 2018 г., 17:56:00 UTC+3 пользователь Brian Brazil написал:

Глеб Коньтяков

unread,
Jun 2, 2022, 1:52:15 PM6/2/22
to Prometheus Users
Hi!
Was this resolved?
I am struggling with the apparently similar 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=10.223.5.112:161 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=10.223.5.112:161 msg="Error parsing float64 from value" metric=diameterStackTotalSessionNbr value=0x0000000000000116 regex=^(?:(.*))$ extracted_value=0x0000000000000116

Any suggestions?
I saw that for andrewd-sterling the approach worked and hex value became a String https://github.com/prometheus/snmp_exporter/issues/186#issuecomment-389914695. But probably this is just because snmp originally returned this value as STRING...

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

вторник, 13 ноября 2018 г. в 02:14:42 UTC+4, Константин Миронов:

Глеб Коньтяков

unread,
Jun 9, 2022, 6:53:40 AM6/9/22
to Prometheus Users
I was able to solve the issue. Described in https://discuss.prometheus.io/t/snmp-exporter-octetstring-shown-as-hex-string-to-parse-as-int/1032

четверг, 2 июня 2022 г. в 21:52:15 UTC+4, Глеб Коньтяков:
Reply all
Reply to author
Forward
0 new messages