Giter VIP home page Giter VIP logo

Comments (4)

toni-moreno avatar toni-moreno commented on June 5, 2024

Hello @matejv , I've reviewed the RFC where is defined this snmp type here ( https://datatracker.ietf.org/doc/html/rfc2578#section-7.1.7)

7.1.7.  Gauge32

   The Gauge32 type represents a non-negative integer, which may
   increase or decrease, but shall never exceed a maximum value, nor
   fall below a minimum value.  The maximum value can not be greater
   than 2^32-1 (4294967295 decimal), and the minimum value can not be
   smaller than 0.  The value of a Gauge32 has its maximum value
   whenever the information being modeled is greater than or equal to
   its maximum value, and has its minimum value whenever the information
   being modeled is smaller than or equal to its minimum value.  If the
   information being modeled subsequently decreases below (increases
   above) the maximum (minimum) value, the Gauge32 also decreases
   (increases).  (Note that despite of the use of the term "latched" in
   the original definition of this type, it does not become "stuck" at
   its maximum or minimum value.)

As you can read 4294967295 is 2^32-1 and a valid value , you should also note that Gauge32 represents a non-negative integer . ( 32 bits) so it seems like it can never be -1

regarding this information snmpcollector seems to be returning the correct value.

from snmpcollector.

matejv avatar matejv commented on June 5, 2024

Thank you @toni-moreno

I understand this. The problem is that the SNMP device I'm polling is returning data type wrong. It should not be Gauge32, but Integer32 (signed, to allow for negative values).

I'm unlikely to be able to get the vendor to fix their device unfortunately. So I thought SNMPcollector would be able to:

  • ignore the snmp type sent by the device and just take the raw bits of the value
  • interpret those raw bits as Integer32 type (that is a signed int, allowing negative values)

I was under the impression that setting DataSrcType to Integer32 would achieve this.

image

If may I ask - what do the different (SNMP SMI Type) *Integer* options actually do? If the value data type is determined by the snmp type sent by device. It doesn't seem to make any difference of I choose here Integer32 or UInteger32, if device sends Gauge32. Correct?

from snmpcollector.

toni-moreno avatar toni-moreno commented on June 5, 2024

Hello again @matejv , sorry for the late response.

Unfortunately for you snmpcollector doesn't force sign or size conversion , it handle data with its original type always .

you can see code yourself.

case "Counter32", "Gauge32", "Counter64", "TimeTicks", "UInteger32", "Unsigned32":
s.Convert = s.convertFromUInteger
if s.cfg.Scale != 0.0 || s.cfg.Shift != 0.0 {
s.Convert = s.convertFromFloat
}
s.SetRawData = func(pdu gosnmp.SnmpPDU, now time.Time) {
s.CookedValue = snmp.PduVal2UInt64(pdu)
s.CurTime = now
s.Scale()
s.Convert()
s.Valid = true
}

and here how to decode data.

func PduVal2UInt64(pdu gosnmp.SnmpPDU) uint64 {
value := pdu.Value
var val uint64
// revisar esta asignación
switch value := value.(type) { // shadow
case int:
val = uint64(value)
case int8:
val = uint64(value)
case int16:
val = uint64(value)
case int32:
val = uint64(value)
case int64:
val = uint64(value)
case uint:
val = uint64(value)
case uint8:
val = uint64(value)
case uint16:
val = uint64(value)
case uint32:
val = uint64(value)
case uint64:
val = uint64(value)
case string:
// for testing and other apps - numbers may appear as strings
var err error
if val, err = strconv.ParseUint(value, 10, 64); err != nil {
return val
}
default:
return 0
}
return val
}

and not sure if this policy should change in the future, because this would be a big breaking change.

instead you could create a new STRING EVAL field to force yourself conversion from the original , by only creating a evaluation expression like my_orig_field > 4294967295 ? ( 4294967295 - my_orig_field )

https://github.com/toni-moreno/snmpcollector/wiki/Component:-SNMP-Metrics#about-stringeval-metrics

Of course you don't need to send my_orig_field to the backend DB , you can choose not to send in the measurement configuration , choosing "never report" my_orig_field.
image

Let me know if this STRING EVAL new field would resolve your issue.

from snmpcollector.

matejv avatar matejv commented on June 5, 2024

I was looking at the code and I suspected as much, but I'm not really used to golang so I wanted to make sure.

I agree that changing current behavior might break stuff for many users, so best not to change it. In the end the fault lies in the buggy device I am using.

I did end up using your STRINGEVAL suggestion. I've done some maths and came up with a bit different formula:

(my_orig_field > 2147483647) ? (my_orig_field - 4294967294) : my_orig_field

2147483647 is the largest possible 32bit signed int. If we know we are operating with signed numbers, then any value larger than that must be negative. I've done some tests and checked results via this form also. If anyone else in the future will stumble across this issue.

Thany ou very much for your help and for creating this amazing tool. Best SNMP poller I've ever used!

from snmpcollector.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.