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"
25 #include "Message.hpp"
28 VesEvent::VesEvent(VesEventType eventType)
29 : mVesEventType(eventType) {
35 /* Default Destructor*/
38 if ( mHttpClient != NULL )
46 /*******************************************************************
48 * @brief Initialize the Ves Event
55 * - Intialize the Ves event with configuration
57 * Instantiates the http client
59 * @params[in] IN - void
62 * ****************************************************************/
64 void VesEvent::init(){
68 mHttpClient = new HttpClient(mVesUrl, mVesServerUsername, mVesServerPassword);
72 /*******************************************************************
74 * @brief prepare Ves Event Fields
81 * - prepare Ves Event Fields in json format
83 * @params[in] IN - void
84 * @return true - success
87 * ****************************************************************/
89 bool VesEvent::prepare(const Message* msg)
92 cJSON *rootNode = JsonHelper::createNode();
94 O1_LOG("\nO1 VesEvent : could not create cJSON root Node object");
97 cJSON *event = JsonHelper::createNode();
99 O1_LOG("\nO1 VesEvent : could not create event cJSON object");
100 JsonHelper::deleteNode(rootNode);
103 if(JsonHelper::addJsonNodeToObject(rootNode, "event", event) == 0) {
104 O1_LOG("\nO1 VesEvent : could not add event Object");
105 JsonHelper::deleteNode(rootNode);
108 cJSON *commHdrNode = JsonHelper::createNode();
109 if(commHdrNode == 0) {
110 O1_LOG("\nO1 VesEvent : could not create common header Node JSON object");
111 JsonHelper::deleteNode(rootNode);
114 VesCommonHeader vesCommHdr;
115 if(vesCommHdr.prepare(commHdrNode, mVesEventType))
117 if(JsonHelper::addJsonNodeToObject(event, "commonEventHeader", commHdrNode) == 0)
119 O1_LOG("\nO1 VesEvent : could not add commonEventHeader object");
120 JsonHelper::deleteNode(rootNode);
124 //add header into the message and create pnfFields
125 mVesEventFields = JsonHelper::createNode();
126 if(mVesEventFields == 0) {
127 O1_LOG("\nO1 VesEvent : could not create Ves Event Fields JSON object");
128 JsonHelper::deleteNode(rootNode);
131 if(!prepareEventFields(msg)) {
132 O1_LOG("\nO1 VesEvent : could not prepare Ves Event Fields Node");
133 JsonHelper::deleteNode(rootNode);
136 if(JsonHelper::addJsonNodeToObject(event, getEventFieldName().c_str(), mVesEventFields) == 0) {
137 O1_LOG("\nO1 VesEvent : could not add mVesEventFields object");
138 JsonHelper::deleteNode(rootNode);
141 mSendData = JsonHelper::printUnformatted(rootNode);
142 char* rootNode_string = JsonHelper::print(rootNode);
143 O1_LOG("\nO1 VesEvent : VES request : -- \n%s\n", rootNode_string);
144 free(rootNode_string);
145 JsonHelper::deleteNode(rootNode); //deleting the rootNode here; (after getting the string version of the json created)
150 O1_LOG("\nO1 VesEvent : Failed to prepare preparePnfRegistration common header");
151 JsonHelper::deleteNode(rootNode);
157 /*******************************************************************
159 * @brief Send the Ves event over Http
166 * - Sends the Ves event over http
168 * @params[in] IN - void
169 * @return true - success
172 * ****************************************************************/
174 bool VesEvent::send()
176 return mHttpClient->send(mSendData);
179 /*******************************************************************
181 * @brief gets Event Type name from VesEventType Enum
185 * Function : getEventFieldName
188 * - returns VesEvent name
192 * @return string : Ves Event Name
193 ******************************************************************/
195 string VesEvent::getEventFieldName()
198 switch(mVesEventType)
200 case VesEventType::PNF_REGISTRATION:
202 return "pnfRegistrationFields";
204 case VesEventType::FAULT_NOTIFICATION:
207 return "stndDefinedFields";
209 return "faultFields";
212 case VesEventType::PM_SLICE:
215 return "stndDefinedFields";
217 return "measurementFields";
220 case VesEventType::HEARTBEAT:
222 return "heartbeatFields";
225 return "eventFields";
229 /*******************************************************************
231 * @brief Get Ves Collector configuration
235 * Function : getConfig
238 * - Gets Ves Collector configuration
243 ******************************************************************/
244 void VesEvent::getConfig()
246 mVesServerIp = ConfigLoader::instance().getOamConfigFile().getVesServerIp();
247 mVesServerPort = ConfigLoader::instance().getOamConfigFile().getVesServerPort();
248 mVesServerUsername = ConfigLoader::instance().getOamConfigFile().getVesServerUsername();
249 mVesServerPassword = ConfigLoader::instance().getOamConfigFile().getVesServerPassword();
252 /*******************************************************************
254 * @brief Create the URL for sending VES messages
258 * Function : createUrl
261 * - Creates the VES URL
266 ******************************************************************/
267 void VesEvent::createUrl()
269 mVesUrl = "https://" + mVesServerIp + ":" + mVesServerPort + "/eventListener/v7";
274 /**********************************************************************
276 **********************************************************************/