What is a good way to show a floating point number via SNMP?

后端 未结 3 1055
栀梦
栀梦 2021-01-05 05:26

I am coding an SNMP Agent. I need to send values that have a decimal point to an SNMP Manager.

I have a couple options:

  1. Truncate the number.
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-05 05:51

    The usual, standard way this is done is to define a TEXTUAL-CONVENTION with an integral type (such as Integer32 or Unsigned32) and a DISPLAY-HINT with "d-N" format, where N is the number of places the decimal should be shifted for display purposes.

    Thus, for a value with a single decimal place ranging from (say) 0.0 to 10.0, you would use a TEXTUAL-CONVENTION of type Unsigned32(0..100) and a DISPLAY-HINT of "d-1". On the wire, the value ranges from 0 to 100, but the manager (by way of the MIB module being loaded) will shift the decimal one place to display a range of 0.0 to 10.0.

    Other ways of doing it are not conducive to interoperability.

提交回复
热议问题