Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inventory-provider
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
dashboardv3
inventory-provider
Commits
5bdc26e2
Commit
5bdc26e2
authored
4 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
use a ConnectionError instead of assertion for snmp i/o errors
parent
5f15bf0a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
inventory_provider/snmp.py
+18
-10
18 additions, 10 deletions
inventory_provider/snmp.py
with
18 additions
and
10 deletions
inventory_provider/snmp.py
+
18
−
10
View file @
5bdc26e2
...
...
@@ -10,6 +10,10 @@ from pysnmp.smi import builder, compiler
RFC1213_MIB_IFDESC
=
'
1.3.6.1.2.1.2.2.1.2
'
class
SNMPWalkError
(
ConnectionError
):
pass
def
_v6address_oid2str
(
dotted_decimal
):
hex_params
=
[]
for
dec
in
re
.
split
(
r
'
\.
'
,
dotted_decimal
):
...
...
@@ -61,15 +65,19 @@ def walk(agent_hostname, community, base_oid): # pragma: no cover
# cf. http://snmplabs.com/
# pysnmp/examples/hlapi/asyncore/sync/contents.html
assert
not
engineErrorIndication
,
(
f
'
snmp response engine error indication:
'
f
'
{
str
(
engineErrorIndication
)
}
-
{
agent_hostname
}
'
)
assert
not
pduErrorIndication
,
'
snmp response pdu error %r at %r
'
%
(
pduErrorIndication
,
errorIndex
and
varBinds
[
int
(
errorIndex
)
-
1
][
0
]
or
'
?
'
)
assert
errorIndex
==
0
,
(
'
sanity failure: errorIndex != 0,
'
'
but no error indication
'
)
if
engineErrorIndication
:
raise
SNMPWalkError
(
f
'
snmp response engine error indication:
'
f
'
{
str
(
engineErrorIndication
)
}
-
{
agent_hostname
}
'
)
if
pduErrorIndication
:
raise
SNMPWalkError
(
'
snmp response pdu error %r at %r
'
%
(
pduErrorIndication
,
errorIndex
and
varBinds
[
int
(
errorIndex
)
-
1
][
0
]
or
'
?
'
))
if
errorIndex
==
0
:
raise
SNMPWalkError
(
'
sanity failure: errorIndex != 0,
'
'
but no error indication
'
)
# varBinds = [
# rfc1902.ObjectType(rfc1902.ObjectIdentity(x[0]),x[1])
...
...
@@ -84,7 +92,7 @@ def walk(agent_hostname, community, base_oid): # pragma: no cover
def
get_router_snmp_indexes
(
hostname
,
community
):
for
ifc
in
walk
(
hostname
,
community
,
RFC1213_MIB_IFDESC
):
m
=
re
.
match
(
r
'
.*\.(\d+)$
'
,
ifc
[
'
oid
'
])
assert
m
,
'
sanity failure parsing oid:
%r
'
%
ifc
[
'
oid
'
]
assert
m
,
f
'
sanity failure parsing oid:
{
ifc
[
"
oid
"
]
}
'
yield
{
'
name
'
:
ifc
[
'
value
'
],
'
index
'
:
int
(
m
.
group
(
1
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment