summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristofer Hallin <kristofer@sunet.se>2022-02-07 14:40:11 +0100
committerKristofer Hallin <kristofer@sunet.se>2022-02-07 14:40:11 +0100
commitef48cdd5b106c194c700503a51534179e1ca84ef (patch)
tree6fab39c9ff03d6215f67e04eb0f6ea6d5c21397e
parent0c61dd6f2cb637a1d6cb2babde29043669c30a9e (diff)
JSON schema for data.
-rw-r--r--src/schema.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/schema.py b/src/schema.py
new file mode 100644
index 0000000..37da5aa
--- /dev/null
+++ b/src/schema.py
@@ -0,0 +1,75 @@
+import json
+
+import jsonschema
+
+schema = {
+ "$schema": "http://json-schema.org/schema#",
+ "type": "object",
+ "properties": {
+ "document_version": {
+ "type": "integer"
+ },
+ "ip": {
+ "type": "string"
+ },
+ "port": {
+ "type": "integer"
+ },
+ "whois_description": {
+ "type": "string"
+ },
+ "asn": {
+ "type": "string"
+ },
+ "asn_country_code": {
+ "type": "string"
+ },
+ "ptr": {
+ "type": "string"
+ },
+ "abuse_mail": {
+ "type": "string"
+ },
+ "domain": {
+ "type": "string"
+ },
+ "timestamp_in_utc": {
+ "type": "string"
+ },
+ "user_presentation": {
+ "type": "object",
+ "properties": {
+ "description": {
+ "type": "string"
+ },
+ "data": {
+ "type": "object"
+ }
+ }
+ }
+ },
+ "required": [
+ "document_version",
+ "ip",
+ "port",
+ "timestamp_in_utc",
+ "user_presentation"
+ ]
+}
+
+
+def validate_collector_data(json_blob):
+ try:
+ jsonschema.validate(json_blob, schema)
+ except jsonschema.exceptions.ValidationError as e:
+ print(f'Validation failed with error: {e}')
+ return False
+
+ return True
+
+
+if __name__ == '__main__':
+ with open('example_data.json') as fd:
+ json_data = json.loads(fd.read())
+
+ validate_collector_data(json_data)