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

added fw & dcu counter oids to gws_indirect response

parent c2ec30e3
No related branches found
No related tags found
No related merge requests found
......@@ -227,11 +227,25 @@ SERVICES_LIST_SCHEMA = {
'$schema': 'http://json-schema.org/draft-07/schema#',
'definitions': {
'oid': {
'type': 'string',
'pattern': r'^(\d+\.)*\d+$'
},
'counters': {
'type': 'object',
'properties': {
'egressOctets': {'$ref': '#/definitions/oid'},
'ingressOctets': {'$ref': '#/definitions/oid'}
},
'required': ['egressOctets', 'ingressOctets'],
'additionalProperties': False
},
'snmp-info': {
'type': 'object',
'properties': {
'ifIndex': {'type': 'integer'},
'community': {'type': 'string'}
'community': {'type': 'string'},
'counters': {'$ref': '#/definitions/counters'}
},
'required': ['ifIndex', 'community'],
'additionalProperties': False
......@@ -731,6 +745,72 @@ def gws_direct():
return Response(result, mimetype="application/json")
# cf. https://gitlab.geant.net/puppet-apps/cacti/-/blob/production/files/scripts/juniper-firewall-dws.pl # noqa: E501
JNX_DCU_STATS_BYTES_OID = '1.3.6.1.4.1.2636.3.6.2.1.5'
JNX_FW_COUNTER_BYTES_OID = '1.3.6.1.4.1.2636.3.5.2.1.5'
JNX_ADDRESS_FAMILY = {
'ipv4': 1,
'ipv6': 2
}
JNX_FW_COUNTER_TYPE = {
'other': 1,
'counter': 2,
'policer': 3
}
def _str2oid(s):
chars = '.'.join(str(ord(c)) for c in s)
return f'{len(s)}.{chars}'
def _jnx_dcu_byte_count_oid(
ifIndex,
class_name='dws-in',
address_family=JNX_ADDRESS_FAMILY['ipv4']):
# sanity checks (in case of programming errors)
assert isinstance(ifIndex, int)
assert isinstance(class_name, str)
assert isinstance(address_family, int)
return '.'.join([
JNX_DCU_STATS_BYTES_OID,
str(ifIndex),
str(address_family),
_str2oid(class_name)
])
def _jnx_fw_counter_bytes_oid(
customer,
interface_name,
filter_name=None,
counter_name=None):
# sanity checks (in case of programming errors)
assert isinstance(customer, str)
assert isinstance(interface_name, str)
assert filter_name is None or isinstance(filter_name, str)
assert counter_name is None or isinstance(counter_name, str)
if filter_name is None:
filter_name = f'nren_IAS_{customer}_OUT-{interface_name}-o'
if counter_name is None:
# TODO: Niall might remove this inconsistency!!!
if customer == 'GRNET':
counter_name = f'DWS-GRnet-out-{interface_name}-o'
else:
counter_name = f'DWS-out-{interface_name}-o'
return '.'.join([
JNX_FW_COUNTER_BYTES_OID,
_str2oid(filter_name),
_str2oid(counter_name),
str(JNX_FW_COUNTER_TYPE['counter'])
])
def _get_services_internal(service_type=None):
"""
Performs the lookup and caching done for calls to
......@@ -769,8 +849,15 @@ def _get_services_internal(service_type=None):
if interface_info:
s['snmp'] = {
'ifIndex': interface_info['index'],
'community': interface_info['community']
'community': interface_info['community'],
}
if s['type'] == 'GWS - INDIRECT':
s['snmp']['counters'] = {
'ingressOctets': _jnx_dcu_byte_count_oid(
interface_info['index']),
'egressOctets': _jnx_fw_counter_bytes_oid(
s['customer'], s['interface'])
}
return s
def _wanted_in_output(s):
......
......@@ -78,6 +78,23 @@ def test_gws_indirect(client):
assert all(s['type'] == 'GWS - INDIRECT' for s in response_data)
def test_gws_indirect_snmp(client, service_type):
# same as test_services_snmp, but also verify that
# the snmp data in the response contains counters
rv = client.get(
'/poller/services/gws_indirect?snmp=1',
headers=DEFAULT_REQUEST_HEADERS)
assert rv.status_code == 200
assert rv.is_json
response_data = json.loads(rv.data.decode('utf-8'))
jsonschema.validate(response_data, poller.SERVICES_LIST_SCHEMA)
assert response_data # test data is non-empty
# all access services should have snmp info
assert all('snmp' in s for s in response_data)
assert all('counters' in s['snmp'] for s in response_data)
def test_all_services_default(client):
rv = client.get(
'/poller/services',
......@@ -160,3 +177,26 @@ def test_get_service_types(client):
# some hard-coded values we expect to see from the test data ...
assert 'gws_indirect' in response_data
assert 'geant_ip' in response_data
@pytest.mark.parametrize('ifIndex,expected_oid', [
(595, '1.3.6.1.4.1.2636.3.6.2.1.5.595.1.6.100.119.115.45.105.110'),
(607, '1.3.6.1.4.1.2636.3.6.2.1.5.607.1.6.100.119.115.45.105.110'),
(1135, '1.3.6.1.4.1.2636.3.6.2.1.5.1135.1.6.100.119.115.45.105.110')
])
def test_dcu_oid_values(ifIndex, expected_oid):
assert poller._jnx_dcu_byte_count_oid(ifIndex) == expected_oid
@pytest.mark.parametrize('customer, interface_name, expected_oid', [
('ASREN', 'ae17.333', '1.3.6.1.4.1.2636.3.5.2.1.5.29.110.114.101.110.95.73.65.83.95.65.83.82.69.78.95.79.85.84.45.97.101.49.55.46.51.51.51.45.111.18.68.87.83.45.111.117.116.45.97.101.49.55.46.51.51.51.45.111.2'), # noqa: E501
('FCCN', 'ae10.333', '1.3.6.1.4.1.2636.3.5.2.1.5.28.110.114.101.110.95.73.65.83.95.70.67.67.78.95.79.85.84.45.97.101.49.48.46.51.51.51.45.111.18.68.87.83.45.111.117.116.45.97.101.49.48.46.51.51.51.45.111.2'), # noqa: E501
('GRNET', 'ae11.333', '1.3.6.1.4.1.2636.3.5.2.1.5.29.110.114.101.110.95.73.65.83.95.71.82.78.69.84.95.79.85.84.45.97.101.49.49.46.51.51.51.45.111.24.68.87.83.45.71.82.110.101.116.45.111.117.116.45.97.101.49.49.46.51.51.51.45.111.2'), # noqa: E501
('GRNET', 'ae10.333', '1.3.6.1.4.1.2636.3.5.2.1.5.29.110.114.101.110.95.73.65.83.95.71.82.78.69.84.95.79.85.84.45.97.101.49.48.46.51.51.51.45.111.24.68.87.83.45.71.82.110.101.116.45.111.117.116.45.97.101.49.48.46.51.51.51.45.111.2'), # noqa: E501
('ULAKBIM', 'ae11.333', '1.3.6.1.4.1.2636.3.5.2.1.5.31.110.114.101.110.95.73.65.83.95.85.76.65.75.66.73.77.95.79.85.84.45.97.101.49.49.46.51.51.51.45.111.18.68.87.83.45.111.117.116.45.97.101.49.49.46.51.51.51.45.111.2'), # noqa: E501
('UOM', 'xe-11/0/0.333', '1.3.6.1.4.1.2636.3.5.2.1.5.32.110.114.101.110.95.73.65.83.95.85.79.77.95.79.85.84.45.120.101.45.49.49.47.48.47.48.46.51.51.51.45.111.23.68.87.83.45.111.117.116.45.120.101.45.49.49.47.48.47.48.46.51.51.51.45.111.2'), # noqa: E501
('LITNET', 'xe-0/1/1.333', '1.3.6.1.4.1.2636.3.5.2.1.5.34.110.114.101.110.95.73.65.83.95.76.73.84.78.69.84.95.79.85.84.45.120.101.45.48.47.49.47.49.46.51.51.51.45.111.22.68.87.83.45.111.117.116.45.120.101.45.48.47.49.47.49.46.51.51.51.45.111.2'), # noqa: E501
])
def test_fw_counter_bytes_oid_values(customer, interface_name, expected_oid):
assert poller._jnx_fw_counter_bytes_oid(
customer, interface_name) == expected_oid
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment