Giter VIP home page Giter VIP logo

Comments (10)

roe-dl avatar roe-dl commented on August 24, 2024

That is not a general issue. For example, the syslog messages for my UPS include real strings:

Mar 22 20:39:33 xxxx weewx[260440] INFO user.SNMP: SNMP-UPS SNMPv2-SMI::mib-2.33.1.1.1.0 = OctetString : "RPS SpA"
Mar 22 20:39:33 xxxx weewx[260440] INFO user.SNMP: SNMP-UPS SNMPv2-SMI::mib-2.33.1.1.2.0 = OctetString : "SDH 2200"

To convert the value to a string is the job of the prettyPrint() function of the pySNMP module. It is not in the scope of the weewx-SNMP extension. Are you sure you are using the latest version of pySNMP? Please check that first.

What does the snmpwalk command report for your device?

from weewx-snmp.

lyuxingliu avatar lyuxingliu commented on August 24, 2024

My pysnmp version is 4.4.12 and system use ubuntu 20.04LTS.
Package Version


certifi 2019.11.28
cffi 1.15.1
chardet 3.0.4
Cheetah3 3.2.6.post1
configobj 5.0.6
dbus-python 1.2.16
distro 1.4.0
ephem 3.7.7.1
idna 2.8
netifaces 0.10.4
olefile 0.46
Pillow 7.0.0
pip 20.0.2
ply 3.11
pyasn1 0.4.8
pycparser 2.21
pycryptodomex 3.17
pyephem 9.99
PyGObject 3.36.0
pymacaroons 0.13.0
PyNaCl 1.3.0
pyserial 3.4
pysmi 0.3.4
pysnmp 4.4.12
python-apt 2.0.1+ubuntu0.20.4.1
pyusb 1.0.2
PyYAML 5.3.1
requests 2.22.0
setuptools 45.2.0
six 1.14.0
snmp 0.4.2
ssh-import-id 5.10
thread6 0.2.0
ubuntu-advantage-tools 8001
urllib3 1.25.8
wheel 0.34.2

snmpwalk show:
iso.3.6.1.4.1.55062.1.13.2.0 = STRING: "LV 3K
"
it not OctetString.
and the pic is MibBrowser
image

from weewx-snmp.

roe-dl avatar roe-dl commented on August 24, 2024

I will see what I can do.

from weewx-snmp.

roe-dl avatar roe-dl commented on August 24, 2024

Could you check whether the version at https://github.com/roe-dl/weewx-snmp/archive/OctetString.zip changes something?

from weewx-snmp.

lyuxingliu avatar lyuxingliu commented on August 24, 2024

Almost perfect, just need to handle the line break symbols.

Mar 25 14:07:58 weewx weewx[1053] INFO user.SNMP: SNMP-SYSTEM SNMPv2-SMI::enterprises.55062.1.13.2.0 = OctetString : "LV 3K#012"

I have been recently trying to interactively install SNMP programs using apt and pip, in order to identify the possible differences between them.

from weewx-snmp.

roe-dl avatar roe-dl commented on August 24, 2024

I checked the pySNMP/pyASN1 code and found the following comment in pyasn1/type/univ.py where the type OctetString is defined:

    #
    # Normally, `.prettyPrint()` is called from `__str__()`. Historically,
    # OctetString.prettyPrint() used to return hexified payload
    # representation in cases when non-printable content is present. At the
    # same time `str()` used to produce either octet-stream (Py2) or
    # text (Py3) representations.
    #
    # Therefore `OctetString.__str__()` -> `.prettyPrint()` call chain is
    # reversed to preserve the original behaviour.
    #
    # Eventually we should deprecate `.prettyPrint()` / `.prettyOut()` harness
    # and end up with just `__str__()` producing hexified representation while
    # both text and octet-stream representation should only be requested via
    # the `.asOctets()` method.
    #
    # Note: ASN.1 OCTET STRING is never mean to contain text!
    #

    def prettyOut(self, value):
        return value

    def prettyPrint(self, scope=0):
        # first see if subclass has its own .prettyOut()
        value = self.prettyOut(self._value)

        if value is not self._value:
            return value

        numbers = self.asNumbers()

        for x in numbers:
            # hexify if needed
            if x < 32 or x > 126:
                return "0x" + "".join(("%.2x" % x for x in numbers))
        else:
            # this prevents infinite recursion
            return OctetString.__str__(self)

Imho the most important note there is "ASN.1 OCTET STRING is never mean to contain text!"

This may explain the strange behavior. And it makes it difficult to process values of OctetString in a portable way. I have to think about it.

from weewx-snmp.

roe-dl avatar roe-dl commented on August 24, 2024

What did you experience with the last changes?

from weewx-snmp.

lyuxingliu avatar lyuxingliu commented on August 24, 2024

I found that when SNMP strings contain line breaks "\r\n", there are problems with handling OctetString. Currently, I am trying to use str.strip() to remove non-standard characters and the display is normal.

from weewx-snmp.

roe-dl avatar roe-dl commented on August 24, 2024

Yes. As you see in the code snippet of the pySNMP module, values of type OctetString are displayed as characters if consist of printable characters only. If they contain at least one control character, they are displayed as hex codes.

Did you try the last version of weewx-SNMP from the OctetString branch?

If so I would like to merge the changes into the master branch and close this issue.

from weewx-snmp.

lyuxingliu avatar lyuxingliu commented on August 24, 2024

Sure, I've tried it. It works fine except for the line break characters.

from weewx-snmp.

Related Issues (1)

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.