--- /dev/null
+{
+ "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
################################################################################
# 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:])