Skip to content

Commit

Permalink
Allowed OIDs to be specified without a leading zero (fixes #15)
Browse files Browse the repository at this point in the history
  • Loading branch information
fgimian committed Jun 12, 2015
1 parent 7eb0aa5 commit 4571bf4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
12 changes: 6 additions & 6 deletions easysnmp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
# This regular expression is used to extract the index from an OID
OID_INDEX_RE = re.compile(
r'''(
(?:\.\d+)+ # numeric OID
| # or
(?:\w+(?:[-:]*\w+)+) # regular OID
| # or
(?:\.iso(?:\.\w+[-:]*\w+)+) # fully qualified OID
\.?\d+(?:\.\d+)* # numeric OID
| # or
(?:\w+(?:[-:]*\w+)+) # regular OID
| # or
(?:\.?iso(?:\.\w+[-:]*\w+)+) # fully qualified OID
)
\.?(.*) # OID index
\.?(.*) # OID index
''',
re.VERBOSE
)
Expand Down
24 changes: 24 additions & 0 deletions tests/test_easy.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,30 @@ def test_snmp_get_fully_qualified_tuple(sess_args):
'sess_args', [sess_v1_args(), sess_v2_args(), sess_v3_args()]
)
def test_snmp_get_numeric(sess_args):
res = snmp_get('.1.3.6.1.2.1.1.1.0', **sess_args)

assert platform.version() in res.value
assert res.oid == 'sysDescr'
assert res.oid_index == '0'
assert res.snmp_type == 'OCTETSTR'


@pytest.mark.parametrize(
'sess_args', [sess_v1_args(), sess_v2_args(), sess_v3_args()]
)
def test_snmp_get_numeric_no_leading_dot(sess_args):
res = snmp_get('1.3.6.1.2.1.1.1.0', **sess_args)

assert platform.version() in res.value
assert res.oid == 'sysDescr'
assert res.oid_index == '0'
assert res.snmp_type == 'OCTETSTR'


@pytest.mark.parametrize(
'sess_args', [sess_v1_args(), sess_v2_args(), sess_v3_args()]
)
def test_snmp_get_numeric_tuple(sess_args):
res = snmp_get(('.1.3.6.1.2.1.1.1', '0'), **sess_args)

assert platform.version() in res.value
Expand Down

0 comments on commit 4571bf4

Please sign in to comment.