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
1e3a11ac
Commit
1e3a11ac
authored
4 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
added support for snmp client config checks
parent
0c57c26a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/data/check-snmp-agent-configs.py
+40
-10
40 additions, 10 deletions
test/data/check-snmp-agent-configs.py
with
40 additions
and
10 deletions
test/data/check-snmp-agent-configs.py
+
40
−
10
View file @
1e3a11ac
import
ipaddress
from
inventory_provider.tasks.common
import
get_current_redis
from
inventory_provider.tasks.common
import
get_current_redis
from
inventory_provider
import
config
from
inventory_provider
import
config
from
lxml
import
etree
from
lxml
import
etree
import
socket
import
socket
COMMUNITY_STRING
=
'
0pBiFbD
'
COLLECTORS
=
[
COLLECTORS
=
[
'
prod-noc-alarms01.geant.org
'
,
'
prod-noc-alarms01.geant.org
'
,
'
prod-noc-alarms02.geant.org
'
,
'
prod-noc-alarms02.geant.org
'
,
'
prod-noc-alarms03.geant.org
'
,
'
prod-noc-alarms03.geant.org
'
,
'
uat-noc-alarms01.geant.org
'
,
'
uat-noc-alarms01.geant.org
'
,
'
uat-noc-alarms02.geant.org
'
,
'
uat-noc-alarms02.geant.org
'
,
'
uat-noc-alarms03.geant.org
'
,
'
uat-noc-alarms03.geant.org
'
,
'
test-noc-alarms01.geant.org
'
,
'
test-noc-alarms01.geant.org
'
,
'
test-noc-alarms02.geant.org
'
,
'
test-noc-alarms02.geant.org
'
,
'
test-noc-alarms03.geant.org
'
'
test-noc-alarms03.geant.org
'
]
]
# COLLECTORS = [
# 'prod-poller-admin.geant.org',
# 'uat-poller-admin.geant.org',
# 'test-poller-admin.geant.org',
# 'test-poller-sensu-agent01.geant.org',
# 'test-poller-sensu-agent02.geant.org'
# ]
def
v4_address
(
hostname
):
def
v4_address
(
hostname
):
for
a
in
socket
.
getaddrinfo
(
hostname
,
None
):
for
a
in
socket
.
getaddrinfo
(
hostname
,
None
):
...
@@ -38,6 +48,15 @@ def agent_addresses(netconf_string):
...
@@ -38,6 +48,15 @@ def agent_addresses(netconf_string):
return
doc
.
xpath
(
'
//configuration/snmp/trap-group/targets/name/text()
'
)
return
doc
.
xpath
(
'
//configuration/snmp/trap-group/targets/name/text()
'
)
def
client_addresses
(
netconf_string
,
community
):
doc
=
etree
.
fromstring
(
netconf_string
)
subnets
=
doc
.
xpath
(
f
'
//configuration/snmp/community[name/text()=
"
{
community
}
"
]
'
'
/clients/name/text()
'
)
for
s
in
subnets
:
yield
ipaddress
.
ip_network
(
s
,
strict
=
False
)
columns
=
[
''
]
+
COLLECTORS
columns
=
[
''
]
+
COLLECTORS
print
(
'
,
'
.
join
(
columns
))
print
(
'
,
'
.
join
(
columns
))
columns
=
[
''
]
+
[
ADDRESS
[
c
]
for
c
in
COLLECTORS
]
columns
=
[
''
]
+
[
ADDRESS
[
c
]
for
c
in
COLLECTORS
]
...
@@ -48,6 +67,11 @@ def _c(b):
...
@@ -48,6 +67,11 @@ def _c(b):
return
'
+
'
if
b
else
'
MISSING
'
return
'
+
'
if
b
else
'
MISSING
'
def
_in_any_subnet
(
hostname
,
subnets
):
address
=
ipaddress
.
ip_address
(
ADDRESS
[
hostname
])
return
any
([
address
in
s
for
s
in
subnets
])
r
=
get_current_redis
(
params
)
r
=
get_current_redis
(
params
)
for
k
in
r
.
scan_iter
(
'
netconf:*
'
):
for
k
in
r
.
scan_iter
(
'
netconf:*
'
):
k
=
k
.
decode
(
'
utf-8
'
)
k
=
k
.
decode
(
'
utf-8
'
)
...
@@ -56,7 +80,13 @@ for k in r.scan_iter('netconf:*'):
...
@@ -56,7 +80,13 @@ for k in r.scan_iter('netconf:*'):
columns
=
[
router
]
columns
=
[
router
]
data
=
r
.
get
(
k
).
decode
(
'
utf-8
'
)
data
=
r
.
get
(
k
).
decode
(
'
utf-8
'
)
agents
=
agent_addresses
(
data
)
with
open
(
f
'
{
router
}
.xml
'
,
'
w
'
)
as
f
:
f
.
write
(
data
)
agents
=
agent_addresses
(
data
)
columns
+=
[
_c
(
ADDRESS
[
c
]
in
agents
)
for
c
in
COLLECTORS
]
columns
+=
[
_c
(
ADDRESS
[
c
]
in
agents
)
for
c
in
COLLECTORS
]
# acl_subnets = list(client_addresses(data, community=COMMUNITY_STRING))
# columns += [_c(_in_any_subnet(c, acl_subnets)) for c in COLLECTORS]
print
(
'
,
'
.
join
(
columns
))
print
(
'
,
'
.
join
(
columns
))
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