diff --git a/inventory_provider/config.py b/inventory_provider/config.py index 4b0a42bd66a0b0def50712c9f8681513ccaa4b36..4881d4c10921fae338a29cf71b8638e48add315d 100644 --- a/inventory_provider/config.py +++ b/inventory_provider/config.py @@ -92,44 +92,46 @@ CONFIG_SCHEMA = { 'required': ['address', 'network', 'interface', 'router'], 'additionalProperties': False }, - 'gws-direct-snmp-counter': { + 'oid': { + 'type': 'string', + 'pattern': r'^(\d+\.)*\d+$' + }, + 'gws-direct-counters': { 'type': 'object', 'properties': { - 'hostname': {'type': 'string'}, - 'community': {'type': 'string'}, - 'oid': { - 'type': 'string', - 'pattern': r'^(\d+\.)*\d+$' - } + 'discards_in': {'$ref': '#/definitions/oid'}, + 'discards_out': {'$ref': '#/definitions/oid'}, + 'errors_in': {'$ref': '#/definitions/oid'}, + 'errors_out': {'$ref': '#/definitions/oid'}, + 'traffic_in': {'$ref': '#/definitions/oid'}, + 'traffic_out': {'$ref': '#/definitions/oid'}, }, - 'required': ['hostname', 'community', 'oid'], 'additionalProperties': False }, - 'gws-direct-snmp-counter-list': { - 'type': 'array', - 'items': {'$ref': '#/definitions/gws-direct-snmp-counter'}, - 'minItems': 1 + 'gws-direct-interface': { + 'type': 'object', + 'properties': { + 'tag': {'type': 'string'}, + 'counters': {'$ref': '#/definitions/gws-direct-counters'} + }, + 'required': ['tag', 'counters'], + 'additionalProperties': False }, - 'gws-direct-counters': { + 'gws-direct-host': { 'type': 'object', 'properties': { - 'traffic_in': { - '$ref': '#/definitions/gws-direct-snmp-counter-list'}, - 'traffic_out': { - '$ref': '#/definitions/gws-direct-snmp-counter-list'}, - 'discards_in': { - '$ref': '#/definitions/gws-direct-snmp-counter-list'}, - 'discards_out': { - '$ref': '#/definitions/gws-direct-snmp-counter-list'}, - 'errors_in': { - '$ref': '#/definitions/gws-direct-snmp-counter-list'}, - 'errors_out': { - '$ref': '#/definitions/gws-direct-snmp-counter-list'} + 'hostname': {'type': 'string'}, + 'community': {'type': 'string'}, + 'interfaces': { + 'type': 'array', + 'items': {'$ref': '#/definitions/gws-direct-interface'}, + 'minItems': 1 + } }, - 'required': ['traffic_in', 'traffic_out'], + 'required': ['hostname', 'community', 'interfaces'], 'additionalProperties': False }, - 'gws-direct-nren-isp-counters': { + 'gws-direct-nren-isp': { 'type': 'object', 'properties': { 'nren': {'type': 'string'}, @@ -137,14 +139,18 @@ CONFIG_SCHEMA = { 'type': 'string', 'enum': ['Cogent', 'Telia', 'Century Link'] }, - 'counters': {'$ref': '#/definitions/gws-direct-counters'}, + 'hosts': { + 'type': 'array', + 'items': {'$ref': '#/definitions/gws-direct-host'}, + 'minItems': 1 + } }, - 'required': ['nren', 'isp', 'counters'], + 'required': ['nren', 'isp', 'hosts'], 'additionalProperties': False }, 'gws-direct': { 'type': 'array', - 'items': {'$ref': '#/definitions/gws-direct-nren-isp-counters'} + 'items': {'$ref': '#/definitions/gws-direct-nren-isp'} }, }, diff --git a/inventory_provider/routes/poller.py b/inventory_provider/routes/poller.py index 8aacdf41025e2ec1456cd106fa6371a1d629a9fd..5a5863604dc44650bea40262d5be1bb2a4360226 100644 --- a/inventory_provider/routes/poller.py +++ b/inventory_provider/routes/poller.py @@ -153,38 +153,46 @@ GWS_DIRECT_DATA_SCHEMA = { '$schema': 'http://json-schema.org/draft-07/schema#', 'definitions': { - 'snmp-counter': { + 'oid': { + 'type': 'string', + 'pattern': r'^(\d+\.)*\d+$' + }, + 'counters': { 'type': 'object', 'properties': { - 'hostname': {'type': 'string'}, - 'community': {'type': 'string'}, - 'oid': { - 'type': 'string', - 'pattern': r'^(\d+\.)*\d+$' - } + 'discards_in': {'$ref': '#/definitions/oid'}, + 'discards_out': {'$ref': '#/definitions/oid'}, + 'errors_in': {'$ref': '#/definitions/oid'}, + 'errors_out': {'$ref': '#/definitions/oid'}, + 'traffic_in': {'$ref': '#/definitions/oid'}, + 'traffic_out': {'$ref': '#/definitions/oid'}, }, - 'required': ['hostname', 'community', 'oid'], 'additionalProperties': False }, - 'snmp-counter-list': { - 'type': 'array', - 'items': {'$ref': '#/definitions/snmp-counter'}, - 'minItems': 1 + 'interface': { + 'type': 'object', + 'properties': { + 'tag': {'type': 'string'}, + 'counters': {'$ref': '#/definitions/counters'} + }, + 'required': ['tag', 'counters'], + 'additionalProperties': False }, - 'isp-counters': { + 'host': { 'type': 'object', 'properties': { - 'traffic_in': {'$ref': '#/definitions/snmp-counter-list'}, - 'traffic_out': {'$ref': '#/definitions/snmp-counter-list'}, - 'discards_in': {'$ref': '#/definitions/snmp-counter-list'}, - 'discards_out': {'$ref': '#/definitions/snmp-counter-list'}, - 'errors_in': {'$ref': '#/definitions/snmp-counter-list'}, - 'errors_out': {'$ref': '#/definitions/snmp-counter-list'} + 'hostname': {'type': 'string'}, + 'community': {'type': 'string'}, + 'interfaces': { + 'type': 'array', + 'items': {'$ref': '#/definitions/interface'}, + 'minItems': 1 + } }, - 'required': ['traffic_in', 'traffic_out'], + 'required': ['hostname', 'community', 'interfaces'], 'additionalProperties': False }, - 'nren-isp-direct-counters': { + 'nren-isp': { 'type': 'object', 'properties': { 'nren': {'type': 'string'}, @@ -192,15 +200,19 @@ GWS_DIRECT_DATA_SCHEMA = { 'type': 'string', 'enum': ['Cogent', 'Telia', 'Century Link'] }, - 'counters': {'$ref': '#/definitions/isp-counters'}, + 'hosts': { + 'type': 'array', + 'items': {'$ref': '#/definitions/host'}, + 'minItems': 1 + } }, - 'required': ['nren', 'isp', 'counters'], + 'required': ['nren', 'isp', 'hosts'], 'additionalProperties': False } }, 'type': 'array', - 'items': {'$ref': '#/definitions/nren-isp-direct-counters'} + 'items': {'$ref': '#/definitions/nren-isp'} } diff --git a/test/data/gws-direct.json b/test/data/gws-direct.json index 87d4449b8df50a197dc883445b34a7e28b41b53b..8fcb50564dd4687b74ff105e62423d75501e999c 100644 --- a/test/data/gws-direct.json +++ b/test/data/gws-direct.json @@ -2,163 +2,288 @@ { "nren": "ARNES", "isp": "Cogent", - "counters": { - "discards_in": [ - {"hostname": "88.200.0.63", "community": "gn2nocT3st", "oid": "1.3.6.1.2.1.2.2.1.13.533"} - ], - "discards_out": [ - {"hostname": "88.200.0.63", "community": "gn2nocT3st", "oid": "1.3.6.1.2.1.2.2.1.19.533"} - ], - "errors_in": [ - {"hostname": "88.200.0.63", "community": "gn2nocT3st", "oid": "1.3.6.1.2.1.2.2.1.14.533"} - ], - "errors_out": [ - {"hostname": "88.200.0.63", "community": "gn2nocT3st", "oid": "1.3.6.1.2.1.2.2.1.20.533"} - ], - "traffic_in": [ - {"hostname": "88.200.0.63", "community": "gn2nocT3st", "oid": "1.3.6.1.2.1.31.1.1.1.6.531"}, - {"hostname": "88.200.0.63", "community": "gn2nocT3st", "oid": "1.3.6.1.2.1.31.1.1.1.6.525"}, - {"hostname": "88.200.0.63", "community": "gn2nocT3st", "oid": "1.3.6.1.2.1.31.1.1.1.6.553"}, - {"hostname": "88.200.0.63", "community": "gn2nocT3st", "oid": "1.3.6.1.2.1.31.1.1.1.6.563"} - ], - "traffic_out": [ - {"hostname": "88.200.0.63", "community": "gn2nocT3st", "oid": "1.3.6.1.2.1.31.1.1.1.10.531"}, - {"hostname": "88.200.0.63", "community": "gn2nocT3st", "oid": "1.3.6.1.2.1.31.1.1.1.10.525"}, - {"hostname": "88.200.0.63", "community": "gn2nocT3st", "oid": "1.3.6.1.2.1.31.1.1.1.10.553"}, - {"hostname": "88.200.0.63", "community": "gn2nocT3st", "oid": "1.3.6.1.2.1.31.1.1.1.10.563"} - ] - } + "hosts": [ + { + "hostname": "88.200.0.63", + "community": "gn2nocT3st", + "interfaces": [ + { + "tag": "a", + "counters": { + "discards_in": "1.3.6.1.2.1.2.2.1.13.533", + "discards_out": "1.3.6.1.2.1.2.2.1.19.533", + "errors_in": "1.3.6.1.2.1.2.2.1.14.533", + "errors_out": "1.3.6.1.2.1.2.2.1.20.533" + } + }, + { + "tag": "b", + "counters": { + "traffic_in": "1.3.6.1.2.1.31.1.1.1.6.531", + "traffic_out": "1.3.6.1.2.1.31.1.1.1.10.531" + } + }, + { + "tag": "c", + "counters": { + "traffic_in": "1.3.6.1.2.1.31.1.1.1.6.525", + "traffic_out": "1.3.6.1.2.1.31.1.1.1.10.525" + } + }, + { + "tag": "d", + "counters": { + "traffic_in": "1.3.6.1.2.1.31.1.1.1.6.553", + "traffic_out": "1.3.6.1.2.1.31.1.1.1.10.553" + } + }, + { + "tag": "e", + "counters": { + "traffic_in": "1.3.6.1.2.1.31.1.1.1.6.563", + "traffic_out": "1.3.6.1.2.1.31.1.1.1.10.563" + } + } + ] + } + ] }, { "nren": "ARNES", "isp": "Telia", - "counters": { - "traffic_in": [ - {"hostname": "62.40.124.6", "community": "gn2nocT3st", "oid": "1.3.6.1.2.1.31.1.1.1.6.611"}, - {"hostname": "62.40.124.6", "community": "gn2nocT3st", "oid": "1.3.6.1.2.1.31.1.1.1.6.589"} - ], - "traffic_out": [ - {"hostname": "62.40.124.6", "community": "gn2nocT3st", "oid": "1.3.6.1.2.1.31.1.1.1.10.611"}, - {"hostname": "62.40.124.6", "community": "gn2nocT3st", "oid": "1.3.6.1.2.1.31.1.1.1.10.589"} - ] - } + "hosts": [ + { + "hostname": "62.40.124.6", + "community": "gn2nocT3st", + "interfaces": [ + { + "tag": "a", + "counters": { + "traffic_in": "1.3.6.1.2.1.31.1.1.1.6.611", + "traffic_out": "1.3.6.1.2.1.31.1.1.1.10.611" + } + }, + { + "tag": "b", + "counters": { + "traffic_in": "1.3.6.1.2.1.31.1.1.1.6.589", + "traffic_out": "1.3.6.1.2.1.31.1.1.1.10.589" + } + } + ] + } + ] }, { "nren": "CARNET", "isp": "Cogent", - "counters": { - "traffic_in": [ - {"hostname": "62.40.124.10", "community": "atlas1453", "oid": "1.3.6.1.2.1.31.1.1.1.6.35"} - ], - "traffic_out": [ - {"hostname": "62.40.124.10", "community": "atlas1453", "oid": "1.3.6.1.2.1.31.1.1.1.10.35"} - ] - } + "hosts": [ + { + "hostname": "62.40.124.10", + "community": "atlas1453", + "interfaces": [ + { + "tag": "a", + "counters": { + "traffic_in": "1.3.6.1.2.1.31.1.1.1.6.35", + "traffic_out": "1.3.6.1.2.1.31.1.1.1.10.35" + } + } + ] + } + ] }, { "nren": "CARNET", "isp": "Telia", - "counters": { - "traffic_in": [ - {"hostname": "62.40.125.150", "community": "atlas1453", "oid": "1.3.6.1.2.1.31.1.1.1.6.48"} - ], - "traffic_out": [ - {"hostname": "62.40.125.150", "community": "atlas1453", "oid": "1.3.6.1.2.1.31.1.1.1.10.48"} - ] - } + "hosts": [ + { + "hostname": "62.40.125.150", + "community": "atlas1453", + "interfaces": [ + { + "tag": "a", + "counters": { + "traffic_in": "1.3.6.1.2.1.31.1.1.1.6.48", + "traffic_out": "1.3.6.1.2.1.31.1.1.1.10.48" + } + } + ] + } + ] }, { "nren": "KIFU", "isp": "Cogent", - "counters": { - "traffic_in": [ - {"hostname": "195.111.97.108", "community": "atlas1453", "oid": "1.3.6.1.2.1.31.1.1.1.6.155"} - ], - "traffic_out": [ - {"hostname": "195.111.97.108", "community": "atlas1453", "oid": "1.3.6.1.2.1.31.1.1.1.10.155"} - ] - } + "hosts": [ + { + "hostname": "195.111.97.108", + "community": "atlas1453", + "interfaces": [ + { + "tag": "a", + "counters": { + "traffic_in": "1.3.6.1.2.1.31.1.1.1.6.155", + "traffic_out": "1.3.6.1.2.1.31.1.1.1.10.155" + } + } + ] + } + ] }, { "nren": "KIFU", "isp": "Telia", - "counters": { - "traffic_in": [ - {"hostname": "195.111.97.108", "community": "atlas1453", "oid": "1.3.6.1.2.1.31.1.1.1.6.148"} - ], - "traffic_out": [ - {"hostname": "195.111.97.108", "community": "atlas1453", "oid": "1.3.6.1.2.1.31.1.1.1.10.148"} - ] - } + "hosts": [ + { + "hostname": "195.111.97.108", + "community": "atlas1453", + "interfaces": [ + { + "tag": "a", + "counters": { + "traffic_in": "1.3.6.1.2.1.31.1.1.1.6.148", + "traffic_out": "1.3.6.1.2.1.31.1.1.1.10.148" + } + } + ] + } + ] }, { "nren": "RedIRIS", "isp": "Telia", - "counters": { - "traffic_in": [ - {"hostname": "130.206.206.250", "community": "atlas1453", "oid": "1.3.6.1.2.1.31.1.1.1.6.1487"}, - {"hostname": "130.206.206.250", "community": "atlas1453", "oid": "1.3.6.1.2.1.31.1.1.1.6.1488"}, - {"hostname": "130.206.206.250", "community": "atlas1453", "oid": "1.3.6.1.2.1.31.1.1.1.6.1489"}, - {"hostname": "130.206.206.250", "community": "atlas1453", "oid": "1.3.6.1.2.1.31.1.1.1.6.760"}, - {"hostname": "130.206.206.250", "community": "atlas1453", "oid": "1.3.6.1.2.1.31.1.1.1.6.796"} - ], - "traffic_out": [ - {"hostname": "130.206.206.250", "community": "atlas1453", "oid": "1.3.6.1.2.1.31.1.1.1.10.1487"}, - {"hostname": "130.206.206.250", "community": "atlas1453", "oid": "1.3.6.1.2.1.31.1.1.1.10.1488"}, - {"hostname": "130.206.206.250", "community": "atlas1453", "oid": "1.3.6.1.2.1.31.1.1.1.10.1489"}, - {"hostname": "130.206.206.250", "community": "atlas1453", "oid": "1.3.6.1.2.1.31.1.1.1.10.760"}, - {"hostname": "130.206.206.250", "community": "atlas1453", "oid": "1.3.6.1.2.1.31.1.1.1.10.796"} - ] - } + "hosts": [ + { + "hostname": "130.206.206.250", + "community": "atlas1453", + "interfaces": [ + { + "tag": "a", + "counters": { + "traffic_in": "1.3.6.1.2.1.31.1.1.1.6.1487", + "traffic_out": "1.3.6.1.2.1.31.1.1.1.10.1487" + } + }, + { + "tag": "b", + "counters": { + "traffic_in": "1.3.6.1.2.1.31.1.1.1.6.1488", + "traffic_out": "1.3.6.1.2.1.31.1.1.1.10.1488" + } + }, + { + "tag": "c", + "counters": { + "traffic_in": "1.3.6.1.2.1.31.1.1.1.6.1489", + "traffic_out": "1.3.6.1.2.1.31.1.1.1.10.1489" + } + }, + { + "tag": "d", + "counters": { + "traffic_in": "1.3.6.1.2.1.31.1.1.1.6.760", + "traffic_out": "1.3.6.1.2.1.31.1.1.1.10.760" + } + }, + { + "tag": "e", + "counters": { + "traffic_in": "1.3.6.1.2.1.31.1.1.1.6.796", + "traffic_out": "1.3.6.1.2.1.31.1.1.1.10.796" + } + } + ] + } + ] }, { "nren": "RoEduNet", "isp": "Cogent", - "counters": { - "traffic_in": [ - {"hostname": "149.6.50.10", "community": "dante", "oid": "1.3.6.1.2.1.31.1.1.1.6.531"} - ], - "traffic_out": [ - {"hostname": "149.6.50.10", "community": "dante", "oid": "1.3.6.1.2.1.31.1.1.1.10.531"} - ] - } + "hosts": [ + { + "hostname": "149.6.50.10", + "community": "dante", + "interfaces": [ + { + "tag": "a", + "counters": { + "traffic_in": "1.3.6.1.2.1.31.1.1.1.6.531", + "traffic_out": "1.3.6.1.2.1.31.1.1.1.10.531" + } + } + ] + } + ] }, { "nren": "RoEduNet", "isp": "Century Link", - "counters": { - "traffic_in": [ - {"hostname": "212.162.45.194", "community": "dante", "oid": "1.3.6.1.2.1.31.1.1.1.6.9"} - ], - "traffic_out": [ - {"hostname": "212.162.45.194", "community": "dante", "oid": "1.3.6.1.2.1.31.1.1.1.10.9"} - ] - } + "hosts": [ + { + "hostname": "212.162.45.194", + "community": "dante", + "interfaces": [ + { + "tag": "a", + "counters": { + "traffic_in": "1.3.6.1.2.1.31.1.1.1.6.9", + "traffic_out": "1.3.6.1.2.1.31.1.1.1.10.9" + } + } + ] + } + ] }, { "nren": "EENet", "isp": "Telia", - "counters": { - "traffic_in": [ - {"hostname": "193.40.133.2", "community": "geant-mon-telia", "oid": "1.3.6.1.2.1.31.1.1.1.6.263"} - ], - "traffic_out": [ - {"hostname": "193.40.133.2", "community": "geant-mon-telia", "oid": "1.3.6.1.2.1.31.1.1.1.10.263"} - ] - } + "hosts": [ + { + "hostname": "193.40.133.2", + "community": "geant-mon-telia", + "interfaces": [ + { + "tag": "a", + "counters": { + "traffic_in": "1.3.6.1.2.1.31.1.1.1.6.263", + "traffic_out": "1.3.6.1.2.1.31.1.1.1.10.263" + } + } + ] + } + ] }, { "nren": "PSNC", "isp": "Century Link", - "counters": { - "traffic_in": [ - {"hostname": "212.191.126.6", "community": "atlas1453", "oid": "1.3.6.1.2.1.31.1.1.1.6.675"}, - {"hostname": "212.191.126.7", "community": "atlas1453", "oid": "1.3.6.1.2.1.31.1.1.1.6.677"} - ], - "traffic_out": [ - {"hostname": "212.191.126.6", "community": "atlas1453", "oid": "1.3.6.1.2.1.31.1.1.1.10.675"}, - {"hostname": "212.191.126.7", "community": "atlas1453", "oid": "1.3.6.1.2.1.31.1.1.1.10.677"} - ] - } + "hosts": [ + { + "hostname": "212.191.126.6", + "community": "atlas1453", + "interfaces": [ + { + "tag": "a", + "counters": { + "traffic_in": "1.3.6.1.2.1.31.1.1.1.6.675", + "traffic_out": "1.3.6.1.2.1.31.1.1.1.10.675" + } + } + ] + }, + { + "hostname": "212.191.126.7", + "community": "atlas1453", + "interfaces": [ + { + "tag": "a", + "counters": { + "traffic_in": "1.3.6.1.2.1.31.1.1.1.6.677", + "traffic_out": "1.3.6.1.2.1.31.1.1.1.10.677" + } + } + ] + } + ] } ] \ No newline at end of file