Skip to content

Commit

Permalink
Merge pull request #46 from zenoss/release/0.43.0
Browse files Browse the repository at this point in the history
release/0.43.0
  • Loading branch information
Deer-WarLord authored Dec 13, 2024
2 parents 71f45c8 + 88b5a1b commit 99ffc99
Show file tree
Hide file tree
Showing 23 changed files with 1,508 additions and 463 deletions.
25 changes: 14 additions & 11 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
IMAGENAME = zenoss/build-tools
VERSION = 0.0.14
IMAGENAME = zenoss/zenpackbuild
VERSION = ubuntu2204-7
TAG = $(IMAGENAME):$(VERSION)

UID := $(shell id -u)
GID := $(shell id -g)

DOCKER_COMMAND = docker run --rm -v $(PWD):/mnt -w /mnt -u $(UID):$(GID) $(TAG)
DOCKER_COMMAND = docker run --rm -v $(PWD):/mnt -w /mnt $(TAG)

.DEFAULT_GOAL := build

.PHONY: bdist
bdist:
@$(DOCKER_COMMAND) bash -c "python setup.py bdist_wheel"
$(DOCKER_COMMAND) bash -c "python setup.py bdist_wheel"

.PHONY: sdist
sdist:
Expand All @@ -25,11 +25,14 @@ clean:
rm -rf *.pyc dist build pynetsnmp.egg-info

.PHONY: test
HOST ?= 127.0.0.1
test:
docker run --rm -v $(PWD):/mnt -w /mnt --user 0 $(TAG) \
bash -c "python setup.py bdist_wheel \
&& pip install dist/pynetsnmp*py2-none-any.whl ipaddr Twisted==20.3.0 \
&& cd test \
&& python test_runner.py --host $(HOST) \
&& chown -R $(UID):$(GID) /mnt" ;
@$(DOCKER_COMMAND) bash -c "pip --no-python-version-warning install -q .; cd tests; python -m unittest discover"

# HOST ?= 127.0.0.1
# test:
# docker run --rm -v $(PWD):/mnt -w /mnt $(TAG) \
# bash -c "python setup.py bdist_wheel \
# && pip install dist/pynetsnmp*py2-none-any.whl ipaddr Twisted==20.3.0 \
# && cd test \
# && python test_runner.py --host $(HOST) \
# && chown -R $(UID):$(GID) /mnt" ;
37 changes: 0 additions & 37 deletions pkg

This file was deleted.

6 changes: 3 additions & 3 deletions pynetsnmp/CONSTANTS.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NULL = 0
USM_LENGTH_OID_TRANSFORM = 10
NULL = None
MAX_CALLBACK_IDS = 2
MAX_CALLBACK_SUBIDS = 16
SNMP_CALLBACK_LIBRARY = 0
Expand Down Expand Up @@ -306,7 +306,8 @@
NETSNMP_CALLBACK_OP_SEND_FAILED = 3
NETSNMP_CALLBACK_OP_CONNECT = 4
NETSNMP_CALLBACK_OP_DISCONNECT = 5
snmp_init_statistics = ()
NETSNMP_CALLBACK_OP_RESEND = 6
NETSNMP_CALLBACK_OP_SEC_ERROR = 7
STAT_SNMPUNKNOWNSECURITYMODELS = 0
STAT_SNMPINVALIDMSGS = 1
STAT_SNMPUNKNOWNPDUHANDLERS = 2
Expand Down Expand Up @@ -377,7 +378,6 @@
MAX_STATS = NETSNMP_STAT_MAX_STATS
COMMUNITY_MAX_LEN = 256
SPRINT_MAX_LEN = 2560
NULL = 0
TRUE = 1
FALSE = 0
READ = 1
Expand Down
4 changes: 2 additions & 2 deletions pynetsnmp/SnmpSession.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import absolute_import

"""Backwards compatible API for SnmpSession"""

from __future__ import absolute_import

from . import netsnmp


Expand Down
29 changes: 27 additions & 2 deletions pynetsnmp/conversions.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
from __future__ import absolute_import

from ipaddr import IPAddress


def asOidStr(oid):
"""converts an oid int sequence to an oid string"""
return "." + ".".join([str(x) for x in oid])
return "." + ".".join(str(x) for x in oid)


def asOid(oidStr):
"""converts an OID string into a tuple of integers"""
return tuple([int(x) for x in oidStr.strip(".").split(".")])
return tuple(int(x) for x in oidStr.strip(".").split("."))


def asAgent(ip, port):
"""take a google ipaddr object and port number and produce a net-snmp
agent specification (see the snmpcmd manpage)"""
ip, interface = ip.split("%") if "%" in ip else (ip, None)
address = IPAddress(ip)

if address.version == 4:
return "udp:{}:{}".format(address.compressed, port)

if address.version == 6:
if address.is_link_local:
if interface is None:
raise RuntimeError(
"Cannot create agent specification from link local "
"IPv6 address without an interface"
)
else:
return "udp6:[{}%{}]:{}".format(
address.compressed, interface, port
)
return "udp6:[{}]:{}".format(address.compressed, port)
61 changes: 61 additions & 0 deletions pynetsnmp/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from __future__ import absolute_import

from . import oids


class SnmpTimeoutError(Exception):
pass


class ArgumentParseError(Exception):
pass


class TransportError(Exception):
pass


class SnmpNameError(Exception):
def __init__(self, oid):
Exception.__init__(self, "Bad Name", oid)


class SnmpError(Exception):
def __init__(self, message, *args, **kwargs):
self.message = message

def __str__(self):
return self.message

def __repr__(self):
return self.message


class SnmpUsmError(SnmpError):
pass


class SnmpUsmStatsError(SnmpUsmError):
def __init__(self, mesg, oid):
super(SnmpUsmStatsError, self).__init__(mesg)
self.oid = oid


_stats_oid_error_map = {
oids.WrongDigest: SnmpUsmStatsError(
"unexpected authentication digest", oids.WrongDigest
),
oids.UnknownUserName: SnmpUsmStatsError(
"unknown user", oids.UnknownUserName
),
oids.UnknownSecurityLevel: SnmpUsmStatsError(
"unknown or unavailable security level", oids.UnknownSecurityLevel
),
oids.DecryptionError: SnmpUsmStatsError(
"privacy decryption error", oids.DecryptionError
),
}


def get_stats_error(oid):
return _stats_oid_error_map.get(oid)
Loading

0 comments on commit 99ffc99

Please sign in to comment.