1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2020-2021] [HCL Technologies Ltd.] #
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. #
16 ################################################################################
17 *******************************************************************************/
19 /* This file contains functions to support the preparation of VES Event
20 It is the parent class of Ves Event, Every event need to override at
21 least prepareEventFields function and fill specific values of event
24 #include "VesEvent.hpp"
27 /* Default constructor*/
34 /* Default Destructor*/
37 if(mHttpClient != NULL)
43 /*******************************************************************
45 * @brief prepare Ves Event Fields
52 * - prepare Ves Event Fields in json format
54 * @params[in] IN - void
55 * @return true - success
58 * ****************************************************************/
60 bool VesEvent::prepare()
63 if(!readConfigFile()) {
64 O1_LOG("\nO1 VesEvent : Could not get SMO details");
68 mHttpClient = new HttpClient(mVesServerIp, mVesServerPort, mVesServerUsername, \
71 cJSON *rootNode = JsonHelper::createNode();
73 O1_LOG("\nO1 VesEvent : could not create cJSON root Node object");
77 cJSON *event = JsonHelper::createNode();
79 O1_LOG("\nO1 VesEvent : could not create event cJSON object");
80 JsonHelper::deleteNode(rootNode);
84 if(JsonHelper::addJsonNodeToObject(rootNode, "event", event) == 0) {
85 O1_LOG("\nO1 VesEvent : could not add event Object");
86 JsonHelper::deleteNode(rootNode);
90 cJSON *commHdrNode = JsonHelper::createNode();
91 if(commHdrNode == 0) {
92 O1_LOG("\nO1 VesEvent : could not create common header Node JSON object");
96 VesCommonHeader vesCommHdr;
98 if(vesCommHdr.prepare(commHdrNode, mVesEventType))
100 if(JsonHelper::addJsonNodeToObject(event, "commonEventHeader", \
102 O1_LOG("\nO1 VesEvent : could not add commonEventHeader object");
103 JsonHelper::deleteNode(rootNode);
108 //add header into the message and create pnfFields
109 mVesEventFields = JsonHelper::createNode();
110 if(mVesEventFields == 0) {
111 O1_LOG("\nO1 VesEvent : could not create Ves Event Fields JSON object");
115 if(!prepareEventFields()) {
116 O1_LOG("\nO1 VesEvent : could not prepare Ves Event Fields Node");
117 JsonHelper::deleteNode(rootNode);
121 if(JsonHelper::addJsonNodeToObject(event, "pnfRegistrationFields", mVesEventFields) == 0) {
122 O1_LOG("\nO1 VesEvent : could not add mVesEventFields object");
123 JsonHelper::deleteNode(rootNode);
127 mSendData = JsonHelper::printUnformatted(rootNode);
128 O1_LOG("\nO1 VesEvent : VES request : -- \n%s\n", JsonHelper::print(rootNode));
133 O1_LOG("\nO1 VesEvent : Failed to prepare preparePnfRegistration common header");
134 JsonHelper::deleteNode(rootNode);
140 bool VesEvent::send()
142 return mHttpClient->send(mSendData);
145 /*******************************************************************
147 * @brief Read Ves Collector config json file
151 * Function : readConfigFile
158 * @return true : success
160 ******************************************************************/
162 bool VesEvent::readConfigFile()
164 cJSON *json = JsonHelper::read(VES_CONFIG);
166 O1_LOG("\nO1 VesEvent : Error reading config file :%s", JsonHelper::getError());
170 cJSON *rootNode = NULL;
171 rootNode = JsonHelper::getNode(json, "vesConfig");
173 O1_LOG("\nO1 VesEvent : Reading smoConfig.json file\n");
174 mVesServerIp = JsonHelper::getValue(rootNode, "vesV4IpAddress");
175 mVesServerPort = JsonHelper::getValue(rootNode, "vesPort");
176 mVesServerUsername = JsonHelper::getValue(rootNode, "username");
177 mVesServerPassword = JsonHelper::getValue(rootNode, "password");
180 O1_LOG("\nO1 VesEvent : smoConfig Object is not available in config file");
184 JsonHelper::deleteNode(json);