Create VES client example for domain 'notification' 52/5852/2
authordemx8as6 <martin.skorupski@highstreet-technologies.com>
Fri, 2 Apr 2021 13:11:57 +0000 (15:11 +0200)
committerdemx8as6 <martin.skorupski@highstreet-technologies.com>
Fri, 2 Apr 2021 14:18:50 +0000 (16:18 +0200)
- first a simpler heardbeat was added
- python script for 'notification'
- common functions are in globalVesEventEmitter.py
- The READMEpy.md is a preparation to replace the README.md

IssueID: OAM-183
Change-Id: Ie2de8f9471562720b7b2226a7001b6d0f0f7038e
Signed-off-by: demx8as6 <martin.skorupski@highstreet-technologies.com>
solution/dev/ves-test-collector/client-scripts-ves-v7/READMEpy.md
solution/dev/ves-test-collector/client-scripts-ves-v7/globalVesEventEmitter.py
solution/dev/ves-test-collector/client-scripts-ves-v7/json/templates/notification.json [new file with mode: 0644]
solution/dev/ves-test-collector/client-scripts-ves-v7/sendVesNotification.py

index 182129d..a363cfd 100644 (file)
@@ -27,7 +27,13 @@ tbd.
 
 ### VES Domain "heartbeat",
 
-tbd.
+The script simulates a VES event of domain "heartbeat" from SDN-R to DCAE VES-Collector.
+
+The following example show the usage of this script:
+
+```
+python3 sendVesHeartbeat.py
+```
 
 ### VES Domain "measurement",
 
@@ -39,7 +45,14 @@ tbd.
 
 ### VES Domain "notification",
 
-tbd.
+The script simulates a VES event of domain "notification" from a physical 
+network-function to DCAE VES-Collector.
+
+The following example show the usage of this script:
+
+```
+python3 sendVesNotification.py --pnfId nSky
+```
 
 ### VES Domain "other",
 
index f9a1fd9..1776b96 100644 (file)
@@ -36,6 +36,7 @@ def getInitData(domain):
   result['fqdn']= socket.getfqdn()
   result['timestamp']= int(currentTime.timestamp()*1000000)
   result['eventTime']= currentTime.isoformat() + 'Z'
+  result['interface']= "urn:ietf:params:xml:ns:yang:ietf-interfaces:interfaces/interface/name='O-RAN-SC-OAM'"
 
   # Read config
   with open('config.yml', 'r') as stream:
@@ -55,7 +56,9 @@ def getInitData(domain):
 
 def saveExample(data):
   if 'directory' in data and 'domain' in data and 'body' in data:
-    outputFileName = data['directory'] + '/json/examples/' + data['domain'] + '.json'
+    name = data['domain']
+    if 'pnfId' in data: name = '-'.join( (data['pnfId'], data['domain']) )
+    outputFileName = data['directory'] + '/json/examples/' + name + '.json'
     with open(outputFileName, 'w') as f:
       json.dump(data['body'], f, indent=2, sort_keys=True)
   else:
diff --git a/solution/dev/ves-test-collector/client-scripts-ves-v7/json/templates/notification.json b/solution/dev/ves-test-collector/client-scripts-ves-v7/json/templates/notification.json
new file mode 100644 (file)
index 0000000..03552f7
--- /dev/null
@@ -0,0 +1,35 @@
+{
+    "event": {
+        "commonEventHeader": {
+            "domain": "@domain@",
+            "eventId": "@eventId@",
+            "eventName": "@domain@_@eventType@",
+            "eventType": "@eventType@",
+            "sequence": 0,
+            "priority": "Low",
+            "reportingEntityId": "",
+            "reportingEntityName": "@controllerName@",
+            "sourceId": "",
+            "sourceName": "@pnfId@",
+            "startEpochMicrosec": "@timestamp@",
+            "lastEpochMicrosec": "@timestamp@",
+            "nfNamingCode": "@type@",
+            "nfVendorName": "@vendor@",
+            "timeZoneOffset": "+00:00",
+            "version": "4.1",
+            "vesEventListenerVersion": "7.2.1"
+        },
+        "notificationFields": {
+            "additionalFields": {
+                "eventTime": "@eventTime@"
+            },
+            "changeContact": "@controllerName@",
+            "changeIdentifier": "@pnfId@",
+            "changeType": "informal",
+            "newState": "all-good",
+            "oldState": "not-too-bad",
+            "notificationFieldsVersion": "2.0",
+            "stateInterface": "@interface@"
+        }
+    }
+}
\ No newline at end of file
index 99b7784..6c4d521 100644 (file)
@@ -2,14 +2,14 @@
 ################################################################################
 # Copyright 2021 highstreet technologies GmbH
 #
-# Licensed under the Apache License, Version 2.0 (the "License");
+# 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,
+# 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.
 ################################################################################
 # Send a VES event for domain 'notification'
 
-# importing the datetime, json, requests, os socket and yaml library
-import datetime
+# importing the sys, json, requests library
+import sys
+import getopt
 import json
 import requests
-import os
-import socket
-import yaml
-from pathlib import Path
+from globalVesEventEmitter import getInitData, saveExample
 
