Giter Site home page Giter Site logo

Comments (7)

Guyverix avatar Guyverix commented on July 17, 2024

Did a var dump to assist in debugging this, and found this:

            [96] => FreeDSx\Snmp\Oid Object
                (
                    [oid:protected] => 1.3.6.1.2.1.92.1.3.1.1.3.7.100.101.102.97.117.108.116.1
                    [value:protected] => FreeDSx\Snmp\Value\StringValue Object
                        (
                            [value:protected] => �

6-
                        )

                    [status:protected] => 
                )

from snmp.

ChadSikorra avatar ChadSikorra commented on July 17, 2024

I imagine it gets mangled as the hex string represents some kind of binary output, and trying to echo that will not work very well. Though I have not worked much in this library since changing jobs and everything a couple times...hah. I would have to dig in more to see if I'm doing something wrong here in code.

from snmp.

Guyverix avatar Guyverix commented on July 17, 2024

If ( and it is a big if) I am reading the code correctly, the TAG_TYPE_OCTET_STRING = 0xFF; may be the culprit. I think I understand a little how to glued this together, and believe it needs a TAG_TYPE_HEX_STRING = 0x??; written that does not change the returned values.

Unfortunately I am still at the tinker-toy level when writing PHP, and not sure where else I can dig in here to assist more. It appears that your FreeDSx\Snmp\Value\StringValue file already has the value transformed when it receives it in the __construct function, and I am not really able to follow backwards more on this very well.

I THINK it is received from the FreeDSx\Asn1\Type\OctetStringType and that is what is mangling the value. Is there any way to simply make any untagged values simply return the string data from SNMP unaltered? I am assuming OCTET_STRING is a catchall since this type is actually identified as hex-STRING according to Net-SNMP output.

from snmp.

ChadSikorra avatar ChadSikorra commented on July 17, 2024

This is really a consequence of me not having MIB parsing / SMIv2 support in this library. How to interpret a hex string is determined by the MIB definition it came from. So this library is just throwing you the raw value without any assumptions about how to interpret it.

What is the value that is printed if, in this case, you wrapped the OID value in a bin2hex? ie:

echo bin2hex($oid->getValue());

Edit: For reference, the possible value types are defined in the RFC here -- https://datatracker.ietf.org/doc/html/rfc3416#section-2.5 . Been a while since I've worked on SNMP, so still trying to remember what I was doing here.

from snmp.

Guyverix avatar Guyverix commented on July 17, 2024

The bin2hex looks like it is translating the value back to a string correctly in the case of Hex-String

php ./pollerTest.php -h 192.168.15.58 -v 2 -c noyb -o 1.3.6.1.2.1.88.1.4.2.1.3.6.95.115.110.109.112.100.95.108.105.110.107.68.111.119.110
1.3.6.1.2.1.88.1.4.2.1.3.6.95.115.110.109.112.100.95.108.105.110.107.68.111.119.110 == �
bin2hex: 80

So the bin2hex returns what was expected for that value, but this one is also not returning as well and it is type Opaque?

php ./pollerTest.php -h 192.168.15.58 -v 2 -c noyb -o 1.3.6.1.4.1.2021.10.1.6.1
1.3.6.1.4.1.2021.10.1.6.1 == �x>\
bin2hex 9f78043ec28f5c
            [37] => FreeDSx\Snmp\Oid Object
                (
                    [oid:protected] => 1.3.6.1.4.1.2021.10.1.6.1
                    [value:protected] => FreeDSx\Snmp\Value\ArbitraryValue Object
                        (
                            [value:protected] => �x>��H
                        )

                    [status:protected] => 
                )
snmpwalk -v2c -c noyb 192.168.15.58 1.3.6.1.4.1.2021.10.1.6.1
iso.3.6.1.4.1.2021.10.1.6.1 = Opaque: Float: 0.230000

from snmp.

Guyverix avatar Guyverix commented on July 17, 2024

Is there a way to do some kind of fall through so that the raw data is simply returned without manipulation if it does not follow the mapped types?

from snmp.

ChadSikorra avatar ChadSikorra commented on July 17, 2024

Is there a way to do some kind of fall through so that the raw data is simply returned without manipulation if it does not follow the mapped types?

That's actually exactly what is happening in these cases :) The data you see on the console that looks malformed is just the string data in its raw, binary, form. This library is doing nothing to it.

If you're attempting to just print out all values to the console and don't want the output to get messed up then you're going to have to try to interpret the data in some way before printing it. One way would be to first check if the value has any non-printable characters (which could indicate a binary value of sorts) and if it does then parse it through bin2hex before dumping it to the console.

from snmp.

Related Issues (14)

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.