Update Documentation
[oam.git] / solution / dev / client-scripts-ves-v7 / sendVesNotification.py
1 #!/usr/bin/env python
2 ################################################################################
3 # Copyright 2021 highstreet technologies GmbH
4 #
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
8 #
9 #     https://www.apache.org/licenses/LICENSE-2.0
10 #
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.
16 #
17
18 ################################################################################
19 # Send a VES event for domain 'notification'
20
21 # importing the sys, json, requests library
22 import sys
23 import getopt
24 import json
25 import requests
26 from globalVesEventEmitter import getInitData, saveExample, sendVesEvent
27
28 # Construct VES body and send
29 def performJob(domain, pnfId):
30     initData = getInitData(domain)
31     initData['pnfId'] = pnfId
32
33     print('################################################################################')
34     print('# send VES ' + domain)
35
36     initData['body']['event']['commonEventHeader']['domain'] = initData['domain']
37     initData['body']['event']['commonEventHeader']['eventId'] = initData['fqdn'] + \
38         '_' + initData['eventTime']
39     initData['body']['event']['commonEventHeader']['eventName'] = initData['domain'] + \
40         '_' + initData['config']['settings']['eventType']
41     initData['body']['event']['commonEventHeader']['eventType'] = initData['config']['settings']['eventType']
42     initData['body']['event']['commonEventHeader']['sequence'] = initData['config']['settings']['sequence']
43     initData['body']['event']['commonEventHeader']['reportingEntityName'] = initData['fqdn']
44     initData['body']['event']['commonEventHeader']['sourceName'] = initData['pnfId']
45     initData['body']['event']['commonEventHeader']['startEpochMicrosec'] = initData['timestamp']
46     initData['body']['event']['commonEventHeader']['lastEpochMicrosec'] = initData['timestamp']
47     initData['body']['event']['commonEventHeader']['nfNamingCode'] = initData['pnfId']
48     initData['body']['event']['commonEventHeader']['nfVendorName'] = 'O-RAN-SC OAM'
49
50     initData['body']['event']['notificationFields']['additionalFields']['eventTime'] = initData['eventTime']
51     initData['body']['event']['notificationFields']['changeContact'] = initData['fqdn']
52     initData['body']['event']['notificationFields']['changeIdentifier'] = initData['pnfId']
53     initData['body']['event']['notificationFields']['stateInterface'] = initData['interface']
54
55     # Save example body
56     saveExample(initData)
57
58     # Send VES Event
59     sendVesEvent(initData)
60
61
62 # Analysing command line parameters
63 def main(argv):
64     domain = 'notification'
65     usage = 'sendVesNotification.py --pnfId <physical-network-function-nwuid>'
66     pnfId = ''
67     try:
68         opts, args = getopt.getopt(argv, "hi:o:", ["pnfId="])
69     except getopt.GetoptError:
70         print(usage)
71         sys.exit(2)
72     for opt, arg in opts:
73         if opt in ('-h', '--help'):
74             print(usage)
75             sys.exit()
76         elif opt in ("-p", "--pnfId"):
77             pnfId = arg
78             performJob(domain, pnfId)
79
80
81 if __name__ == "__main__":
82     main(sys.argv[1:])