From cdaeca62054605b5fb9e099d80cdc1f42f3f91bb Mon Sep 17 00:00:00 2001
From: Erik Reid <erik.reid@geant.org>
Date: Tue, 8 Jun 2021 12:56:48 +0200
Subject: [PATCH] updated gws-direct schema

---
 inventory_provider/config.py        | 66 ++++++++++++++++-------------
 inventory_provider/routes/poller.py | 60 +++++++++++++++-----------
 2 files changed, 72 insertions(+), 54 deletions(-)

diff --git a/inventory_provider/config.py b/inventory_provider/config.py
index 4b0a42bd..4881d4c1 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 8aacdf41..5a586360 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'}
 }
 
 
-- 
GitLab