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

V3 support out of the box, identifier 3? #117

Open
srdjus opened this issue Jun 13, 2024 · 2 comments
Open

V3 support out of the box, identifier 3? #117

srdjus opened this issue Jun 13, 2024 · 2 comments

Comments

@srdjus
Copy link

srdjus commented Jun 13, 2024

I'm using Python 3.12 and I Installed puresnmp w/ puresnmp-crypto package. I already have V2 implementation and puresnmp is working as expected.

This is what I get when I try to run a get command on my SNMP v3 agent:

Got an exception: Namespace 'puresnmp_plugins.security' did not contain a plugin with identifier 3. Known identifiers: [0, 1, 2]. See the 'puresnmp' documentation on plugins.

I tried snmpwalk/snmpget from CLI, and it works. I am not sure if there is something else I have to configure in order to use V3? How do I include this identifier and where?

import asyncio
from puresnmp import PyWrapper, Client, V3
from puresnmp.credentials import Auth, Priv
 
credentials = V3(
    username="bootstrap",
    auth=Auth(b"temp_password", "md5"),
    priv=Priv(b"myprivphrase", "aes")
)

# Create a new client
client = PyWrapper(
    Client(
        ip="127.0.0.1",
        port=161,
        credentials=credentials
    )
)

try:
     output = await client.get("1.3.6.1.2.1.1.5.0")
     print(f"Sys name is: {output}")
except Exception as e:
     print(f"Got an exception: {e}")

UPDATE:
I solved it. I had to install typing-extensions package.

In puresnmp/plugins/pluginbase.py discover_plugins function 'puresnmp_plugins.security' module couldn't be found, ImportError was caught telling me I'm missing this package.

UPDATE 2:
Now I got like 10 new errors like
puresnmp_plugins.security.usm.EncryptionError: Unable to encrypt message (string argument without an encoding)
not sure if this is related, but I guess it has something to do with python/packages version/dependencies...

@Venkatesh416
Copy link

"Namespace 'puresnmp_plugins.mpm' did not contain a plugin with identifier 0. Known identifiers: []. See the 'puresnmp' documentation on plugins."

from puresnmp import Client, ObjectIdentifier as oid, credentials
oids = [oid('.1.3.6.1.2.1.33.1.3.3.1.3.1'),  # upsInputVoltage
                oid('.1.3.6.1.2.1.33.1.3.3.1.2.1'),  # input frequency.
                oid('.1.3.6.1.2.1.33.1.2.5.0'),  # battery voltage.
                oid('.1.3.6.1.2.1.33.1.2.7.0'),  # UPS Battery temperature
                oid('.1.3.6.1.2.1.33.1.2.4.0'),  # Battery capacity
                oid('.1.3.6.1.2.1.33.1.4.4.1.2.1'),  # upsOutputVoltage
                oid('.1.3.6.1.2.1.33.1.4.2.0'),  # output frequency
                oid('.1.3.6.1.2.1.33.1.4.4.1.5.1')  # ups load percentage
                ]

client = Client('172.16.2.101', credentials.V1("public"), port=161)
result1 = client.multiget(oids)
x = run(result1)
result = [0] * len(oids)
for j in range(len(oids)):
	xx = bytes(x[j])
	result[j] = int.from_bytes(xx[2:], byteorder="big", signed=True)

I'm having the above error after converting python file to .exe file using pyinstaller. But python program is executing through IDE" . Please suggest

@janipez
Copy link

janipez commented Dec 16, 2024

Having the same issue here.

When building with PyInstaller I need to manually include puresnmp by adding --collect-all puresnmp option, otherwise I get an error:

Traceback (most recent call last):
  File "main.py", line 2, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 384, in exec_module
  File "puresnmp\__init__.py", line 18, in <module>
  File "puresnmp\compatibility.py", line 14, in package_version
  File "importlib\metadata.py", line 569, in version
  File "importlib\metadata.py", line 542, in distribution
  File "importlib\metadata.py", line 196, in from_name
importlib.metadata.PackageNotFoundError: puresnmp

But even if I include puresnmp manually, I get the following error when running built executable:
Namespace 'puresnmp_plugins.mpm' did not contain a plugin with identifier 3. Known identifiers: []. See the 'puresnmp' documentation on plugins.

Perhaps there's something else I'd have to include manually?

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

3 participants