-# Globals
-dir = os.path.dirname(os.path.realpath(__file__))
-domain = "notification"
-fqdn = socket.getfqdn()
+# Construct VES body and send
+def performJob(domain, pnfId):
+    initData = getInitData(domain)
+    initData['pnfId'] = pnfId
 
-# time formats
-currentTime = datetime.datetime.utcnow()
-timestamp = int(currentTime.timestamp()*1000000)
-eventTime = currentTime.isoformat() + "Z"
+    print('################################################################################')
+    print('# send VES ' + domain)
 
-# Create output path
-Path(dir + "/json/examples").mkdir(parents=True, exist_ok=True)
+    initData['body']['event']['commonEventHeader']['domain'] = initData['domain']
+    initData['body']['event']['commonEventHeader']['eventId'] = initData['fqdn'] + \
+        '_' + initData['eventTime']
+    initData['body']['event']['commonEventHeader']['eventName'] = initData['domain'] + \
+        '_' + initData['config']['settings']['eventType']
+    initData['body']['event']['commonEventHeader']['eventType'] = initData['config']['settings']['eventType']
+    initData['body']['event']['commonEventHeader']['sequence'] = initData['config']['settings']['sequence']
+    initData['body']['event']['commonEventHeader']['reportingEntityName'] = initData['fqdn']
+    initData['body']['event']['commonEventHeader']['sourceName'] = initData['pnfId']
+    initData['body']['event']['commonEventHeader']['startEpochMicrosec'] = initData['timestamp']
+    initData['body']['event']['commonEventHeader']['lastEpochMicrosec'] = initData['timestamp']
+    initData['body']['event']['commonEventHeader']['nfNamingCode'] = initData['pnfId']
+    initData['body']['event']['commonEventHeader']['nfVendorName'] = 'O-RAN-SC OAM'
 
-# Read settings
-with open("config.yml", 'r') as stream:
-    try:
-        cfg = yaml.safe_load(stream)
-    except yaml.YAMLError as exc:
-        print(exc)
+    initData['body']['event']['notificationFields']['additionalFields']['eventTime'] = initData['eventTime']
+    initData['body']['event']['notificationFields']['changeContact'] = initData['fqdn']
+    initData['body']['event']['notificationFields']['changeIdentifier'] = initData['pnfId']
+    initData['body']['event']['notificationFields']['stateInterface'] = initData['interface']
+
+    # Save example body
+    saveExample(initData)
 
-print("################################################################################")
-print("# send SDN-Controller " + domain)
+    # Send VES Event
+    url = initData['config']['vesEndpoint']['url']
+    username = initData['config']['vesEndpoint']['username']
+    password = initData['config']['vesEndpoint']['password']
+    verify = initData['config']['vesEndpoint']['verify']
+    response = requests.post(url, json=initData['body'], auth=(
+        username, password), verify=verify)
+    print(response)
 
-# Read template body
-templateFileName = dir + "/json/templates/" + domain + ".json"
-with open(templateFileName) as f:
-    data = json.load(f)
+# Analysing command line parameters
 
-data["event"]["commonEventHeader"]["domain"] = domain
-data["event"]["commonEventHeader"]["eventId"] = fqdn + "_" + eventTime
-data["event"]["commonEventHeader"]["eventName"] = domain + \
-    "_" + cfg["settings"]["eventType"]
-data["event"]["commonEventHeader"]["eventType"] = cfg["settings"]["eventType"]
-data["event"]["commonEventHeader"]["sequence"] = cfg["settings"]["sequence"]
-data["event"]["commonEventHeader"]["reportingEntityName"] = fqdn
-data["event"]["commonEventHeader"]["sourceName"] = fqdn
-data["event"]["commonEventHeader"]["startEpochMicrosec"] = timestamp
-data["event"]["commonEventHeader"]["lastEpochMicrosec"] = timestamp
-data["event"]["commonEventHeader"]["nfNamingCode"] = "SDN-Controller"
-data["event"]["commonEventHeader"]["nfVendorName"] = "O-RAN-SC OAM"
 
-data["event"]["heartbeatFields"]["additionalFields"]["eventTime"] = eventTime
+def main(argv):
+    domain = 'notification'
+    usage = 'sendVesNotification.py --pnfId <physical-network-function-nwuid>'
+    pnfId = ''
+    try:
+        opts, args = getopt.getopt(argv, "hi:o:", ["pnfId="])
+    except getopt.GetoptError:
+        print(usage)
+        sys.exit(2)
+    for opt, arg in opts:
+        if opt in ('-h', '--help'):
+            print(usage)
+            sys.exit()
+        elif opt in ("-p", "--pnfId"):
+            pnfId = arg
+            performJob(domain, pnfId)
 
-# save example body
-outputFileName = dir + "/json/examples/" + domain + ".json"
-with open(outputFileName, 'w') as f:
-    json.dump(data, f, indent=2, sort_keys=True)
 
-# Send VES Event
-url = cfg["vesEndpoint"]["url"]
-username = cfg["vesEndpoint"]["username"]
-password = cfg["vesEndpoint"]["password"]
-verify = cfg["vesEndpoint"]["verify"]
-response = requests.post(url, json=data, auth=(username, password), verify=verify)
-print(response)
+if __name__ == "__main__":
+    main(sys.argv[1:])