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) {
33 mHttpClient = new HttpClient(mVesUrl, mVesServerUsername, mVesServerPassword);
38 /* Default Destructor*/
41 if ( mHttpClient != NULL )
48 /*******************************************************************
50 * @brief prepare Ves Event Fields
57 * - prepare Ves Event Fields in json format
59 * @params[in] IN - void
60 * @return true - success
63 * ****************************************************************/
65 bool VesEvent::prepare(const Message* msg)
68 cJSON *rootNode = JsonHelper::createNode();
70 O1_LOG("\nO1 VesEvent : could not create cJSON root Node object");
73 cJSON *event = JsonHelper::createNode();
75 O1_LOG("\nO1 VesEvent : could not create event cJSON object");
76 JsonHelper::deleteNode(rootNode);
79 if(JsonHelper::addJsonNodeToObject(rootNode, "event", event) == 0) {
80 O1_LOG("\nO1 VesEvent : could not add event Object");
81 JsonHelper::deleteNode(rootNode);
84 cJSON *commHdrNode = JsonHelper::createNode();
85 if(commHdrNode == 0) {
86 O1_LOG("\nO1 VesEvent : could not create common header Node JSON object");
87 JsonHelper::deleteNode(rootNode);
90 VesCommonHeader vesCommHdr;
91 if(vesCommHdr.prepare(commHdrNode, mVesEventType))
93 if(JsonHelper::addJsonNodeToObject(event, "commonEventHeader", commHdrNode) == 0)
95 O1_LOG("\nO1 VesEvent : could not add commonEventHeader object");
96 JsonHelper::deleteNode(rootNode);
100 //add header into the message and create pnfFields
101 mVesEventFields = JsonHelper::createNode();
102 if(mVesEventFields == 0) {
103 O1_LOG("\nO1 VesEvent : could not create Ves Event Fields JSON object");
104 JsonHelper::deleteNode(rootNode);
107 if(!prepareEventFields(msg)) {
108 O1_LOG("\nO1 VesEvent : could not prepare Ves Event Fields Node");
109 JsonHelper::deleteNode(rootNode);
112 if(JsonHelper::addJsonNodeToObject(event, getEventFieldName().c_str(), mVesEventFields) == 0) {
113 O1_LOG("\nO1 VesEvent : could not add mVesEventFields object");
114 JsonHelper::deleteNode(rootNode);
117 mSendData = JsonHelper::printUnformatted(rootNode);
118 char* rootNode_string = JsonHelper::print(rootNode);
119 O1_LOG("\nO1 VesEvent : VES request : -- \n%s\n", rootNode_string);
120 free(rootNode_string);
121 JsonHelper::deleteNode(rootNode); //deleting the rootNode here; (after getting the string version of the json created)
126 O1_LOG("\nO1 VesEvent : Failed to prepare preparePnfRegistration common header");
127 JsonHelper::deleteNode(rootNode);
133 bool VesEvent::send()
135 return mHttpClient->send(mSendData);
138 /*******************************************************************
140 * @brief gets Event Type name from VesEventType Enum
144 * Function : getEventFieldName
147 * - returns VesEvent name
151 * @return string : Ves Event Name
152 ******************************************************************/
154 string VesEvent::getEventFieldName()
157 switch(mVesEventType)
159 case VesEventType::PNF_REGISTRATION:
161 return "pnfRegistrationFields";
163 case VesEventType::FAULT_NOTIFICATION:
165 return "faultFields";
167 case VesEventType::PM_SLICE:
169 return "measurementFields";
171 case VesEventType::HEARTBEAT:
173 return "heartbeatFields";
176 return "eventFields";
180 /*******************************************************************
182 * @brief Get Ves Collector configuration
186 * Function : getConfig
189 * - Gets Ves Collector configuration
194 ******************************************************************/
195 void VesEvent::getConfig()
197 mVesServerIp = ConfigLoader::instance().getOamConfigFile().getVesServerIp();
198 mVesServerPort = ConfigLoader::instance().getOamConfigFile().getVesServerPort();
199 mVesServerUsername = ConfigLoader::instance().getOamConfigFile().getVesServerUsername();
200 mVesServerPassword = ConfigLoader::instance().getOamConfigFile().getVesServerPassword();
203 /*******************************************************************
205 * @brief Create the URL for sending VES messages
209 * Function : createUrl
212 * - Creates the VES URL
217 ******************************************************************/
218 void VesEvent::createUrl()
220 mVesUrl = "https://" + mVesServerIp + ":" + mVesServerPort + "/eventListener/v7";
222 /**********************************************************************
224 **********************************************************************/