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

bugfixes and updated tests with eumetsat data

parent 1ffb347b
No related branches found
No related tags found
No related merge requests found
...@@ -133,6 +133,7 @@ class State(object): ...@@ -133,6 +133,7 @@ class State(object):
GWS_INDIRECT = 'gws-indirect.json' GWS_INDIRECT = 'gws-indirect.json'
INTERFACES = 'interfaces.json' INTERFACES = 'interfaces.json'
STATE = 'state.json' STATE = 'state.json'
EUMET_MC = 'eumetsat-multicast.json'
STATE_SCHEMA = { STATE_SCHEMA = {
'$schema': 'http://json-schema.org/draft-07/schema#', '$schema': 'http://json-schema.org/draft-07/schema#',
...@@ -150,7 +151,8 @@ class State(object): ...@@ -150,7 +151,8 @@ class State(object):
'state': os.path.join(state_dir, State.STATE), 'state': os.path.join(state_dir, State.STATE),
'interfaces': os.path.join(state_dir, State.INTERFACES), 'interfaces': os.path.join(state_dir, State.INTERFACES),
'gws-direct': os.path.join(state_dir, State.GWS_DIRECT), 'gws-direct': os.path.join(state_dir, State.GWS_DIRECT),
'gws-indirect': os.path.join(state_dir, State.GWS_INDIRECT) 'gws-indirect': os.path.join(state_dir, State.GWS_INDIRECT),
'eumetsat-multicast': os.path.join(state_dir, State.EUMET_MC)
} }
@staticmethod @staticmethod
...@@ -231,6 +233,19 @@ class State(object): ...@@ -231,6 +233,19 @@ class State(object):
new_services, new_services,
inventory.GWS_INDIRECT_SCHEMA) inventory.GWS_INDIRECT_SCHEMA)
@property
def eumetsat_multicast(self) -> list:
return State._load_json(
self.cache_filenames['eumetsat-multicast'],
inventory.MULTICAST_SUBSCRIPTION_LIST_SCHEMA)
@eumetsat_multicast.setter
def eumetsat_multicast(self, new_subscriptions):
State._save_json(
self.cache_filenames['eumetsat-multicast'],
new_subscriptions,
inventory.MULTICAST_SUBSCRIPTION_LIST_SCHEMA)
def _setup_logging(filename=None): def _setup_logging(filename=None):
""" """
......
...@@ -33,10 +33,10 @@ class EUMETSATMulticastHostCheck(sensu.AbstractCheck): ...@@ -33,10 +33,10 @@ class EUMETSATMulticastHostCheck(sensu.AbstractCheck):
return self.hostname return self.hostname
def refresh(sensu_params, eumetsat_multicast_config): def refresh(sensu_params, subscriptions):
# one check per unique host # one check per unique host
all_routers = {x['router'] for x in eumetsat_multicast_config} all_routers = {x['router'] for x in subscriptions}
required_checks = [ required_checks = [
EUMETSATMulticastHostCheck( EUMETSATMulticastHostCheck(
sensu_params['eumetsat-multicast-check'], hostname) sensu_params['eumetsat-multicast-check'], hostname)
......
...@@ -97,6 +97,26 @@ GWS_INDIRECT_SCHEMA = { ...@@ -97,6 +97,26 @@ GWS_INDIRECT_SCHEMA = {
} }
# much less strict version of the actual schema
MULTICAST_SUBSCRIPTION_LIST_SCHEMA = {
'$schema': 'http://json-schema.org/draft-07/schema#',
'definitions': {
'subscription': {
'type': 'object',
'properties': {
# we really only use this field
# don't depend strictly on unused data
'router': {'type': 'string'}
},
'required': ['router']
}
},
'type': 'array',
'items': {'$ref': '#/definitions/subscription'}
}
def _pick_one(haystack): def _pick_one(haystack):
if not isinstance(haystack, (list, tuple, set)): if not isinstance(haystack, (list, tuple, set)):
haystack = [haystack] haystack = [haystack]
...@@ -159,6 +179,19 @@ def load_gws_indirect_services(base_urls): ...@@ -159,6 +179,19 @@ def load_gws_indirect_services(base_urls):
'poller/gws/indirect', base_urls, GWS_INDIRECT_SCHEMA) 'poller/gws/indirect', base_urls, GWS_INDIRECT_SCHEMA)
def load_eumetsat_multicast_subscriptions(base_urls):
"""
Load /poller/eumetsat-multicast from inventory provider
:param base_urls: inventory provider base api url, or a list of them
:return: a list of dicts, each with a 'router' key
"""
return _load_inventory_json(
'poller/eumetsat-multicast',
base_urls,
MULTICAST_SUBSCRIPTION_LIST_SCHEMA)
def last_update_timestamp(base_urls) -> float: def last_update_timestamp(base_urls) -> float:
try: try:
r = requests.get( r = requests.get(
......
...@@ -54,7 +54,8 @@ REFRESH_RESULT_SCHEMA = { ...@@ -54,7 +54,8 @@ REFRESH_RESULT_SCHEMA = {
'properties': { 'properties': {
'interfaces': {'$ref': '#/definitions/refresh-result'}, 'interfaces': {'$ref': '#/definitions/refresh-result'},
'gws_direct': {'$ref': '#/definitions/refresh-result'}, 'gws_direct': {'$ref': '#/definitions/refresh-result'},
'gws_indirect': {'$ref': '#/definitions/refresh-result'} 'gws_indirect': {'$ref': '#/definitions/refresh-result'},
'eumetsat_multicast': {'$ref': '#/definitions/refresh-result'},
}, },
'required': ['interfaces'], 'required': ['interfaces'],
'additionalProperties': False 'additionalProperties': False
...@@ -85,6 +86,9 @@ def refresh(config, force=False): ...@@ -85,6 +86,9 @@ def refresh(config, force=False):
config['inventory']) config['inventory'])
state.gws_indirect = inventory.load_gws_indirect_services( state.gws_indirect = inventory.load_gws_indirect_services(
config['inventory']) config['inventory'])
state.eumetsat_multicast \
= inventory.load_eumetsat_multicast_subscriptions(
config['inventory'])
result = { result = {
'interfaces': interfaces.refresh(config['sensu'], state.interfaces), 'interfaces': interfaces.refresh(config['sensu'], state.interfaces),
'gws_direct': gws_direct.refresh(config['sensu'], state.gws_direct), 'gws_direct': gws_direct.refresh(config['sensu'], state.gws_direct),
......
...@@ -36,20 +36,28 @@ def config(): ...@@ -36,20 +36,28 @@ def config():
'interface-check': { 'interface-check': {
'script': '/var/lib/sensu/bin/counter2influx.sh', 'script': '/var/lib/sensu/bin/counter2influx.sh',
'measurement': 'counters', 'measurement': 'counters',
'command': ('{script} {measurement} ' 'command': '{script} {measurement}'
'{community} {hostname} ' ' {community} {hostname}'
'{interface} {ifIndex}'), ' {interface} {ifIndex}',
}, },
'gws-direct-interface-check': { 'gws-direct-interface-check': {
'script': '/var/lib/sensu/bin/poll-gws-direct.sh', 'script': '/var/lib/sensu/bin/poll-gws-direct.sh',
'measurement': 'gwsd_counters', 'measurement': 'gwsd_counters',
'command': ('{script} {measurement} ' 'command': '{script} {measurement}'
'{nren} {isp} {hostname} {tag}') ' {nren} {isp} {hostname} {tag}'
}, },
'dscp32-service-check': { 'dscp32-service-check': {
'script': '/var/lib/sensu/bin/poll-gws-indirect.sh', 'script': '/var/lib/sensu/bin/poll-gws-indirect.sh',
'measurement': 'dscp32_counters', 'measurement': 'dscp32_counters',
'command': '{script} {measurement} {service}' 'command': '{script} {measurement} {service}'
},
'eumetsat-multicast-check': {
'script': '/home/brian_checks/venv/eumetsat-multicast',
'measurement': 'multicast',
'command': '{script}'
' --inventory http://localhost:18080'
' --measurement {measurement}'
' --hostname {hostname}'
} }
}, },
'statedir': state_dir_name, 'statedir': state_dir_name,
...@@ -184,6 +192,11 @@ def mocked_inventory(): ...@@ -184,6 +192,11 @@ def mocked_inventory():
url=re.compile(r'.*inventory.+/poller/gws/indirect.*'), url=re.compile(r'.*inventory.+/poller/gws/indirect.*'),
body=_load_test_data('gws-indirect.json')) body=_load_test_data('gws-indirect.json'))
responses.add(
method=responses.GET,
url=re.compile(r'.*inventory.+/poller/eumetsat-multicast'),
body=_load_test_data('eumetsat-multicast.json'))
bogus_version = {'latch': {'timestamp': 10000 * random.random()}} bogus_version = {'latch': {'timestamp': 10000 * random.random()}}
# mocked api for returning all checks # mocked api for returning all checks
responses.add( responses.add(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment