Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tango
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
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
LOFAR2.0
tango
Commits
fd7ecb8e
Commit
fd7ecb8e
authored
3 years ago
by
Taya Snijder
Browse files
Options
Downloads
Patches
Plain Diff
added named_value support
parent
3e8f6d64
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!288
Resolve L2SS-446 "Extend snmp client to support mib files"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tangostationcontrol/tangostationcontrol/clients/snmp_client.py
+28
-8
28 additions, 8 deletions
...stationcontrol/tangostationcontrol/clients/snmp_client.py
with
28 additions
and
8 deletions
tangostationcontrol/tangostationcontrol/clients/snmp_client.py
+
28
−
8
View file @
fd7ecb8e
...
...
@@ -111,7 +111,7 @@ class SNMP_client(CommClient):
def
load_mib
(
mib_name
):
mibBuilder
=
builder
.
MibBuilder
()
mibBuilder
.
loadModule
(
mib_name
)
class
snmp_attribute
:
...
...
@@ -200,19 +200,39 @@ class snmp_attribute:
varBinds
=
varBinds
[
0
]
for
varBind
in
varBinds
:
# class 'DisplayString' doesnt want to play along for whatever reason
if
"
DisplayString
"
in
str
(
type
(
varBind
[
1
])):
vals
.
append
(
varBind
[
1
].
prettyPrint
())
elif
type
(
varBind
[
1
])
==
hlapi
.
IpAddress
:
# Get all the types. Custom and base. Custom types are merely wrapped base types.
varbind_types
=
varBind
[
1
].
__class__
.
__bases__
+
(
type
(
varBind
[
1
]),)
snmp_type
=
None
for
i
in
varbind_types
:
if
i
in
snmp_to_numpy_dict
.
keys
():
snmp_type
=
i
if
snmp_type
is
None
:
TypeError
(
f
"
Error: did not find a valid snmp type. Got:
{
varbind_types
}
, expected one of:
{
snmp_to_numpy_dict
.
keys
()
}
"
)
if
snmp_type
==
hlapi
.
IpAddress
:
# IpAddress values get printed as their raw value but in hex (7F 20 20 01 for 127.0.0.1 for example)
vals
.
append
(
varBind
[
1
].
prettyPrint
())
elif
snmp_type
==
hlapi
.
Integer32
and
self
.
dtype
==
str
:
# Integers can have 'named values', Where a value can be translated to a specific name. A dict basically
# Example: {1: "other", 2: "invalid", 3: "dynamic", 4: "static",}
if
varBind
[
1
].
namedValues
==
{}:
# An empty dict {} means no namedValue's are present.
vals
.
append
(
snmp_to_numpy_dict
[
snmp_type
](
varBind
[
1
]))
else
:
# append the named values string instead of the raw number.
vals
.
append
(
varBind
[
1
].
prettyPrint
())
else
:
# convert from the funky pysnmp types to numpy types and then append
vals
.
append
(
snmp_to_numpy_dict
[
type
(
varBind
[
1
])
](
varBind
[
1
]))
vals
.
append
(
snmp_to_numpy_dict
[
snmp_type
](
varBind
[
1
]))
if
self
.
is_scalar
:
vals
=
vals
[
0
]
return
vals
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