Init version
[oam.git] / solution / dev / ves-test-collector / client-scripts-ves-v7 / sendVesHeartbeat.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 #     http://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 'heartbeat'
20
21 # importing the datetime, json, requests, os socket and yaml library
22 import json
23 import requests
24 from globalVesEventEmitter import getInitData
25
26 # Globals
27 domain = 'heartbeat'
28 initData = getInitData(domain)
29
30 print('################################################################################')
31 print('# send SDN-Controller ' + domain)
32
33 initData['body']['event']['commonEventHeader']['domain'] = initData['domain']
34 initData['body']['event']['commonEventHeader']['eventId'] = initData['fqdn'] + '_' + initData['eventTime']
35 initData['body']['event']['commonEventHeader']['eventName'] = initData['domain'] + '_' + initData['config']['settings']['eventType']
36 initData['body']['event']['commonEventHeader']['eventType'] = initData['config']['settings']['eventType']
37 initData['body']['event']['commonEventHeader']['sequence'] = initData['config']['settings']['sequence']
38 initData['body']['event']['commonEventHeader']['reportingEntityName'] = initData['fqdn']
39 initData['body']['event']['commonEventHeader']['sourceName'] =initData['fqdn']
40 initData['body']['event']['commonEventHeader']['startEpochMicrosec'] = initData['timestamp']
41 initData['body']['event']['commonEventHeader']['lastEpochMicrosec'] = initData['timestamp']
42 initData['body']['event']['commonEventHeader']['nfNamingCode'] = 'SDN-Controller'
43 initData['body']['event']['commonEventHeader']['nfVendorName'] = 'O-RAN-SC OAM'
44
45 initData['body']['event']['heartbeatFields']['additionalFields']['eventTime'] = initData['eventTime']
46
47 # Save example body
48 outputFileName = initData['directory'] + '/json/examples/' + domain + '.json'
49 with open(outputFileName, 'w') as f:
50     json.dump(initData['body'], f, indent=2, sort_keys=True)
51
52 # Send VES Event
53 url = initData['config']['vesEndpoint']['url']
54 username = initData['config']['vesEndpoint']['username']
55 password = initData['config']['vesEndpoint']['password']
56 verify = initData['config']['vesEndpoint']['verify']
57 response = requests.post(url, json=initData['body'], auth=(username, password), verify=verify)
58 print(response)