Init version
[oam.git] / solution / dev / ves-test-collector / client-scripts-ves-v7 / globalVesEventEmitter.py
diff --git a/solution/dev/ves-test-collector/client-scripts-ves-v7/globalVesEventEmitter.py b/solution/dev/ves-test-collector/client-scripts-ves-v7/globalVesEventEmitter.py
new file mode 100644 (file)
index 0000000..30d596f
--- /dev/null
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+################################################################################
+# Copyright 2021 highstreet technologies GmbH
+#
+# Licensed under the Apache License, Version 2.0 (the 'License');
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an 'AS IS' BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+################################################################################
+# A selection of common methods
+
+import datetime
+import json
+import os
+import socket
+import yaml
+from pathlib import Path
+
+def getInitData(domain):
+  currentTime = datetime.datetime.utcnow()
+  dir = os.path.dirname(os.path.realpath(__file__))
+
+  result = {}
+  result['domain']= domain
+  result['directory']= dir
+  result['outdir']= dir + '/json/examples'
+  result['fqdn']= socket.getfqdn()
+  result['timestamp']= int(currentTime.timestamp()*1000000)
+  result['eventTime']= currentTime.isoformat() + 'Z'
+
+  # Read config
+  with open('config.yml', 'r') as stream:
+    try:
+        result['config']= yaml.safe_load(stream)
+    except yaml.YAMLError as exc:
+        print(exc)
+
+  # Read template body
+  templateFileName = dir + '/json/templates/' + domain + '.json'
+  with open(templateFileName) as f:
+    result['body']= json.load(f)
+
+  
+  Path(result["outdir"]).mkdir(parents=True, exist_ok=True)
+  return result