2 ################################################################################
3 # Copyright 2021 highstreet technologies GmbH
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 ################################################################################
19 # Send a VES event for domain 'notification'
21 # importing the datetime, json, requests, os socket and yaml library
28 from pathlib import Path
31 dir = os.path.dirname(os.path.realpath(__file__))
32 domain = "notification"
33 fqdn = socket.getfqdn()
36 currentTime = datetime.datetime.utcnow()
37 timestamp = int(currentTime.timestamp()*1000000)
38 eventTime = currentTime.isoformat() + "Z"
41 Path(dir + "/json/examples").mkdir(parents=True, exist_ok=True)
44 with open("config.yml", 'r') as stream:
46 cfg = yaml.safe_load(stream)
47 except yaml.YAMLError as exc:
50 print("################################################################################")
51 print("# send SDN-Controller " + domain)
54 templateFileName = dir + "/json/templates/" + domain + ".json"
55 with open(templateFileName) as f:
58 data["event"]["commonEventHeader"]["domain"] = domain
59 data["event"]["commonEventHeader"]["eventId"] = fqdn + "_" + eventTime
60 data["event"]["commonEventHeader"]["eventName"] = domain + \
61 "_" + cfg["settings"]["eventType"]
62 data["event"]["commonEventHeader"]["eventType"] = cfg["settings"]["eventType"]
63 data["event"]["commonEventHeader"]["sequence"] = cfg["settings"]["sequence"]
64 data["event"]["commonEventHeader"]["reportingEntityName"] = fqdn
65 data["event"]["commonEventHeader"]["sourceName"] = fqdn
66 data["event"]["commonEventHeader"]["startEpochMicrosec"] = timestamp
67 data["event"]["commonEventHeader"]["lastEpochMicrosec"] = timestamp
68 data["event"]["commonEventHeader"]["nfNamingCode"] = "SDN-Controller"
69 data["event"]["commonEventHeader"]["nfVendorName"] = "O-RAN-SC OAM"
71 data["event"]["heartbeatFields"]["additionalFields"]["eventTime"] = eventTime
74 outputFileName = dir + "/json/examples/" + domain + ".json"
75 with open(outputFileName, 'w') as f:
76 json.dump(data, f, indent=2, sort_keys=True)
79 url = cfg["vesEndpoint"]["url"]
80 username = cfg["vesEndpoint"]["username"]
81 password = cfg["vesEndpoint"]["password"]
82 verify = cfg["vesEndpoint"]["verify"]
83 response = requests.post(url, json=data, auth=(username, password), verify=verify)