Skip to content
Snippets Groups Projects
Commit 1e3a11ac authored by Erik Reid's avatar Erik Reid
Browse files

added support for snmp client config checks

parent 0c57c26a
No related branches found
No related tags found
No related merge requests found
import ipaddress
from inventory_provider.tasks.common import get_current_redis
from inventory_provider import config
from lxml import etree
import socket
COMMUNITY_STRING = '0pBiFbD'
COLLECTORS = [
'prod-noc-alarms01.geant.org',
'prod-noc-alarms02.geant.org',
'prod-noc-alarms03.geant.org',
'uat-noc-alarms01.geant.org',
'uat-noc-alarms02.geant.org',
'uat-noc-alarms03.geant.org',
'test-noc-alarms01.geant.org',
'test-noc-alarms02.geant.org',
'test-noc-alarms03.geant.org'
'prod-noc-alarms01.geant.org',
'prod-noc-alarms02.geant.org',
'prod-noc-alarms03.geant.org',
'uat-noc-alarms01.geant.org',
'uat-noc-alarms02.geant.org',
'uat-noc-alarms03.geant.org',
'test-noc-alarms01.geant.org',
'test-noc-alarms02.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):
for a in socket.getaddrinfo(hostname, None):
......@@ -38,6 +48,15 @@ def agent_addresses(netconf_string):
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
print(','.join(columns))
columns = [''] + [ADDRESS[c] for c in COLLECTORS]
......@@ -48,6 +67,11 @@ def _c(b):
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)
for k in r.scan_iter('netconf:*'):
k = k.decode('utf-8')
......@@ -56,7 +80,13 @@ for k in r.scan_iter('netconf:*'):
columns = [router]
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]
# acl_subnets = list(client_addresses(data, community=COMMUNITY_STRING))
# columns += [_c(_in_any_subnet(c, acl_subnets)) for c in COLLECTORS]
print(','.join(columns))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment