Skip to main content

GoSNMP Python

Reason this release was yanked:

Errors in README

Project description

gosnmp-python

The purpose of this module is to provide a Python interface to the Golang gosnmp module.

It was made very easy with the help of the Golang gopy module.

Versions

This version (0.2.4) is the last version to support Python 2; all versions after this have been subject to a refactor and support Python 3 only.

Limitations

  • Python command needs to be prefixed with GODEBUG=cgocheck=0 (or have that in the environment)
  • I've not implemented walk (as I didn't need it for my use-case, I just use get_next with Python)
  • Seems to have some odd memory problems with PyPy (via CFFI); lots of locks and stuff to try and alleviate that

Prerequisites

  • Go 1.13
  • Python 2.7+
  • pip
  • virtualenvwrapper
  • pkgconfig/pkg-config

Installation (for prod)

  • python setup.py install

Making a python wheel install file (for distribution)

  • python setup.py bdist_wheel

Setup (for dev)

Ensure both go and pkg-config are installed.

  • mkvirtualenvwrapper -p (/path/to/pypy) gosnmp-python
  • pip install -r requirements-dev.txt
  • ./build.sh
  • GODEBUG=cgocheck=0 py.test -v

What's worth knowing if I want to further the development?

  • gopy doesn't like Go interfaces; so make sure you don't have any public (exported) interfaces
    • this includes a struct with a public property that may eventually lead to an interface

Example Go RPCSession usage (simple session ID, calls return JSON)

There's no real reason why you'd want to do this (just use gosnmp on it's own)- it's more for reference:

package main

import (
	"gosnmp_python"
	"fmt"
)

func main() {

	sessionID := gosnmp_python.NewRPCSessionV2c(
		"1.2.3.4",
		161,
		"public",
		5,
		1,
	)

	err := gosnmp_python.RPCConnect(sessionID)
	if err != nil {
		panic(err)
	}

	jsonResult, err := gosnmp_python.RPCGet(sessionID, ".1.3.6.1.2.1.1.5.0")
	if err != nil {
		panic(err)
	}

	fmt.Println(jsonResult)

	err = gosnmp_python.RPCClose(sessionID)
	if err != nil {
		panic(err)
	}

}

Example Python usage (uses RPCSession underneath because of memory leaks between Go and Python with structs)

To create an SNMPv2 session in Python do the following:

from gosnmp_python import create_snmpv2c_session

session = create_snmpv2c_session(
    hostname='1.2.3.4',
    community='public',
)

session.connect()

print session.get('.1.3.6.1.2.1.1.5.0')

session.close()

Which returns an object like this:

SNMPVariable(
    oid='.1.3.6.1.2.1.1.5', 
    oid_index=0, 
    snmp_type=u'bytearray', 
    value='hostname.domain.com.au'
)

Some of this may feel a bit like easysnmp; that's intentional, I was originally using that but I think its got some underlying thread-safety issues on the C side (particularly to do with SNMPv3).

No offence to the guys that contribute to that project- it's served me very well.

To use the test build container...

./test.sh

To shell into the test container to have a look around...

./test.sh bash

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gosnmp-python-0.9.tar.gz (2.5 MB view details)

Uploaded Source

File details

Details for the file gosnmp-python-0.9.tar.gz.

File metadata

  • Download URL: gosnmp-python-0.9.tar.gz
  • Upload date:
  • Size: 2.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.7.1 requests/2.26.0 setuptools/44.1.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/2.7.16

File hashes

Hashes for gosnmp-python-0.9.tar.gz
Algorithm Hash digest
SHA256 9e96b6240ddd2b6f8c91dfae7070d34847a1c4f96a30913c438184707bcecdc7
MD5 902dc39f2f6613f2c57928dde34ef9a7
BLAKE2b-256 137504cbe147c9ae8a18e989da292d519b65fcdd5bff5a8acb96fee000b6b89f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page