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
75b01fc8
Commit
75b01fc8
authored
6 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
zip v4 interface responses
parent
27040d4f
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
config.py
+67
-13
67 additions, 13 deletions
config.py
with
67 additions
and
13 deletions
config.py
+
67
−
13
View file @
75b01fc8
...
...
@@ -33,7 +33,6 @@ def walk(agent_hostname, community, base_oid):
# Pre-load MIB modules we expect to work with
mibBuilder
.
loadModules
(
'
SNMPv2-MIB
'
,
'
SNMP-COMMUNITY-MIB
'
,
'
RFC1213-MIB
'
)
print
(
"
walking %s: %s
"
%
(
agent_hostname
,
base_oid
))
for
(
engineErrorIndication
,
pduErrorIndication
,
...
...
@@ -50,13 +49,14 @@ def walk(agent_hostname, community, base_oid):
assert
not
engineErrorIndication
assert
not
pduErrorIndication
assert
errorIndex
==
0
varBinds
=
[
rfc1902
.
ObjectType
(
rfc1902
.
ObjectIdentity
(
x
[
0
]),
x
[
1
])
.
resolveWithMib
(
mibViewController
)
for
x
in
varBinds
]
#
varBinds = [
#
rfc1902.ObjectType(rfc1902.ObjectIdentity(x[0]),x[1])
#
.resolveWithMib(mibViewController)
#
for x in varBinds]
for
oid
,
val
in
varBinds
:
print
(
"
\t
oid:
'
%s
'
, val:
'
%s
'"
%
(
oid
.
prettyPrint
(),
val
.
prettyPrint
()))
yield
{
"
oid
"
:
"
.
"
+
str
(
oid
),
"
value
"
:
val
.
prettyPrint
()}
# print("\toid: '%s', val: '%s'" % (
# oid.prettyPrint(), val.prettyPrint()))
def
_validate_config
(
ctx
,
param
,
value
):
"""
...
...
@@ -135,6 +135,59 @@ def _db_test(db, router):
print
(
absid
)
def
get_router_interfaces
(
router
):
with
open
(
"
oid_list.conf
"
)
as
f
:
oid_map
=
load_oids
(
f
)
details
=
{}
for
name
,
oid
in
oid_map
.
items
():
details
[
name
]
=
walk
(
router
[
"
hostname
"
],
router
[
"
community
"
],
oid
)
print
(
name
)
details
[
name
]
=
list
(
details
[
name
])
print
(
details
[
name
])
# assert len(details["v4Address"]) == len(details["v4Mask"])
# assert len(details["v4Address"]) == len(details["v4InterfaceOID"])
interface_names
=
dict
([
x
[
"
oid
"
],
x
[
"
value
"
]]
for
x
in
details
[
"
v4InterfaceName
"
])
interfaces
=
[]
for
v4Address
,
v4Mask
,
v4InterfaceOID
in
zip
(
details
[
"
v4Address
"
],
details
[
"
v4Mask
"
],
details
[
"
v4InterfaceOID
"
]):
ifc_oid
=
oid_map
[
"
v4InterfaceName
"
]
+
"
.
"
+
v4InterfaceOID
[
"
value
"
]
v4InterfaceName
=
interface_names
[
ifc_oid
]
interfaces
.
append
({
"
v4Address
"
:
v4Address
[
"
value
"
],
"
v4Mask
"
:
v4Mask
[
"
value
"
],
"
v4InterfaceName
"
:
v4InterfaceName
})
print
(
interfaces
)
return
interfaces
"""
v4Address=.1.3.6.1.2.1.4.20.1.1
v4InterfaceOID=.1.3.6.1.2.1.4.20.1.2
v4InterfaceName=.1.3.6.1.2.1.31.1.1.1.1
v4Mask=.1.3.6.1.2.1.4.20.1.3
## IPv6
v6AddressAndMask=.1.3.6.1.2.1.55.1.8.1.2
v6InterfaceName=.1.3.6.1.2.1.55.1.5.1.2
"""
# interfaces = []
#
# # for name, oid in
# # # walk(r["address"], r["community"], ".1.3.6.1.2.1.4.20.1.1")
# # walk(r["hostname"], r["community"], ".1.3.6.1.2.1.4.20.1.1")
# print(details)
#
#
@click.command
()
@click.option
(
"
--config
"
,
...
...
@@ -144,13 +197,14 @@ def _db_test(db, router):
default
=
open
(
"
config.json
"
),
callback
=
_validate_config
)
def
cli
(
config
):
with
connection
(
config
[
"
alarms-db
"
])
as
c
:
with
open
(
"
routers_community.conf
"
)
as
f
:
for
r
in
load_routers
(
f
):
with
open
(
"
routers_community.conf
"
)
as
f
:
for
r
in
load_routers
(
f
):
with
connection
(
config
[
"
alarms-db
"
])
as
c
:
_db_test
(
c
,
r
)
# walk(r["address"], r["community"], ".1.3.6.1.2.1.4.20.1.1")
walk
(
r
[
"
hostname
"
],
r
[
"
community
"
],
"
.1.3.6.1.2.1.4.20.1.1
"
)
break
get_router_interfaces
(
r
)
break
if
__name__
==
"
__main__
"
:
...
...
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