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 O1_LOG("O1 VES : prepare PNF Registration start\n");
64 if(!getVesCollectorDetails()) {
65 O1_LOG("O1 VES : Could not get successfully details of Ves Collector\n");
69 mHttpClient = new HttpClient(mVesServerIp, mVesServerPort, mVesServerUsername, \
72 cJSON *rootNode = JsonHelper::createNode();
74 O1_LOG("O1 VES : could not create cJSON root Node object\n");
78 cJSON *event = JsonHelper::createNode();
80 O1_LOG("O1 VES : could not create event cJSON object\n");
81 JsonHelper::deleteNode(rootNode);
85 if(JsonHelper::addJsonNodeToObject(rootNode, "event", event) == 0) {
86 O1_LOG("O1 VES : could not add event Object\n");
87 JsonHelper::deleteNode(rootNode);
91 cJSON *commHdrNode = JsonHelper::createNode();
92 if(commHdrNode == 0) {
93 O1_LOG("O1 VES : could not create common header Node JSON object");
97 VesCommonHeader vesCommHdr;
99 if(vesCommHdr.prepare(commHdrNode, mVesEventType))
101 if(JsonHelper::addJsonNodeToObject(event, "commonEventHeader", \
103 O1_LOG("O1 VES : could not add commonEventHeader object\n");
104 JsonHelper::deleteNode(rootNode);
109 //add header into the message and create pnfFields
110 mVesEventFields = JsonHelper::createNode();
111 if(mVesEventFields == 0) {
112 O1_LOG("O1 VES : could not create Ves Event Fields JSON object\n");
116 if(!prepareEventFields()) {
117 O1_LOG("O1 VES : could not prepare Ves Event Fields Node \n");
118 JsonHelper::deleteNode(rootNode);
122 if(JsonHelper::addJsonNodeToObject(event, "pnfRegistrationFields", mVesEventFields) == 0) {
123 O1_LOG("O1 VES : could not add mVesEventFields object\n");
124 JsonHelper::deleteNode(rootNode);
128 mSendData = JsonHelper::printUnformatted(rootNode);
129 O1_LOG("O1 VES : final ves request : -- \n%s\n", JsonHelper::print(rootNode));
134 O1_LOG("O1 VES : preparePnfRegistration common header preparation failed\n");
135 JsonHelper::deleteNode(rootNode);
141 bool VesEvent::send()
143 return mHttpClient->send(mSendData);
146 /*******************************************************************
148 * @brief Gets the Ves Collector Server details
152 * Function : getVesCollectorDetails
155 * - Gets the Ves Collector Server details by reading config file
157 * @params[in] IN - pointer to pnfFields
158 * @return true - success
161 * ****************************************************************/
164 bool VesEvent::getVesCollectorDetails()
166 return readConfigFile();
169 /*******************************************************************
171 * @brief Read Ves Collector config json file
175 * Function : readConfigFile
182 * @return true : success
184 ******************************************************************/
186 bool VesEvent::readConfigFile()
188 cJSON *json = JsonHelper::read(VES_CONFIG);
190 O1_LOG("O1 VES : Config file reading error is :%s\n", JsonHelper::getError());
194 cJSON *rootNode = NULL;
195 rootNode = JsonHelper::getNode(json, "vesConfig");
197 O1_LOG("O1 VES : Reading smoConfig.json file\n");
198 mVesServerIp = JsonHelper::getValue(rootNode, "vesV4IpAddress");
199 mVesServerPort = JsonHelper::getValue(rootNode, "vesPort");
200 mVesServerUsername = JsonHelper::getValue(rootNode, "username");
201 mVesServerPassword = JsonHelper::getValue(rootNode, "password");
204 O1_LOG("O1 VES : smoConfig Object is not availbale in config file\n");
208 JsonHelper::deleteNode(json);