1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2020-2022] [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 *******************************************************************************/
23 #include "CellStateChangeStdDef.hpp"
24 #include "JsonHelper.hpp"
25 /* Default constructor*/
26 CellStateChangeStdDef::CellStateChangeStdDef() : Notification(VesEventType::FAULT_NOTIFICATION)
31 /* Default Destructor*/
32 CellStateChangeStdDef::~CellStateChangeStdDef()
38 /*******************************************************************
40 * @brief Returns ISO time String
44 * Function :getISOEventTime
47 * - Returns ISO time String
49 * @params[in] IN - void
50 * @return value of string - success
51 * empty string - failure
53 * ****************************************************************/
55 std::string CellStateChangeStdDef::getISOEventTime() {
56 auto now = std::chrono::system_clock::now();
57 auto itt = std::chrono::system_clock::to_time_t(now);
58 std::ostringstream os;
59 os << std::put_time(gmtime(&itt), "%FT%TZ");
63 /*******************************************************************
65 * @brief prepare CellStateChangeStdDef Fields
69 * Function : prepareCellStateChangeStdDefEventFields
72 * - prepare CellStateChangeStdDef Fields in json format
74 * @params[in] IN - pointer to pnfFields
75 * @return true - success
78 * ****************************************************************/
80 bool CellStateChangeStdDef::prepareEventFields(const Message* msg) {
81 const Alarm* alrm = dynamic_cast<const Alarm*> (msg);
83 O1_LOG("\nO1 CellStateChangeStdDef : Casting failed in prepareEventFields");
89 cJSON* stndDefinedFields = this->mVesEventFields;
91 if(JsonHelper::addNodeToObject(stndDefinedFields, "schemaReference", FAULT_SCHEMA) == 0) {
95 cJSON* data = JsonHelper::createNode();
97 O1_LOG("\nO1 CellStateChangeStdDef : could not create data JSON object");
100 else if(JsonHelper::addJsonNodeToObject(stndDefinedFields, "data", \
104 else if(JsonHelper::addNodeToObject(data, "href", HREF) == 0) {
107 else if(JsonHelper::addNodeToObject(data, "uri", URI) == 0) {
110 else if(JsonHelper::addNodeToObject(data, "notificationId", NOTIFICATION_ID) == 0) {
113 else if(JsonHelper::addNodeToObject(data, "notificationType", NOTIFICATION_TYPE) == 0) {
116 else if(JsonHelper::addNodeToObject(data, "eventTime", getISOEventTime().c_str()) == 0) {
119 else if(JsonHelper::addNodeToObject(data, "systemDN", "") == 0) {
122 else if(JsonHelper::addNodeToObject(data, "probableCause", PROBABLE_CAUSE) == 0) {
125 else if(JsonHelper::addNodeToObject(data, "perceivedSeverity",PERCEIVED_SEVERITY) == 0) {
128 else if(JsonHelper::addNodeToObject(data, "rootCauseIndicator", (bool)false ) == 0) {
131 else if(JsonHelper::addNodeToObject(data, "specificProblem", "") == 0) {
135 cJSON* correlatedNotificationsArr= cJSON_CreateArray();
136 if (correlatedNotificationsArr == NULL)
140 cJSON_AddItemToObject(data, "correlatedNotifications", correlatedNotificationsArr);
142 if(JsonHelper::addNodeToObject(data, "backedUpStatus", (bool)true) == 0) {
145 else if(JsonHelper::addNodeToObject(data, "backUpObject", "") == 0) {
148 else if(JsonHelper::addNodeToObject(data, "trendIndication", TRND_INDICATION) == 0) {
152 cJSON* thresholdInfo = JsonHelper::createNode();
153 if(thresholdInfo == 0) {
154 O1_LOG("\nO1 CellStateChange : could not create thresholdInfo JSON object");
157 else if(JsonHelper::addJsonNodeToObject(data, "thresholdInfo", \
158 thresholdInfo ) == 0) {
161 else if(JsonHelper::addNodeToObject(thresholdInfo, "observedMeasurement", OBSRVED_MEASUREMENT) == 0) {
164 else if(JsonHelper::addNodeToObject(thresholdInfo, "observedValue", OBSERVED_VALUE) == 0) {
168 cJSON* stateChangeDefinitionArr= cJSON_CreateArray();
169 if (stateChangeDefinitionArr == NULL)
173 cJSON_AddItemToObject(data, "stateChangeDefinition", stateChangeDefinitionArr);
175 cJSON* monitoredAttributes = JsonHelper::createNode();
176 if( monitoredAttributes == 0) {
177 O1_LOG("\nO1 CellStateChange : could not create monitoredAttributes JSON object");
180 else if(JsonHelper::addJsonNodeToObject(data , "monitoredAttributes", \
181 monitoredAttributes ) == 0) {
184 else if(JsonHelper::addNodeToObject(monitoredAttributes, "newAtt", NEW_ATT) == 0) {
187 else if(JsonHelper::addNodeToObject(data, "proposedRepairActions", PROPOSED_REPAIR_ACTION) == 0) {
190 else if(JsonHelper::addNodeToObject(data, "additionalText", ADDITIONAL_TEXT) == 0) {
194 cJSON* additionalInformation = JsonHelper::createNode();
195 if(additionalInformation == 0) {
196 O1_LOG("\nO1 CellStateChangeStdDef : could not create additionalInformation JSON object");
199 else if(JsonHelper::addJsonNodeToObject(data , "additionalInformation", \
200 additionalInformation ) == 0) {
203 else if(JsonHelper::addNodeToObject( additionalInformation, "addInfo", ADD_INFO) == 0) {
206 else if(JsonHelper::addNodeToObject(data , "alarmId", ALARM_ID) == 0) {
209 else if(JsonHelper::addNodeToObject(data , "alarmType",ALRAM_TYPE ) == 0) {
213 else if(JsonHelper::addNodeToObject(stndDefinedFields, "stndDefinedFieldsVersion", STND_DEFINED_FEILD_VERSION) == 0) {
223 /**********************************************************************
225 **********************************************************************/