From c554903563b5b99aa7e032169adc5171a0a3eba1 Mon Sep 17 00:00:00 2001 From: Erik Reid <erik.reid@geant.org> Date: Wed, 2 Jun 2021 10:43:15 +0200 Subject: [PATCH] added /poller/gws/direct with hard-coded data --- inventory_provider/routes/poller.py | 399 +++++++++++++++++++++++++++- 1 file changed, 398 insertions(+), 1 deletion(-) diff --git a/inventory_provider/routes/poller.py b/inventory_provider/routes/poller.py index 900fd11c..18275d9f 100644 --- a/inventory_provider/routes/poller.py +++ b/inventory_provider/routes/poller.py @@ -2,7 +2,7 @@ import json import logging import re -from flask import Blueprint, Response, current_app, request +from flask import Blueprint, Response, current_app, request, jsonify from lxml import etree from inventory_provider import juniper @@ -117,6 +117,56 @@ MULTICAST_SUBSCRIPTION_LIST_SCHEMA = { 'items': {'$ref': '#/definitions/subscription'} } +GWS_DIRECT_DATA_SCHEMA = { + '$schema': 'http://json-schema.org/draft-07/schema#', + + 'definitions': { + 'snmp-counter': { + 'type': 'object', + 'properties': { + 'hostname': {'type': 'string'}, + 'community': {'type': 'string'}, + 'oid': { + 'type': 'string', + 'pattern': r'^(\d+\.)*\d+$' + } + }, + 'required': ['hostname', 'community', 'oid'], + 'additionalProperties': False + }, + 'snmp-counter-list': { + 'type': 'array', + 'items': {'$ref': '#/definitions/snmp-counter'}, + 'minItems': 1 + }, + 'isp-counters': { + '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'} + }, + 'required': ['traffic_in', 'traffic_out'], + 'additionalProperties': False + }, + 'nren-isp-direct-counters': { + 'type': 'object', + 'properties': { + 'nren': {'type': 'string'}, + 'isp': {'type': 'string', 'enum': ['Cogent', 'Telia', 'Century Link']}, + 'counters': {'$ref': '#/definitions/isp-counters'}, + }, + 'required': ['nren', 'isp', 'counters'], + 'additionalProperties': False + } + }, + + 'type': 'array', + 'items': {'$ref': '#/definitions/nren-isp-direct-counters'} +} @routes.after_request def after_request(resp): @@ -522,3 +572,350 @@ def eumetsat_multicast(hostname=None): r.set(cache_key, result.encode('utf-8')) return Response(result, mimetype="application/json") + + +@routes.route("/gws/direct", methods=['GET', 'POST']) +@common.require_accepts_json +def gws_direct(): + data = [ + { + "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" + } + ] + } + }, + { + "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" + } + ] + } + }, + { + "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" + } + ] + } + }, + { + "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" + } + ] + } + }, + { + "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" + } + ] + } + }, + { + "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" + } + ] + } + }, + { + "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" + } + ] + } + }, + { + "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" + } + ] + } + }, + { + "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" + } + ] + } + }, + { + "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" + } + ] + } + }, + { + "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" + } + ] + } + } + ] + + return jsonify(data) -- GitLab