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

I'm trying to get information of some Printers using SNMP #464

Open
igorcarmona-git opened this issue Sep 9, 2024 · 3 comments
Open

I'm trying to get information of some Printers using SNMP #464

igorcarmona-git opened this issue Sep 9, 2024 · 3 comments

Comments

@igorcarmona-git
Copy link

Good afternoon!

I'm trying to get information from some printers using SNMP. I followed the steps in the official documentation, but when I run the code, it always says: "module 'pysnmp.hlapi' has no attribute 'getCmd'."

This is my code below:

import pysnmp.hlapi as hlapi

# OIDs Comuns
SerialNumber = '1.3.6.1.2.1.43.5.1.1.17.1'
totalPageCounter = '1.3.6.1.2.1.43.10.2.1.4.1.1'
tonerLevel = '1.3.6.1.2.1.43.11.1.1.9.1.1'

def get_snmp_data(ip, community, oid):
    for (errorIndication, errorStatus, errorIndex, varBinds) in hlapi.getCmd(
        hlapi.SnmpEngine(),
        hlapi.CommunityData(community, mpModel=0),  # mpModel=0 para SNMPv1 ou mpModel=1 para SNMPv2c
        hlapi.UdpTransportTarget((ip, 161)),
        hlapi.ContextData(),
        hlapi.ObjectType(hlapi.ObjectIdentity(oid))
    ):
        if errorIndication:
            print(f"Erro: {errorIndication}")
            return None
        elif errorStatus:
            print(f"Erro no status: {errorStatus.prettyPrint()} em {errorIndex}")
            return None
        else:
            for var_bind in varBinds:
                return var_bind[1].prettyPrint()

def main():
    print(get_snmp_data("192.168.1.150", "public", SerialNumber))

if __name__ == "__main__":
    main()

I'm using a Windows 10 system.
errorCode

@lextm
Copy link

lextm commented Sep 9, 2024

You must be reading some very old materials, as the latest releases 6.x/7.x have moved away completely from import pysnmp.hlapi as hlapi.

Please read about the latest status from #429 and this upgrade guide.

This repo is no longer in use, so new issues should go to https://github.com/lextudio/pysnmp/issues.

@igorcarmona-git
Copy link
Author

I tried to follow these steps on this page: https://pysnmp.readthedocs.io/en/latest/quick-start.html.
Was I in the wrong place?

@lextm
Copy link

lextm commented Sep 9, 2024

That's surely the wrong place and some random guy set it up with incorrect branch from Ilya's repo.

#429 covered that already.

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