Update release notes for Sprint 4
[oam.git] / solution / dev / client-scripts-ves-v7 / sendVesStndDefined.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 'stndDefined' with 3gpp fault body
20 # https://raw.githubusercontent.com/onap/testsuite/master/robot/assets/dcae/ves_stndDefined_3GPP-FaultSupervision.json
21 # https://forge.3gpp.org/rep/sa5/MnS/blob/SA88-Rel16/OpenAPI/faultMnS.yaml
22
23 # importing the sys, json, requests library
24 import sys
25 import getopt
26 import json
27 import requests
28 from globalVesEventEmitter import getInitData, saveExample, sendVesEvent
29
30 # Construct VES body and send
31 def performJob(domain, pnfId, stdnBody):
32     initData = getInitData(domain, stdnBody)
33     initData['pnfId'] = pnfId
34
35     print('################################################################################')
36     print(' '.join( ('# send VES', domain, stdnBody) ) )
37
38     initData['body']['event']['commonEventHeader']['domain'] = initData['domain']
39     initData['body']['event']['commonEventHeader']['eventId'] = initData['fqdn'] + \
40         '_' + initData['eventTime']
41     initData['body']['event']['commonEventHeader']['eventName'] = initData['domain'] + \
42         '_' + initData['config']['settings']['eventType']
43     initData['body']['event']['commonEventHeader']['eventType'] = initData['config']['settings']['eventType']
44     initData['body']['event']['commonEventHeader']['sequence'] = initData['config']['settings']['sequence']
45     initData['body']['event']['commonEventHeader']['reportingEntityName'] = initData['fqdn']
46     initData['body']['event']['commonEventHeader']['sourceName'] = initData['pnfId']
47     initData['body']['event']['commonEventHeader']['startEpochMicrosec'] = initData['timestamp']
48     initData['body']['event']['commonEventHeader']['lastEpochMicrosec'] = initData['timestamp']
49     initData['body']['event']['commonEventHeader']['nfNamingCode'] = initData['pnfId']
50     initData['body']['event']['commonEventHeader']['nfVendorName'] = 'O-RAN-SC OAM'
51
52     initData['body']['event']['stndDefinedFields']['data']['eventTime'] = initData['eventTime']
53     initData['body']['event']['stndDefinedFields']['data']['eventTime'] = 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 = 'stndDefined'
65     usage = 'sendVesStndDefined.py --pnfId <physical-network-function-nwuid> --body <3gpp-Fault | 3GPP-Heartbeat | 3GPP-PerformanceAssurance | 3GPP-Provisioning>'
66     pnfId = ''
67     stdnBody = ''
68     try:
69         opts, args = getopt.getopt(argv, "hi:o:", ["pnfId=", "body="])
70     except getopt.GetoptError:
71         print(usage)
72         sys.exit(2)
73     for opt, arg in opts:
74         if opt in ('-h', '--help'):
75             print(usage)
76             sys.exit()
77         elif opt in ("-p", "--pnfId"):
78             pnfId = arg
79         elif opt in ("-b", "--body"):
80             stdnBody = arg
81
82     performJob(domain, pnfId, stdnBody)
83
84
85 if __name__ == "__main__":
86     main(sys.argv[1:])