Add to_directory method to relevant object classes
[oam.git] / code / 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 from globalVesEventEmitter import getInitData, saveExample, sendVesEvent
25
26 # Construct VES body and send
27 def performJob(domain, pnfId):
28     initData = getInitData(domain)
29     initData['pnfId'] = pnfId
30
31     print('################################################################################')
32     print('# send VES ' + domain)
33
34     initData['body']['event']['commonEventHeader']['domain'] = initData['domain']
35     initData['body']['event']['commonEventHeader']['eventId'] = initData['fqdn'] + \
36         '_' + initData['eventTime']
37     initData['body']['event']['commonEventHeader']['eventName'] = initData['domain'] + \
38         '_' + initData['config']['settings']['eventType']
39     initData['body']['event']['commonEventHeader']['eventType'] = initData['config']['settings']['eventType']
40     initData['body']['event']['commonEventHeader']['sequence'] = initData['config']['settings']['sequence']
41     initData['body']['event']['commonEventHeader']['reportingEntityName'] = initData['fqdn']
42     initData['body']['event']['commonEventHeader']['sourceName'] = initData['pnfId']
43     initData['body']['event']['commonEventHeader']['startEpochMicrosec'] = initData['timestamp']
44     initData['body']['event']['commonEventHeader']['lastEpochMicrosec'] = initData['timestamp']
45     initData['body']['event']['commonEventHeader']['nfNamingCode'] = initData['pnfId']
46     initData['body']['event']['commonEventHeader']['nfVendorName'] = 'O-RAN-SC OAM'
47
48     initData['body']['event']['notificationFields']['additionalFields']['eventTime'] = initData['eventTime']
49     initData['body']['event']['notificationFields']['changeContact'] = initData['fqdn']
50     initData['body']['event']['notificationFields']['changeIdentifier'] = initData['pnfId']
51     initData['body']['event']['notificationFields']['stateInterface'] = initData['interface']
52
53     # Save example body
54     saveExample(initData)
55
56     # Send VES Event
57     sendVesEvent(initData)
58
59
60 # Analysing command line parameters
61 def main(argv):
62     domain = 'notification'
63     usage = 'sendVesNotification.py --pnfId <physical-network-function-nwuid>'
64     pnfId = ''
65     try:
66         opts, args = getopt.getopt(argv, "hi:o:", ["pnfId="])
67     except getopt.GetoptError:
68         print(usage)
69         sys.exit(2)
70     for opt, arg in opts:
71         if opt in ('-h', '--help'):
72             print(usage)
73             sys.exit()
74         elif opt in ("-p", "--pnfId"):
75             pnfId = arg
76             performJob(domain, pnfId)
77
78
79 if __name__ == "__main__":
80     main(sys.argv[1:])