Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getRegistered(context) throws exception when OctetString is DateTime #44

Open
paulo-erichsen opened this issue Jun 9, 2020 · 1 comment

Comments

@paulo-erichsen
Copy link

I'm setting an OctetString as follows as an SNMP DateTime object

I'm not sure if the way I'm setting the DateTime is correct for SNMP, but when I do a snmpwalk, I'm able to see the variable just fine. Except the program blows up when I call dump_registered()

setup

import struct
import time

# setup the agent as in simple_agent.py example, then

time_millisecs = 1577836800000

# convert milliseconds to an OctetString
value = time.gmtime(time_millisecs / 1000)
value = struct.pack(
                            ">HBBBBBB",
                            value.tm_year,
                            value.tm_mon,
                            value.tm_mday,
                            value.tm_hour,
                            value.tm_min,
                            value.tm_sec,
                            0,
                        )
new_row.setRowCell(2, agent.OctetString(value))

# the above is fine, but it then blows up when the following is called
dump_registered(agent)

stacktrace

Traceback (most recent call last):
  File "./snmp_agent.py", line 465, in <module>
    main()
  File "./snmp_agent.py", line 435, in main
    dump_registered(agent)
  File "./snmp_agent.py", line 342, in dump_registered
    variables = agent.getRegistered(context)
  File "~/my_venv/lib/python3.8/site-packages/netsnmpagent.py", line 949, in getRegistered
    "value": snmpobj.value()
  File "~/my_venv/lib/python3.8/site-packages/netsnmpagent.py", line 895, in value
    retdict[indices][int(data.contents.column)] = u(ctypes.string_at(data.contents.data.string, data.contents.data_len))
  File "~/my_venv/lib/python3.8/site-packages/netsnmpagent.py", line 51, in u
    return s if isinstance("Test", bytes) else s.decode(locale.getpreferredencoding())
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 1: invalid continuation byte
Exception ignored in: <module 'threading' from '/usr/lib/python3.8/threading.py'>
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 1388, in _shutdown
    lock.acquire()
KeyboardInterrupt: 
* Cleaning up...
@kgraefe
Copy link
Contributor

kgraefe commented Jul 13, 2020

This has been addressed in #40.

@pief You may want to make a new release? The latest release is quite behind the master branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants